Add support for backup nextcloud accounts.
This commit is contained in:
		| @@ -101,6 +101,7 @@ post_backup_commands=() | ||||
| ##  | ||||
| dir_backup="<blank seperatet list of directories>" | ||||
|  | ||||
|  | ||||
| ## - backup network filesystems like nfs or smbfs | ||||
| ## - | ||||
| ## - NOTICE! | ||||
| @@ -148,10 +149,12 @@ mysql_password=backup | ||||
| ## - | ||||
| mysql_gzip=false | ||||
|  | ||||
|  | ||||
| ## - restart apache after mysqldump | ||||
| ## - | ||||
| restart_apache=false | ||||
|  | ||||
|  | ||||
| ## - also store postresql databases ? | ||||
| ## -  | ||||
| pgsql_backup=false | ||||
| @@ -175,6 +178,32 @@ svn_source_base_path="<path-to-svn i.e. /data/svn>" | ||||
| svn_gzip=false | ||||
|  | ||||
|  | ||||
| ## - backup nextcloud accounts | ||||
| ## -  | ||||
| nextcloud_backup=false | ||||
|  | ||||
| ## - nextcloud_server_url | ||||
| ## - | ||||
| nextcloud_server_url="https://${srcHost}" | ||||
|  | ||||
| ## - nextcloud_account_arr | ||||
| ## - | ||||
| ## - nextcloud_accounts="<name1>;<password1>[;server_url] [<name2;password2>[;server_url] [.. | ||||
| ## - | ||||
| ## - Notice: | ||||
| ## -    if 'server_url' is ommited, the value of variable 'nextcloud_server_url', the | ||||
| ## -    default on, will be used. | ||||
| ## - | ||||
| ## - Example: | ||||
| ## - | ||||
| ## -    nextcloud_accounts=" | ||||
| ## -       user1;P4ssw0rd1 | ||||
| ## -       user2;P4ssw0rd2;non-default-cloud-server-url | ||||
| ## -    " | ||||
| ## -        | ||||
| nextcloud_accounts="" | ||||
|  | ||||
|  | ||||
| ## - Give rsync arguments here. Maybe you wish  | ||||
| ## - to exclude some files or diredtories | ||||
| ## - | ||||
|   | ||||
| @@ -122,8 +122,12 @@ if [ "X$backup_dirs" = "X" ]; then | ||||
|    found=false | ||||
| fi | ||||
|  | ||||
| ## - Be compartible with older host files, which are missing variables concerning | ||||
| ## - backup nextcloud accounts. | ||||
| ## - | ||||
| [[ -z "$nextcloud_backup" ]] && nextcloud_backup=false | ||||
|  | ||||
| if [ "$found" = "true" -o "$pgsql_backup" = "true"  -o "$mysql_backup" = "true" -o "$disksetting_backup" = "true" ] ; then | ||||
| if [ "$found" = "true" -o "$pgsql_backup" = "true"  -o "$mysql_backup" = "true" -o "$disksetting_backup" = "true" -o "$nextcloud_backup" = "true" ] ; then | ||||
|  | ||||
|    begin_h=`date +%H` | ||||
|    begin_m=`date +%M` | ||||
| @@ -350,6 +354,42 @@ 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.." | ||||
|   | ||||
							
								
								
									
										130
									
								
								hosts/scripts/nc_accounts_backup.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										130
									
								
								hosts/scripts/nc_accounts_backup.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,130 @@ | ||||
| #!/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 | ||||
|  | ||||
| #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 | ||||
|    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 | ||||
|       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" | ||||
|       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 | ||||
|       ## - | ||||
|       [ -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 | ||||
		Reference in New Issue
	
	Block a user