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 "List backups that have been taken and are available for doing restores."
echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-c CATEGORY]"
echo "Usage: $thisfilename [-b <backupdate>] [-c <category>] [-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 <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."
exit
}

View File

@ -16,19 +16,20 @@ help()
echo ""
echo "Restore file(s) from backup."
echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-p PATH]"
echo "Usage: $thisfilename [-b <backupdate>] [-p <path>] [-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 <backupdate> Backup date/archive to restore from."
echo " -p <path> 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

View File

@ -16,14 +16,15 @@ help()
echo ""
echo "Restore database from backup."
echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-d DATABASE]"
echo "Usage: $thisfilename [-b <backupdate>] [-d <database>] [-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 <backupdate> Backup date/archive to restore from."
echo " -d <database> 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

View File

@ -16,14 +16,15 @@ help()
echo ""
echo "Restore database from backup."
echo ""
echo "Usage: $thisfilename [-b BACKUPDATE] [-z ZONE]"
echo "Usage: $thisfilename [-b <backupdate>] [-z <zone>] [-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 <backupdate> Backup date/archive to restore from."
echo " -z <zone> 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

View File

@ -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