diff --git a/conf/rcopy_functions.conf b/conf/rcopy_functions.conf index 7e8e2c5..ef66e77 100644 --- a/conf/rcopy_functions.conf +++ b/conf/rcopy_functions.conf @@ -114,6 +114,13 @@ fatal(){ exit 1 } +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + blank_line() { echo "" } diff --git a/hosts/backup_script.sh.sample b/hosts/backup_script.sh.sample index 40f578f..6a29530 100644 --- a/hosts/backup_script.sh.sample +++ b/hosts/backup_script.sh.sample @@ -186,9 +186,15 @@ nextcloud_backup=false ## - nextcloud_server_url="https://${srcHost}" -## - nextcloud_account_arr +## - nextcloud_accounts ## - -## - nextcloud_accounts=";[;server_url] [[;server_url] [.. +## - !! Notice !! +## - ============ +## - - delemiter between fields is th backtick sign: '`' +## - - single AND double quote sign CANNOT BE USED as a sign inside a field +## - - the single quote sign is used as begin/end sign for this variable +## - +## - nextcloud_accounts='`[`server_url] [[`server_url] [..' ## - ## - Notice: ## - if 'server_url' is ommited, the value of variable 'nextcloud_server_url', the @@ -196,12 +202,12 @@ nextcloud_server_url="https://${srcHost}" ## - ## - Example: ## - -## - nextcloud_accounts=" -## - user1;P4ssw0rd1 -## - user2;P4ssw0rd2;non-default-cloud-server-url -## - " -## - -nextcloud_accounts="" +## - nextcloud_accounts=' +## - user1`P4ssw0rd1 +## - user2`P4ssw0rd2`non-default-cloud-server-url +## - ' +## - +nextcloud_accounts='' ## - Give rsync arguments here. Maybe you wish diff --git a/hosts/scripts/main_part.include b/hosts/scripts/main_part.include index 585196d..9db7d51 100644 --- a/hosts/scripts/main_part.include +++ b/hosts/scripts/main_part.include @@ -354,42 +354,6 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" done fi - if $nextcloud_backup ; then - - declare -a nextcloud_account_arr - for _account in $nextcloud_accounts ; do - nextcloud_account_arr+=("$_account") - done - - echolog "\nGoing to backup nextcloud accounts.. ( $(date +%H): $($date +%M) h)" - for _val in "${nextcloud_account_arr[@]}" ; do - IFS=';' read -a _val_arr <<< "${_val}" - if [[ "${#_val_arr[@]}" -eq 3 ]] ; then - _server_url="${_val_arr[2]}" - else - _server_url="$nextcloud_server_url" - fi - _server_name="${_server_url#http://}" - _server_name="${_server_name#https://}" - #echo "" - #echo "#_val_arr[@]: ${#_val_arr[@]}" - #echo "_val_arr[0]: ${_val_arr[0]}" - #echo "_val_arr[1]: ${_val_arr[1]}" - #echo "_val_arr[2]: ${_val_arr[2]}" - #echo "_val_arr[3]: ${_val_arr[3]}" - #echo "" - - echolog "\n\tBackup nextcloud account '${_val_arr[0]}' from server '$_server_name'" - nc_server_url="$_server_url" \ - nc_server_name="$_server_name" \ - nc_user="${_val_arr[0]}" \ - nc_password="${_val_arr[1]}" \ - ${script_dir}/nc_accounts_backup.sh - - done - - fi - if [[ -n "$post_backup_commands" ]]; then echolog "\nGoing to execute post backup commands.." @@ -410,6 +374,43 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" done fi + if $nextcloud_backup ; then + + declare -a nextcloud_account_arr + + # - Splitt on newlines + # - + # - Use: IFS=$'\n' + # - + IFS=$'\n' ; for _account in $nextcloud_accounts ; do + nextcloud_account_arr+=("$(trim $_account)"); + done + + echolog "\nGoing to backup nextcloud accounts.. ( $(date +%H): $($date +%M) h)" + for _val in "${nextcloud_account_arr[@]}" ; do + + # - Note: Field delemeter is the backtick sign '`' + # - + IFS='`' read -a _val_arr <<< "${_val}" + if [[ "${#_val_arr[@]}" -eq 3 ]] ; then + _server_url="${_val_arr[2]}" + else + _server_url="$nextcloud_server_url" + fi + _server_name="${_server_url#http://}" + _server_name="${_server_name#https://}" + + echolog "\n\tBackup nextcloud account '${_val_arr[0]}' from server '$_server_name'" + nc_server_url="$_server_url" \ + nc_server_name="$_server_name" \ + nc_user="${_val_arr[0]}" \ + nc_password="${_val_arr[1]}" \ + ${script_dir}/nc_accounts_backup.sh + + done + + fi + fi # if $NO_NEW_BACKUP end_h=`$date +%H` diff --git a/hosts/scripts/nc_accounts_backup.sh b/hosts/scripts/nc_accounts_backup.sh index bfc5666..8168ddb 100755 --- a/hosts/scripts/nc_accounts_backup.sh +++ b/hosts/scripts/nc_accounts_backup.sh @@ -20,7 +20,7 @@ err_Log=${LOCK_DIR}/nc_account.err.log backup_base_target_dir="${backup_mirror_dir}/Nextcloud-Accounts" backup_target_dir="${backup_base_target_dir}/${nc_server_name}/${nc_user}" -nc_params="--non-interactive --silent" +#nc_params="--non-interactive --silent" nc_params="--non-interactive" if [[ ! -d "$backup_base_target_dir" ]] ; then @@ -40,13 +40,6 @@ if [[ ! -d "$backup_target_dir" ]] ; then fi fi -#echo "server url: $nc_server_url" -#echo "server name: $nc_server_name" -#echo "user: $nc_user" -#echo "password: $nc_password" -# -#exit 0 - nc_cmd_bin="$(which nextcloudcmd)" if [ -z "$nc_cmd_bin" ]; then @@ -64,10 +57,10 @@ if $MIRROR ; then b_timestamp="$(date +"%s")" echo "" - echo "$nc_cmd_bin $nc_params -u $nc_user -p $nc_password $backup_target_dir $nc_server_url" + echo "$nc_cmd_bin $nc_params -u $nc_user -p \"$nc_password\" $backup_target_dir $nc_server_url" echo "" $( - $nc_cmd_bin $nc_params -u $nc_user -p $nc_password $backup_target_dir $nc_server_url > $err_Log 2>&1 + $nc_cmd_bin $nc_params -u $nc_user -p "$nc_password" $backup_target_dir $nc_server_url > $err_Log 2>&1 exit $? ) retval=$? @@ -95,12 +88,15 @@ if $MIRROR ; then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + cp -a "$err_Log" "/var/log/nc_account-${nc_user}.err.log" if grep -i -q -E "Authentication\s+failed" "$err_Log" 2> /dev/null ; then - echo "Authentication failed for user \"$nc_user\" on system \"$nc_server_name\".." > "$err_Log" + print_error_stdout "Authentication failed for user \"$nc_user\" on system \"$nc_server_name\"" + echolog "\t[ERROR] Authentication failed for user \"$nc_user\".. [ $duration ]" + else + print_error_stdout "Cannot backup netxcloud account \"$nc_user\"" + echolog "\t[ Notice ] Errors occured while syncing files from netxcloud account \"$nc_user\" [ $duration ]" fi - print_error_stdout "Cannot backup netxcloud account \"$nc_user\"\n $(cat "$err_Log")" - echolog "\t[ERROR] Cannot Cannot backup netxcloud account \"$nc_user\" [ $duration ]\n\t`$cat $err_Log`\n" else ## - print durations right-aligned