Add Options 'ONLY_BACKUP' (do not handle existing archives) and 'NO_NEW_BACKUP' (do not backup any host, only handle existing archives).
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| # I put everything in one block and added sharedscripts, so that mysql gets  | ||||
| # flush-logs'd only once. | ||||
| # Else the binary logs would automatically increase by n times every day. | ||||
| /var/log/rsync.log { | ||||
| /var/log/rcopy.log { | ||||
|    daily | ||||
|    rotate 7 | ||||
|    missingok | ||||
|   | ||||
							
								
								
									
										64
									
								
								conf/logrotate_handle-backups.conf.sample
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								conf/logrotate_handle-backups.conf.sample
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| # I put everything in one block and added sharedscripts, so that mysql gets  | ||||
| # flush-logs'd only once. | ||||
| # Else the binary logs would automatically increase by n times every day. | ||||
| /var/log/rcopy-handle_backups.log { | ||||
|    daily | ||||
|    rotate 7 | ||||
|    missingok | ||||
|    compress | ||||
|    su root root | ||||
|    prerotate | ||||
|     | ||||
|       filesystem=`df` | ||||
|  | ||||
|       content_type='Content-Type: text/plain;\n charset="utf-8"' | ||||
|  | ||||
|       extra_admin_email="" | ||||
|       extra_error_email="" | ||||
|  | ||||
|       ## - These variables will be exportet from backup script (rcopy.sh) | ||||
|       ## - | ||||
|       ## -   admin_email from_address company logFile logDuration  | ||||
|       #admin_email="argus@oopen.de" | ||||
|       #from_address="root@`hostname -f`" | ||||
|       #company="Warenform INET" | ||||
|       #logFile=/backup/log/rsync.log | ||||
|       #label | ||||
|  | ||||
|       durations_top="\nDurations of the certain hosts:\n" | ||||
|       durations="${durations_top}`cat $logDuration`\n" | ||||
|  | ||||
|       send=`cat $logFile` | ||||
|  | ||||
|       datum=`date +"%d.%m.%Y"` | ||||
|  | ||||
|       echo -e "To:${admin_email}\n${content_type}\nSubject:Handle Backups $company -- $datum\n$filesystem\n\nBackup resource / Label: $label\n$durations\n\n$send\n" | /usr/sbin/sendmail -F "BACKUP $company" -f $from_address $admin_email | ||||
|       if [[ -n "$extra_admin_email" ]]; then | ||||
|          echo -e "To:${extra_admin_email}\n${content_type}\nSubject:Handle Backups $company -- $datum\n$filesystem\n\nBackup resource / Labe: $label\n$durations\n\n$send\n" | /usr/sbin/sendmail -F "BACKUP $company" -f $from_address $extra_admin_email | ||||
|       fi | ||||
|  | ||||
|       declare -i error=`grep -e"\[ERROR" $logFile | wc -l` | ||||
|       declare -i warning=`grep -e"\[WARN" $logFile | wc -l` | ||||
|  | ||||
|    if [ $error -gt 0 -o $warning -gt 0 ] ; then | ||||
|  | ||||
|       err_msg="`grep -A 2 -B 1 -e\"\[ERROR\" $logFile`\n" | ||||
|       warn_msg="`grep -A 2 -B 2 -e\"\[WARN\" $logFile`\n" | ||||
|        | ||||
|       msg_top="Backup $company vom $datum.\nBackup resource / Label: $label\nBackupprozess beendet mit:" | ||||
|       msg_body_01="\t$error Error(s)\n\t$warning Warning(s)\n" | ||||
|       msg_body_02="\n\n--- ERROR(S) ---\n${err_msg}\n\n--- WARNING(S) ...\n${warn_msg}" | ||||
|  | ||||
|       msg="${msg_top}\n${msg_body_01}\n${msg_body_02}" | ||||
|  | ||||
|       echo -e "To:${admin_email}\n${content_type}\nSubject:Handle Backups Errors $company -- $datum\n${msg}" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $admin_email | ||||
|       if [ "X$extra_error_email" != "X" ]; then | ||||
|          echo -e "To:${extra_error_email}\n${content_type}\nSubject:Handle Backups Errors $company -- $datum\n${msg}" | /usr/sbin/sendmail -F "Errors BACKUP $company" -f $from_address $extra_error_email | ||||
|       fi | ||||
|  | ||||
|    fi | ||||
|  | ||||
|  | ||||
|  | ||||
|    endscript | ||||
| } | ||||
| @@ -137,11 +137,6 @@ reminder_email_2="" | ||||
| backup_base_dir=${backup_mountpoint}/backup | ||||
| #backup_base_dir=/backup | ||||
|  | ||||
| ## - location of the logfile | ||||
| ## - | ||||
| logFile="/var/log/rsync.log" | ||||
| disk_label_log_file="/var/log/backup_disk-label.log" | ||||
|  | ||||
| ## - logging backup durations in an different file | ||||
| ## - NOTICE: | ||||
| ## -    because of the process number in the filename, take care, not to | ||||
|   | ||||
| @@ -5,6 +5,64 @@ | ||||
| # --------------------------------------------------- # | ||||
| # ------------------- Funktionen -------------------- # | ||||
| # | ||||
| usage() { | ||||
|  | ||||
|  | ||||
|    [[ -n  "$1" ]] && error "$1" | ||||
|  | ||||
|  | ||||
|    echo -e " | ||||
| \033[1mUsage:\033[m | ||||
|  | ||||
|    $(basename $0) [OPTION [OPTION .. | ||||
|  | ||||
| \033[1mDescription\033[m | ||||
|  | ||||
|    Main Backup Script for hosts maintained by O.OPEN. | ||||
|  | ||||
| \033[1mOptions\033[m | ||||
|  | ||||
|    -B | ||||
|       Only Backup host - do not handle (existing) archives. | ||||
|  | ||||
|    -N | ||||
|       Do not backup anything, only maintain existing backups - archiving and/or | ||||
|       removing existing backups. | ||||
|  | ||||
|    -m | ||||
|       Only backup hosts listed in file conf/manual_hosts.conf. Don't inform anyone, | ||||
|       and also don't restart services. | ||||
|  | ||||
| \033[1mFiles\033[m | ||||
|  | ||||
|    \033[1m$(basename $rcopy_conf_file)\033[m: Main Configuration | ||||
| 	 | ||||
| 	See folder 'conf' for more configuration files | ||||
|  | ||||
| \033[1mExample:\033[m | ||||
|     | ||||
|    Normal Backup | ||||
|  | ||||
|       $(basename $0) | ||||
|  | ||||
|    Only maintain backup archives - do NOT write new backups | ||||
|     | ||||
|       $(basename $0) -N | ||||
|  | ||||
| " | ||||
|  | ||||
|    clean_up 1 | ||||
|  | ||||
| } | ||||
|  | ||||
| clean_up() { | ||||
|  | ||||
|    # Perform program exit housekeeping | ||||
|    rm -rf "$LOCK_DIR" | ||||
|    blank_line | ||||
|    exit $1 | ||||
| } | ||||
|  | ||||
| echolog(){  | ||||
|    if [ -n "$2" ];then | ||||
|       case $_DEBUG in | ||||
| @@ -55,6 +113,11 @@ fatal(){ | ||||
|    echolog  "\n*** End Update --  no backups are done ***\n\n" | ||||
|    exit 1 | ||||
| } | ||||
|  | ||||
| blank_line() { | ||||
|    echo "" | ||||
| } | ||||
|  | ||||
| # | ||||
| # ------------------ Ende Funktionen ---------------- # | ||||
| # --------------------------------------------------- # | ||||
|   | ||||
| @@ -150,173 +150,185 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true"  -o "$mysql_backup" = "true" | ||||
|  | ||||
|    if  $ARCHIVE ;then | ||||
|  | ||||
|       echolog "\nGoing to handle archives.. ( `$date +%H`:`$date +%M` h )" | ||||
|       _done=false | ||||
|       if $ONLY_BACKUP ; then | ||||
|  | ||||
|       if [ ! -d $backup_archiv_dir ]; then | ||||
|         mkdir -p $backup_archiv_dir; | ||||
|       fi | ||||
|          echolog "\n\tOnly saving backups was requested - (ONLY_BACKUP=true)." | ||||
|  | ||||
|       ## - remove backups older then $days | ||||
|       ## - | ||||
|       archive_dirs=`find $backup_archiv_dir -maxdepth 1 -mindepth 1 -type d -name "Backup_*"` | ||||
|       _today=`date --date "now" +"%Y-%m-%d"` | ||||
|       _timestamp_today=`date --date "$_today" "+%s"` | ||||
|       for _dir in $archive_dirs ; do | ||||
|          _bakup_day=`cat $_dir/BACKUP-DATE` | ||||
|          _backup_timestamp=`date --date "$_bakup_day" +"%s"` | ||||
|          _days=$(echo "scale=0;($_timestamp_today-$_backup_timestamp)/86400" | bc) | ||||
|          if [ $_days -gt $days ]; then | ||||
|             echolog "\n\tRemoving backup from $_bakup_day.." | ||||
|       else | ||||
|  | ||||
|             ## - begin timestamp | ||||
|             ## - | ||||
|             b_timestamp=`$date +"%s"` | ||||
|          echolog "\nGoing to handle archives.. ( `$date +%H`:`$date +%M` h )" | ||||
|          _done=false | ||||
|  | ||||
|             rm -rf $_dir | ||||
|             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 | ||||
|  | ||||
|             if [ ! "$retval" = 0 ]; then | ||||
|                echo -e "\t[ Error ]: Removing backup from $_bakup_day failed" | ||||
|             else | ||||
|                echolog "\t--- Backup from $_bakup_day successfully removed..    [ $duration ]" | ||||
|             fi | ||||
|          fi | ||||
|          _done=true | ||||
|       done | ||||
|  | ||||
|       ## - Archive last backup.. | ||||
|       ## - | ||||
|       if [ -f $backup_mirror_dir/BACKUP-DATE ]; then | ||||
|          _last_backup_date=`head -n1 $backup_mirror_dir/BACKUP-DATE` | ||||
|          if [ ! -d $backup_archiv_dir/Backup_$_last_backup_date ] ; then | ||||
|             echolog "\n\tArchiving (last) backup from $_last_backup_date..  ( `$date +%H`:`$date +%M` h )" | ||||
|  | ||||
|             ## - begin timestamp | ||||
|             ## - | ||||
|             b_timestamp=`$date +"%s"` | ||||
|  | ||||
|             cp  -ral $backup_mirror_dir $backup_archiv_dir/Backup_$_last_backup_date | ||||
|  | ||||
|             ## - 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 | ||||
|  | ||||
|             if [ ! "$?" = 0 ]; then | ||||
|                echo -e "\t[ Error ]: Archiving backup from $_last_backup_date failed" | ||||
|             else | ||||
|                echolog "\t--- Backup from $_last_backup_date successfully archived..   [ $duration ]" | ||||
|             fi | ||||
|          if [ ! -d $backup_archiv_dir ]; then | ||||
|          mkdir -p $backup_archiv_dir; | ||||
|          fi | ||||
|  | ||||
|          _done=true | ||||
|          ## - remove backups older then $days | ||||
|          ## - | ||||
|          archive_dirs=`find $backup_archiv_dir -maxdepth 1 -mindepth 1 -type d -name "Backup_*"` | ||||
|          _today=`date --date "now" +"%Y-%m-%d"` | ||||
|          _timestamp_today=`date --date "$_today" "+%s"` | ||||
|          for _dir in $archive_dirs ; do | ||||
|             _bakup_day=`cat $_dir/BACKUP-DATE` | ||||
|             _backup_timestamp=`date --date "$_bakup_day" +"%s"` | ||||
|             _days=$(echo "scale=0;($_timestamp_today-$_backup_timestamp)/86400" | bc) | ||||
|             if [ $_days -gt $days ]; then | ||||
|                echolog "\n\tRemoving backup from $_bakup_day.. ( `$date +%H`:`$date +%M` h )" | ||||
|  | ||||
|                ## - begin timestamp | ||||
|                ## - | ||||
|                b_timestamp=`$date +"%s"` | ||||
|  | ||||
|                rm -rf $_dir | ||||
|                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 | ||||
|  | ||||
|                if [ ! "$retval" = 0 ]; then | ||||
|                   echo -e "\t[ Error ]: Removing backup from $_bakup_day failed" | ||||
|                else | ||||
|                   echolog "\t--- Backup from $_bakup_day successfully removed..    [ $duration ]" | ||||
|                fi | ||||
|                _done=true | ||||
|             fi | ||||
|          done | ||||
|  | ||||
|          ## - Archive last backup.. | ||||
|          ## - | ||||
|          if [ -f $backup_mirror_dir/BACKUP-DATE ]; then | ||||
|             _last_backup_date=`head -n1 $backup_mirror_dir/BACKUP-DATE` | ||||
|             if [ ! -d $backup_archiv_dir/Backup_$_last_backup_date ] ; then | ||||
|                echolog "\n\tArchiving (last) backup from $_last_backup_date.. ( `$date +%H`:`$date +%M` h )" | ||||
|  | ||||
|                ## - begin timestamp | ||||
|                ## - | ||||
|                b_timestamp=`$date +"%s"` | ||||
|  | ||||
|                cp  -ral $backup_mirror_dir $backup_archiv_dir/Backup_$_last_backup_date | ||||
|  | ||||
|                ## - 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 | ||||
|  | ||||
|                if [ ! "$?" = 0 ]; then | ||||
|                   echo -e "\t[ Error ]: Archiving backup from $_last_backup_date failed" | ||||
|                else | ||||
|                   echolog "\t--- Backup from $_last_backup_date successfully archived..   [ $duration ]" | ||||
|                fi | ||||
|                _done=true | ||||
|             fi | ||||
|  | ||||
|          fi # if $ONLY_BACKUP | ||||
|  | ||||
|       fi | ||||
|  | ||||
|       if ! $_done ; then | ||||
|          echolog "\n\tNothing to do. - No last backup found, no backup older then $days days found." | ||||
|          echolog "\n\tNothing to do. - No last backup (not yet archived) found\n\t                 No backup older then $days days found." | ||||
|       fi | ||||
|       echolog "" | ||||
|  | ||||
|    fi | ||||
|  | ||||
|    if $disksetting_backup ; then | ||||
|       echolog "\nGoing to backup disk settings..  ( `$date +%H`:`$date +%M` h )" | ||||
|       $script_dir/disksettings_backup.sh | ||||
|    fi | ||||
|    if $svn_backup;then | ||||
|       echolog "\nGoing to backup svn repositories..  ( `$date +%H`:`$date +%M` h )" | ||||
|       export svn_source_base_path svn_gzip | ||||
|       $script_dir/svn_backup.sh | ||||
|    fi | ||||
|    if $mysql_backup ;then | ||||
|    if $NO_NEW_BACKUP ; then | ||||
|       echolog "\n\tOnly handle existing backups was requested - NOT WRITING any backups (NO_NEW_BACKUP=true)." | ||||
|    else | ||||
|  | ||||
|       if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then | ||||
|          for _val in "${mysql_credential_args_arr[@]}" ; do | ||||
|       if $disksetting_backup ; then | ||||
|          echolog "\nGoing to backup disk settings..  ( `$date +%H`:`$date +%M` h )" | ||||
|          $script_dir/disksettings_backup.sh | ||||
|       fi | ||||
|       if $svn_backup;then | ||||
|          echolog "\nGoing to backup svn repositories..  ( `$date +%H`:`$date +%M` h )" | ||||
|          export svn_source_base_path svn_gzip | ||||
|          $script_dir/svn_backup.sh | ||||
|       fi | ||||
|       if $mysql_backup ;then | ||||
|  | ||||
|             IFS=':' read -a _val_arr <<< "${_val}" | ||||
|          if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then | ||||
|             for _val in "${mysql_credential_args_arr[@]}" ; do | ||||
|  | ||||
|             mysql_version="${_val_arr[0]}" | ||||
|             mysql_credential_args="${_val_arr[1]}" | ||||
|                IFS=':' read -a _val_arr <<< "${_val}" | ||||
|  | ||||
|             echolog "\nGoing to backup mysql databases ${_val_arr[0]} ..  ( `$date +%H`:`$date +%M` h )" | ||||
|             export mysql_version mysql_credential_args mysql_gzip | ||||
|                mysql_version="${_val_arr[0]}" | ||||
|                mysql_credential_args="${_val_arr[1]}" | ||||
|  | ||||
|                echolog "\nGoing to backup mysql databases ${_val_arr[0]} ..  ( `$date +%H`:`$date +%M` h )" | ||||
|                export mysql_version mysql_credential_args mysql_gzip | ||||
|                $script_dir/mysql_backup.sh | ||||
|             done | ||||
|          else | ||||
|             echolog "\nGoing to backup mysql databases..  ( `$date +%H`:`$date +%M` h )" | ||||
|             export mysql_user mysql_password mysql_credential_args mysql_gzip | ||||
|             $script_dir/mysql_backup.sh  | ||||
|          done | ||||
|       else | ||||
|          echolog "\nGoing to backup mysql databases..  ( `$date +%H`:`$date +%M` h )" | ||||
|          export mysql_user mysql_password mysql_credential_args mysql_gzip | ||||
|          $script_dir/mysql_backup.sh  | ||||
|          fi | ||||
|          ## - !!  | ||||
|          if $restart_apache ;then | ||||
|             $ssh ${ssh_user}@$srcHost "sudo /etc/init.d/apache2 restart" | ||||
|          fi | ||||
|       fi | ||||
|       ## - !!  | ||||
|       if $restart_apache ;then | ||||
|          $ssh ${ssh_user}@$srcHost "sudo /etc/init.d/apache2 restart" | ||||
|       if $pgsql_backup;then | ||||
|          echolog "\nGoing to backup postgres databases..  ( `$date +%H`:`$date +%M` h )" | ||||
|          export pgsql_user pgsql_gzip | ||||
|          $script_dir/pgsql_backup.sh | ||||
|       fi | ||||
|    fi | ||||
|    if $pgsql_backup;then | ||||
|       echolog "\nGoing to backup postgres databases..  ( `$date +%H`:`$date +%M` h )" | ||||
|       export pgsql_user pgsql_gzip | ||||
|       $script_dir/pgsql_backup.sh | ||||
|    fi | ||||
|  | ||||
|    echolog "\nGoing to backup directories..  ( `$date +%H`:`$date +%M` h )" | ||||
|    _done=false | ||||
|       echolog "\nGoing to backup directories..  ( `$date +%H`:`$date +%M` h )" | ||||
|       _done=false | ||||
|  | ||||
|    for dir in $dir_backup ; do | ||||
|       echolog "\n\tDirectory $dir" | ||||
|       backup_dir=$dir $script_dir/dir_backup.sh | ||||
|       _done=true | ||||
|    done | ||||
|  | ||||
|    if ! $_done ; then | ||||
|       echo -e "\t[ Warning ]: No directory for backup selected !!" | ||||
|    fi | ||||
|  | ||||
|  | ||||
|    if $mount_netdir; then | ||||
|       echolog "\nGoing to backup network directories..  ( `$date +%H`:`$date +%M` h )" | ||||
|       for dir in $net_mounted_dir_backup ; do | ||||
|          echolog "\n\tBackup network directory $dir" | ||||
|          export mount_netdir  | ||||
|          backup_dir=$dir $script_dir/net_mounted_dir_backup.sh | ||||
|       for dir in $dir_backup ; do | ||||
|          echolog "\n\tDirectory $dir" | ||||
|          backup_dir=$dir $script_dir/dir_backup.sh | ||||
|          _done=true | ||||
|       done | ||||
|    fi | ||||
|  | ||||
|       if ! $_done ; then | ||||
|          echo -e "\t[ Warning ]: No directory for backup selected !!" | ||||
|       fi | ||||
|  | ||||
|  | ||||
|       if $mount_netdir; then | ||||
|          echolog "\nGoing to backup network directories..  ( `$date +%H`:`$date +%M` h )" | ||||
|          for dir in $net_mounted_dir_backup ; do | ||||
|             echolog "\n\tBackup network directory $dir" | ||||
|             export mount_netdir  | ||||
|             backup_dir=$dir $script_dir/net_mounted_dir_backup.sh | ||||
|          done | ||||
|       fi | ||||
|    fi # if $NO_NEW_BACKUP | ||||
|  | ||||
|    end_h=`$date +%H` | ||||
|    end_m=`$date +%M` | ||||
|   | ||||
							
								
								
									
										111
									
								
								rcopy.sh
									
									
									
									
									
								
							
							
						
						
									
										111
									
								
								rcopy.sh
									
									
									
									
									
								
							| @@ -1,12 +1,12 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| manual=$1 | ||||
| NO_NEW_BACKUP=${NO_NEW_BACKUP:=false} | ||||
| manual=${manual:=false} | ||||
|  | ||||
| if [[ $manual != false && $manual != true ]]; then | ||||
|    echo -e "\n[ Error ]: Usage: `basename $0` [true|false]\n" | ||||
|    exit 2 | ||||
| fi | ||||
| #if [[ $MANUAL != false && $MANUAL != true ]]; then | ||||
| #   echo -e "\n[ Error ]: Usage: `basename $0` [true|false]\n" | ||||
| #   exit 2 | ||||
| #fi | ||||
|  | ||||
| ## - if you plan to run the backup scripts as a cronjob,  | ||||
| ## - you have to set this variable manually | ||||
| @@ -18,29 +18,52 @@ USER=$LOGNAME | ||||
| rcopy_base_dir="$(realpath $(dirname $0))" | ||||
| rcopy_conf_file="$rcopy_base_dir/conf/rcopy.conf" | ||||
| rcopy_functions_file=$rcopy_base_dir/conf/rcopy_functions.conf | ||||
| ## - location of the logfile | ||||
| ## - | ||||
| logFile="/var/log/rcopy.log" | ||||
| disk_label_log_file="/var/log/backup_disk-label.log" | ||||
|  | ||||
| export rcopy_base_dir rcopy_conf_file rcopy_functions_file | ||||
|  | ||||
| if $manual ; then | ||||
|    ## - this is for manual start, we don't want inform anyone and | ||||
|    ## - also don't restart any service | ||||
|    ## - | ||||
|    send_reminder=false | ||||
|    restart_samba_service=false | ||||
|    manual_hosts_file="${rcopy_base_dir}/conf/manual_hosts.conf" | ||||
| fi | ||||
|  | ||||
| ## - Note: the file "/var/lib/logrotate/status" must have | ||||
| ## - write permissions for the script-user | ||||
| ## - | ||||
| logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf" | ||||
| if [[ -f "$rcopy_base_dir/conf/logrotate.conf" ]]; then | ||||
|    logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf" | ||||
| elif [[ -f "$rcopy_base_dir/conf/logrotate.conf.sample" ]]; then | ||||
|    logrotate_conf_file="$rcopy_base_dir/conf/logrotate.conf.sample" | ||||
| else | ||||
|    logrotate_conf_file="" | ||||
| fi | ||||
|  | ||||
| [ -f $rcopy_functions_file ] || exit 1 | ||||
| . $rcopy_functions_file | ||||
|  | ||||
| ## - load configuration | ||||
| ## - | ||||
| [ -f $rcopy_conf_file ] || exit 1 | ||||
| . $rcopy_conf_file | ||||
|  | ||||
| NO_NEW_BACKUP=false | ||||
| ONLY_BACKUP=false | ||||
| MANUAL=false | ||||
| while getopts BhNm opt ; do | ||||
|    case $opt in | ||||
|       B)    ONLY_BACKUP=true | ||||
|             ;; | ||||
|       m)    MANUAL=true | ||||
|             ;; | ||||
|       N)    NO_NEW_BACKUP=true | ||||
|             ;; | ||||
|       h)    usage | ||||
|             ;; | ||||
|       \?)   usage ;; | ||||
|    esac | ||||
| done | ||||
|  | ||||
| if $ONLY_BACKUP && $NO_NEW_BACKUP ; then | ||||
|    fatal "Parameter '-B' AND '-N' is not possible." | ||||
| fi | ||||
|  | ||||
| # - Be compartible with older configuration files | ||||
| # - | ||||
| if [ "X$remote_disk" = "X" ] ; then | ||||
| @@ -51,8 +74,35 @@ if [ "X$check_mountpoint" = "X" ] ; then | ||||
|    check_mountpoint=false | ||||
| fi | ||||
|  | ||||
| [ -f $rcopy_functions_file ] || exit 1 | ||||
| . $rcopy_functions_file | ||||
|  | ||||
| # ---------- | ||||
| # - Read commandline parameter | ||||
| # ---------- | ||||
|  | ||||
| if $MANUAL ; then | ||||
|    ## - this is for manual start, we don't want inform anyone and | ||||
|    ## - also don't restart any service | ||||
|    ## - | ||||
|    send_reminder=false | ||||
|    restart_samba_service=false | ||||
|    manual_hosts_file="${rcopy_base_dir}/conf/manual_hosts.conf" | ||||
| fi | ||||
|  | ||||
| if $NO_NEW_BACKUP ; then | ||||
|    ## - Note: the file "/var/lib/logrotate/status" must have | ||||
|    ## - write permissions for the script-user | ||||
|    ## - | ||||
|    if [[ -f "$rcopy_base_dir/conf/logrotate_handle-backups.conf" ]]; then | ||||
|       logrotate_conf_file="$rcopy_base_dir/conf/logrotate_handle-backups.conf" | ||||
|    elif [[ -f "$rcopy_base_dir/conf/logrotate_handle-backups.conf.sample" ]]; then | ||||
|       logrotate_conf_file="$rcopy_base_dir/conf/logrotate_handle-backups.conf.sample" | ||||
|    else | ||||
|       logrotate_conf_file="" | ||||
|    fi | ||||
|    logFile="/var/log/rcopy-handle_backups.log" | ||||
| fi | ||||
|  | ||||
| export logFile disk_label_log_file ONLY_BACKUP NO_NEW_BACKUP rcopy_base_dir rcopy_conf_file rcopy_functions_file | ||||
|  | ||||
| ## - if backup job already runs, stop execution.. | ||||
| ## - | ||||
| @@ -64,7 +114,7 @@ if mkdir "$LOCK_DIR" 2> /dev/null ; then | ||||
| else | ||||
|  | ||||
|    msg="[ Error ]: A previos instance of the backup script seems already be running.\n\tExiting now.." | ||||
|    if $manual ; then | ||||
|    if $MANUAL ; then | ||||
|       echo -e "\n$msg\n" | ||||
|    else | ||||
|       datum=`date +"%d.%m.%Y"` | ||||
| @@ -80,12 +130,17 @@ else | ||||
|  | ||||
| fi | ||||
|  | ||||
| echo "" | ||||
| echo "MANUAL:        $MANUAL" | ||||
| echo "NO_NEW_BACKUP: $NO_NEW_BACKUP" | ||||
|  | ||||
|  | ||||
| if $check_mountpoint ; then | ||||
|    if [[ ! -d $backup_mountpoint ]];then | ||||
|       msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n" | ||||
|       msg01="           exiting now.." | ||||
|       msg="${msg00}\n${msg01}" | ||||
|       if $manual ; then | ||||
|       if $MANUAL ; then | ||||
|          echo -e "\n$msg\n" | ||||
|       else | ||||
|          datum=`date +"%d.%m.%Y"` | ||||
| @@ -108,7 +163,7 @@ if $extern_usb_disk || $extern_sata_disk || $intern_disk ; then | ||||
|    sleep 2 | ||||
|    if ! df | grep "$backup_partition" > /dev/null 2>&1 ;then | ||||
|       msg="[ Error ]: Cannot mount Backup Partion \"$backup_partition\". exiting now.." | ||||
|       if $manual ; then | ||||
|       if $MANUAL ; then | ||||
|          echo -e "\n$msg\n" | ||||
|       else | ||||
|          datum=`date +"%d.%m.%Y"` | ||||
| @@ -126,7 +181,7 @@ elif $remote_disk ; then | ||||
|    sleep 2 | ||||
|    if ! df | grep "$backup_mountpoint" > /dev/null 2>&1 ;then | ||||
|       msg="[ Error ]: Mounting remote disk to '$backup_mountpoint' failed. exiting now.." | ||||
|       if $manual ; then | ||||
|       if $MANUAL ; then | ||||
|          echo -e "\n$msg\n" | ||||
|       else | ||||
|          datum=`date +"%d.%m.%Y"` | ||||
| @@ -140,7 +195,7 @@ elif $remote_disk ; then | ||||
| #      msg00="[ Error ]: Mountpoint \"$backup_mountpoint\" for Backup Partion \"$backup_partition\" not found.\n" | ||||
| #      msg01="           exiting now.." | ||||
| #      msg="${msg00}\n${msg01}" | ||||
| #      if $manual ; then | ||||
| #      if $MANUAL ; then | ||||
| #         echo -e "\n$msg\n" | ||||
| #      else | ||||
| #         datum=`date +"%d.%m.%Y"` | ||||
| @@ -154,7 +209,7 @@ if $extern_usb_disk || $extern_sata_disk || $intern_disk || $remote_disk ; then | ||||
|    sleep 2 | ||||
|    if ! df | grep "$backup_partition" > /dev/null 2>&1 ;then | ||||
|       msg="[ Error ]: Cannot mount Backup Partion \"$backup_partition\". exiting now.." | ||||
|       if $manual ; then | ||||
|       if $MANUAL ; then | ||||
|          echo -e "\n$msg\n" | ||||
|       else | ||||
|          datum=`date +"%d.%m.%Y"` | ||||
| @@ -183,7 +238,7 @@ if [ ! -O $AGENT ]; then | ||||
|    msg_02="\t !! BACKUP INTERUPTED !!" | ||||
|    msg_03="As user \"$USER\" do:\n\tssh-agent > $AGENT; . $AGENT; ssh-add" | ||||
|    msg="${msg_00}\n\n${msg_01}\n${msg_02}\n${msg_01}\n\n${msg_03}" | ||||
|    if $manual ; then | ||||
|    if $MANUAL ; then | ||||
|       echo -e "\n$msg\n" | ||||
|    else | ||||
|       datum=`date +"%d.%m.%Y"` | ||||
| @@ -202,7 +257,7 @@ if [ ! `$ps aux | $grep -e"^$USER" | $grep "$SSH_AGENT_PID" | $grep ssh-agent | | ||||
|    msg_02="\t !! BACKUP INTERUPTED !!" | ||||
|    msg_03="As user \"$USER\" do:\n\tssh-agent > $AGENT; . $AGENT; ssh-add" | ||||
|    msg="${msg_00}\n\n${msg_01}\n${msg_02}\n${msg_01}\n\n${msg_03}" | ||||
|    if $manual ; then | ||||
|    if $MANUAL ; then | ||||
|       echo -e "$msg\n" | ||||
|    else | ||||
|       datum=`date +"%d.%m.%Y"` | ||||
| @@ -222,7 +277,7 @@ if [ ! $? -eq 0 ]; then | ||||
|    msg_02="\t !! BACKUP INTERUPTED !!" | ||||
|    msg_03="As user \"$USER\" do:\n\tssh-agent > $AGENT; . $AGENT; ssh-add" | ||||
|    msg="${msg_00}\n\n${msg_01}\n${msg_02}\n${msg_01}\n\n${msg_03}" | ||||
|    if $manual ; then | ||||
|    if $MANUAL ; then | ||||
|       echo -e "\n$msg\n" | ||||
|    else | ||||
|       datum=`date +"%d.%m.%Y"` | ||||
| @@ -237,7 +292,7 @@ fi | ||||
| ## - searching hosts for backup | ||||
| ## - | ||||
| host_scripts="" | ||||
| if $manual ; then | ||||
| if $MANUAL ; then | ||||
|    if [[ -f "$manual_hosts_file" ]] ; then | ||||
|       source "$manual_hosts_file" | ||||
|       for script in $hosts ; do | ||||
|   | ||||
| @@ -1,8 +1,6 @@ | ||||
| #!/usr/bin/env bash | ||||
|  | ||||
| manual=${manual:=true} | ||||
|  | ||||
| script_dir=$(realpath `dirname $0`) | ||||
| $script_dir/rcopy.sh true | ||||
| $script_dir/rcopy.sh -m $* | ||||
|  | ||||
| exit $? | ||||
|   | ||||
		Reference in New Issue
	
	Block a user