Fix some errors syncunf nextclud accounts..

This commit is contained in:
root 2020-11-19 18:46:54 +01:00
parent 8477b08aee
commit 2c54e20d04
4 changed files with 67 additions and 57 deletions

View File

@ -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 ""
}

View File

@ -186,9 +186,15 @@ nextcloud_backup=false
## -
nextcloud_server_url="https://${srcHost}"
## - nextcloud_account_arr
## - nextcloud_accounts
## -
## - nextcloud_accounts="<name1>;<password1>[;server_url] [<name2;password2>[;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='<name1>`<password1>[`server_url] [<name2`password2>[`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='
## - user1`P4ssw0rd1
## - user2`P4ssw0rd2`non-default-cloud-server-url
## - '
## -
nextcloud_accounts=""
nextcloud_accounts=''
## - Give rsync arguments here. Maybe you wish

View File

@ -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`

View File

@ -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