127 lines
3.4 KiB
Bash
Executable File
127 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
## - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
## -
|
|
## - No further settings on (remote) nextcloud mashine are necessary
|
|
## -
|
|
## - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
err_Log=${LOCK_DIR}/nc_account.err.log
|
|
> $err_Log
|
|
|
|
|
|
## - load functions
|
|
## -
|
|
. $rcopy_functions_file
|
|
|
|
# --------------------------------------------------- #
|
|
# -------------------- Variable --------------------- #
|
|
#
|
|
|
|
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"
|
|
|
|
if [[ ! -d "$backup_base_target_dir" ]] ; then
|
|
|
|
mkdir -p "$backup_base_target_dir" > $err_Log 2>&1
|
|
if [[ $? -ne 0 ]] ; then
|
|
echolog "\t[ERROR] Cannot create directory '$backup_base_target_dir'"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [[ ! -d "$backup_target_dir" ]] ; then
|
|
mkdir -p "$backup_target_dir" > $err_Log 2>&1
|
|
if [[ $? -ne 0 ]] ; then
|
|
echolog "\t[ERROR] Cannot create directory '$backup_target_dir'"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
nc_cmd_bin="$(which nextcloudcmd)"
|
|
|
|
if [ -z "$nc_cmd_bin" ]; then
|
|
echolog "\t[ERROR] Cannot find binary \"nextcloudcmd\""
|
|
exit 1
|
|
|
|
fi
|
|
|
|
#
|
|
# ------------------ Ende Variable ------------------ #
|
|
# --------------------------------------------------- #
|
|
|
|
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 > $err_Log 2>&1
|
|
exit $?
|
|
)
|
|
retval=$?
|
|
|
|
## - end timestamp
|
|
## -
|
|
e_timestamp=`$date +"%s"`
|
|
|
|
## - determin duration
|
|
## -
|
|
_time=`expr $e_timestamp - $b_timestamp`
|
|
t_h=`expr $_time / 60 / 60`
|
|
t_rest_h=`expr $_time - $t_h \\* 60 \\* 60`
|
|
t_m=`expr $t_rest_h / 60`
|
|
t_s=`expr $t_rest_h - $t_m \\* 60`
|
|
duration=""
|
|
if [ $t_h -gt 0 ]; then
|
|
duration="$t_h h : $t_m min : $t_s sec"
|
|
elif [ $t_m -gt 0 ];then
|
|
duration="$t_m min : $t_s sec"
|
|
else
|
|
duration="$t_s sec"
|
|
fi
|
|
|
|
## - 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
|
|
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
|
|
|
|
else
|
|
|
|
## - print durations right-aligned
|
|
## -
|
|
[ -z $right_tabstop ] && right_tabstop=70
|
|
info_msg="NC Account \"$nc_user\" on server \"$nc_server_name\" successfully mirrored "
|
|
_tmp_string="${info_msg}${duration}"
|
|
_strlen=${#_tmp_string}
|
|
_count_blank=`expr $right_tabstop - $_strlen`
|
|
_str_blanks=""
|
|
while [ $_count_blank -gt 1 ]; do
|
|
_str_blanks="$_str_blanks "
|
|
_count_blank=`expr $_count_blank - 1`
|
|
done
|
|
echononl "\t$info_msg"
|
|
echononl "$_str_blanks"
|
|
|
|
echolog "[ $duration ]"
|
|
fi
|
|
|
|
#echo " $real_backupSrcDir" >> $dirs_backup_done
|
|
|
|
else
|
|
echolog "\tMIRROR is set to $MIRROR. So nothing to do."
|
|
fi
|
|
|
|
exit 0
|