clean up help(), add -n (dryrun) opt

This commit is contained in:
Matthew Saunders Brown 2024-05-21 10:27:34 -07:00
parent d946245f30
commit d64b3d47fb
5 changed files with 69 additions and 42 deletions

View File

@ -16,17 +16,17 @@ help()
echo "" echo ""
echo "List backups that have been taken and are available for doing restores." echo "List backups that have been taken and are available for doing restores."
echo "" echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-c CATEGORY]" echo "Usage: $thisfilename [-b <backupdate>] [-c <category>] [-h]"
echo "" echo ""
echo " -b BACKUPDATE Backup date/archive to list." echo " -b <backupdate> Backup date/archive to list."
echo " -c CATEGORY Category of backup to verify/list." echo " -c <category> Category of backup to verify/list."
echo " -h Print this help." echo " -h Print this help."
echo " If no options are specified a list of backup (dates)" echo " If no options are specified a list of backup (dates)"
echo " will be displayed. If only the -b option is used then" echo " will be displayed. If only the -b option is used then"
echo " a list of available categories (directories) will be" echo " a list of available categories (directories) will be"
echo " displayed. If both -b & -c options are specified then" echo " displayed. If both -b & -c options are specified then"
echo " the specific backups (files/directories, databases," echo " the specific backups (files/directories, databases,"
echo " dns zones) available for restoring will be displayed." echo " dns zones) available for restoring will be displayed."
exit exit
} }

View File

@ -16,19 +16,20 @@ help()
echo "" echo ""
echo "Restore file(s) from backup." echo "Restore file(s) from backup."
echo "" echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-p PATH]" echo "Usage: $thisfilename [-b <backupdate>] [-p <path>] [-n] [-h]"
echo "" echo ""
echo " -b BACKUPDATE Backup date/archive to restore from." echo " -b <backupdate> Backup date/archive to restore from."
echo " -p PATH Path to file or directory to restore." echo " -p <path> Path to file or directory to restore."
echo " -h Print this help." echo " -n Dry-run - don't actually restore, just echo commands needed for restore."
echo " You will be prompted to select backup date and file" echo " -h Print this help."
echo " or directory if not specified on the command line" echo " You will be prompted to select backup date and file"
echo " with the above options." echo " or directory if not specified on the command line"
echo " with the above options."
exit exit
} }
# set any options that were passed # set any options that were passed
while getopts "b:p:h" opt; do while getopts "b:np:h" opt; do
case "${opt}" in case "${opt}" in
h ) h )
help help
@ -36,6 +37,9 @@ while getopts "b:p:h" opt; do
b ) b )
backup=${OPTARG} backup=${OPTARG}
;; ;;
n )
dryrun=${OPTARG}
;;
p ) p )
pathtorestore=${OPTARG} pathtorestore=${OPTARG}
;; ;;
@ -123,10 +127,14 @@ if [[ $verify_back_dir == FALSE ]]; then
exit 1 exit 1
fi fi
# perform restore if [[ -n $dryrun ]]; then
echo "Running:" echo $MOUNT
echo "/usr/bin/rsync -v --archive --numeric-ids --one-file-system --delete $pathtobackup $pathtorestore" 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 echo $UMOUNT
else
# perform restore
/usr/bin/rsync -v --archive --numeric-ids --one-file-system --delete $pathtobackup $pathtorestore
fi
bashup::unmount_storage_dir bashup::unmount_storage_dir

View File

@ -16,14 +16,15 @@ help()
echo "" echo ""
echo "Restore database from backup." echo "Restore database from backup."
echo "" echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-d DATABASE]" echo "Usage: $thisfilename [-b <backupdate>] [-d <database>] [-n] [-h]"
echo "" echo ""
echo " -b BACKUPDATE Backup date/archive to restore from." echo " -b <backupdate> Backup date/archive to restore from."
echo " -d DATABASE Database to restore." echo " -d <database> Database to restore."
echo " -h Print this help." echo " -n Dry-run - don't actually restore, just echo commands needed for restore."
echo " You will be prompted to select backup date and/or" echo " -h Print this help."
echo " database name from a list of available options" echo " You will be prompted to select backup date and/or"
echo " if they are not specified on the command line." echo " database name from a list of available options"
echo " if they are not specified on the command line."
exit exit
} }
@ -100,9 +101,15 @@ fi
# check that dump exists and restore it now # check that dump exists and restore it now
if [ -d $backup_storage_dir/$backup ]; then if [ -d $backup_storage_dir/$backup ]; then
if [ -f $backup_storage_dir/$backup/mysql/$dump ]; then if [ -f $backup_storage_dir/$backup/mysql/$dump ]; then
echo "running:" if [[ -n $dryrun ]]; then
echo "/usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database" echo $MOUNT
/usr/bin/zcat $backup_storage_dir/$backup/mysql/$dump | mysql --defaults-extra-file=$mysql_defaults_extra_file $database 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 else
echo "ERROR: Dump for database $database does not exist in the $backup backup dir." echo "ERROR: Dump for database $database does not exist in the $backup backup dir."
exit 1 exit 1

View File

@ -16,14 +16,15 @@ help()
echo "" echo ""
echo "Restore database from backup." echo "Restore database from backup."
echo "" echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-z ZONE]" echo "Usage: $thisfilename [-b <backupdate>] [-z <zone>] [-n] [-h]"
echo "" echo ""
echo " -b BACKUPDATE Backup date/archive to restore from." echo " -b <backupdate> Backup date/archive to restore from."
echo " -z ZONE DNS Zone to restore." echo " -z <zone> DNS Zone to restore."
echo " -h Print this help." echo " -n Dry-run - don't actually restore, just echo commands needed for restore."
echo " You will be prompted to select backup date and/or" echo " -h Print this help."
echo " zone name from a list of available options" echo " You will be prompted to select backup date and/or"
echo " if they are not specified on the command line." echo " zone name from a list of available options"
echo " if they are not specified on the command line."
exit exit
} }
@ -100,9 +101,15 @@ fi
# check that dump exists and restore it now # check that dump exists and restore it now
if [ -d $backup_storage_dir/$backup ]; then if [ -d $backup_storage_dir/$backup ]; then
if [ -f $backup_storage_dir/$backup/pdns/$zone_file ]; then if [ -f $backup_storage_dir/$backup/pdns/$zone_file ]; then
echo "running:" if [[ -n $dryrun ]]; then
echo "/usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file" echo $MOUNT
/usr/bin/pdnsutil load-zone $zone $backup_storage_dir/$backup/pdns/$zone_file 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 else
echo "ERROR: Zone file for zone $zone does not exist in the $backup backup dir." echo "ERROR: Zone file for zone $zone does not exist in the $backup backup dir."
exit 1 exit 1

View File

@ -90,6 +90,11 @@ if [ -d $backup_storage_dir ]; then
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: failed to mount $backup_storage_dir" echo "ERROR: failed to mount $backup_storage_dir"
exit 1 exit 1
else
if [[ -n $dryrun ]]; then
MOUNT="mount $backup_storage_dir"
UMOUNT="umount $backup_storage_dir"
fi
fi fi
fi fi
fi fi