From d64b3d47fb562450eaaacd21ebc59fb11ee2d9cf Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Tue, 21 May 2024 10:27:34 -0700 Subject: [PATCH] clean up help(), add -n (dryrun) opt --- sbin/bashup-list-backups.sh | 20 ++++++++++---------- sbin/bashup-restore-files.sh | 32 ++++++++++++++++++++------------ sbin/bashup-restore-mysql.sh | 27 +++++++++++++++++---------- sbin/bashup-restore-pdns.sh | 27 +++++++++++++++++---------- sbin/bashup.sh | 5 +++++ 5 files changed, 69 insertions(+), 42 deletions(-) diff --git a/sbin/bashup-list-backups.sh b/sbin/bashup-list-backups.sh index 09f649b..0672a8d 100755 --- a/sbin/bashup-list-backups.sh +++ b/sbin/bashup-list-backups.sh @@ -16,17 +16,17 @@ help() echo "" echo "List backups that have been taken and are available for doing restores." echo "" - echo "Usage: $thisfilename [-b BACKUPDATE] [-c CATEGORY]" + echo "Usage: $thisfilename [-b ] [-c ] [-h]" echo "" - echo " -b BACKUPDATE Backup date/archive to list." - echo " -c CATEGORY Category of backup to verify/list." - echo " -h Print this help." - echo " If no options are specified a list of backup (dates)" - echo " will be displayed. If only the -b option is used then" - echo " a list of available categories (directories) will be" - echo " displayed. If both -b & -c options are specified then" - echo " the specific backups (files/directories, databases," - echo " dns zones) available for restoring will be displayed." + echo " -b Backup date/archive to list." + echo " -c Category of backup to verify/list." + echo " -h Print this help." + echo " If no options are specified a list of backup (dates)" + echo " will be displayed. If only the -b option is used then" + echo " a list of available categories (directories) will be" + echo " displayed. If both -b & -c options are specified then" + echo " the specific backups (files/directories, databases," + echo " dns zones) available for restoring will be displayed." exit } diff --git a/sbin/bashup-restore-files.sh b/sbin/bashup-restore-files.sh index 8310938..98f1413 100755 --- a/sbin/bashup-restore-files.sh +++ b/sbin/bashup-restore-files.sh @@ -16,19 +16,20 @@ help() echo "" echo "Restore file(s) from backup." echo "" - echo "Usage: $thisfilename [-b BACKUPDATE] [-p PATH]" + echo "Usage: $thisfilename [-b ] [-p ] [-n] [-h]" echo "" - echo " -b BACKUPDATE Backup date/archive to restore from." - echo " -p PATH Path to file or directory to restore." - echo " -h Print this help." - echo " You will be prompted to select backup date and file" - echo " or directory if not specified on the command line" - echo " with the above options." + echo " -b Backup date/archive to restore from." + echo " -p Path to file or directory to restore." + echo " -n Dry-run - don't actually restore, just echo commands needed for restore." + echo " -h Print this help." + echo " You will be prompted to select backup date and file" + echo " or directory if not specified on the command line" + echo " with the above options." exit } # set any options that were passed -while getopts "b:p:h" opt; do +while getopts "b:np:h" opt; do case "${opt}" in h ) help @@ -36,6 +37,9 @@ while getopts "b:p:h" opt; do b ) backup=${OPTARG} ;; + n ) + dryrun=${OPTARG} + ;; p ) pathtorestore=${OPTARG} ;; @@ -123,10 +127,14 @@ if [[ $verify_back_dir == FALSE ]]; then exit 1 fi -# perform restore -echo "Running:" -echo "/usr/bin/rsync -v --archive --numeric-ids --one-file-system --delete $pathtobackup $pathtorestore" -/usr/bin/rsync -v --archive --numeric-ids --one-file-system --delete $pathtobackup $pathtorestore +if [[ -n $dryrun ]]; then + echo $MOUNT + echo "/usr/bin/rsync -v --archive --numeric-ids --one-file-system --delete $pathtobackup $pathtorestore" + echo $UMOUNT +else + # perform restore + /usr/bin/rsync -v --archive --numeric-ids --one-file-system --delete $pathtobackup $pathtorestore +fi bashup::unmount_storage_dir diff --git a/sbin/bashup-restore-mysql.sh b/sbin/bashup-restore-mysql.sh index 275a0ab..e60c4b2 100755 --- a/sbin/bashup-restore-mysql.sh +++ b/sbin/bashup-restore-mysql.sh @@ -16,14 +16,15 @@ help() echo "" echo "Restore database from backup." echo "" - echo "Usage: $thisfilename [-b BACKUPDATE] [-d DATABASE]" + echo "Usage: $thisfilename [-b ] [-d ] [-n] [-h]" echo "" - echo " -b BACKUPDATE Backup date/archive to restore from." - echo " -d DATABASE Database to restore." - echo " -h Print this help." - echo " You will be prompted to select backup date and/or" - echo " database name from a list of available options" - echo " if they are not specified on the command line." + echo " -b Backup date/archive to restore from." + echo " -d Database to restore." + echo " -n Dry-run - don't actually restore, just echo commands needed for restore." + echo " -h Print this help." + echo " You will be prompted to select backup date and/or" + echo " database name from a list of available options" + echo " if they are not specified on the command line." exit } @@ -100,9 +101,15 @@ fi # check that dump exists and restore it now if [ -d $backup_storage_dir/$backup ]; then if [ -f $backup_storage_dir/$backup/mysql/$dump ]; then - echo "running:" - echo "/usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database" - /usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database + if [[ -n $dryrun ]]; then + echo $MOUNT + echo "/usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database" + echo $UMOUNT + else + echo "running:" + echo "/usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database" + /usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database + fi else echo "ERROR: Dump for database $database does not exist in the $backup backup dir." exit 1 diff --git a/sbin/bashup-restore-pdns.sh b/sbin/bashup-restore-pdns.sh index 7b84662..ee22994 100755 --- a/sbin/bashup-restore-pdns.sh +++ b/sbin/bashup-restore-pdns.sh @@ -16,14 +16,15 @@ help() echo "" echo "Restore database from backup." echo "" - echo "Usage: $thisfilename [-b BACKUPDATE] [-z ZONE]" + echo "Usage: $thisfilename [-b ] [-z ] [-n] [-h]" echo "" - echo " -b BACKUPDATE Backup date/archive to restore from." - echo " -z ZONE DNS Zone to restore." - echo " -h Print this help." - echo " You will be prompted to select backup date and/or" - echo " zone name from a list of available options" - echo " if they are not specified on the command line." + echo " -b Backup date/archive to restore from." + echo " -z DNS Zone to restore." + echo " -n Dry-run - don't actually restore, just echo commands needed for restore." + echo " -h Print this help." + echo " You will be prompted to select backup date and/or" + echo " zone name from a list of available options" + echo " if they are not specified on the command line." exit } @@ -100,9 +101,15 @@ fi # check that dump exists and restore it now if [ -d $backup_storage_dir/$backup ]; then if [ -f $backup_storage_dir/$backup/pdns/$zone_file ]; then - echo "running:" - echo "/usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file" - /usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file + if [[ -n $dryrun ]]; then + echo $MOUNT + echo "/usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file" + echo $UMOUNT + else + echo "running:" + echo "/usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file" + /usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file + fi else echo "ERROR: Zone file for zone $zone does not exist in the $backup backup dir." exit 1 diff --git a/sbin/bashup.sh b/sbin/bashup.sh index 4264567..ce18f36 100755 --- a/sbin/bashup.sh +++ b/sbin/bashup.sh @@ -90,6 +90,11 @@ if [ -d $backup_storage_dir ]; then if [ $? -ne 0 ]; then echo "ERROR: failed to mount $backup_storage_dir" exit 1 + else + if [[ -n $dryrun ]]; then + MOUNT="mount $backup_storage_dir" + UMOUNT="umount $backup_storage_dir" + fi fi fi fi