1 Commits

Author SHA1 Message Date
Joe Clarke
6f7e71f713 Add untested support for a remote backup file. 2022-07-11 09:54:01 -04:00

View File

@@ -863,6 +863,10 @@ while true; do
shift shift
BACKUP_FILE=$1 BACKUP_FILE=$1
;; ;;
--remote-file)
shift
REMOTE_FILE=$1
;;
-b | --backup) -b | --backup)
BACKUP=1 BACKUP=1
;; ;;
@@ -936,13 +940,18 @@ if [ ${GET_SRC_DIRS} -eq 1 ]; then
exit 0 exit 0
fi fi
if [ -n "${REMOTE_HOST}" ] && [ -n "${BACKUP_FILE}" ]; then if [ -n "${REMOTE_HOST}" ] && ([ -n "${BACKUP_FILE}" ] || [ -n "${REMOTE_FILE}" ]); then
echo "Only one of --host or --file may be specified." echo "Only one of --host or --file or --remote-file may be specified."
exit 1 exit 1
fi fi
if [ -z "${REMOTE_HOST}" ] && [ -z "${BACKUP_FILE}" ]; then if [ -z "${REMOTE_HOST}" ] && [ -z "${BACKUP_FILE}" ] && [ -z "${REMOTE_FILE}" ]; then
echo "One of --host or --file must be specified." echo "One of --host or --file or --remote-file must be specified."
exit 1
fi
if [ -n "${BACKUP_FILE}" ] && [ -n "${REMOTE_FILE}" ]; then
echo "Only one of --file or --remote-file may be specified."
exit 1 exit 1
fi fi
@@ -1099,11 +1108,17 @@ else
done done
fi fi
BACKUP_FILE=$(realpath "${BACKUP_FILE}") if [ -n "${BACKUP_FILE}" ]; then
BACKUP_FILE=$(realpath "${BACKUP_FILE}")
# We are doing a dump to a single tar file. # We are doing a dump to a single tar file.
if ! check_disk_space "${SRC_DIRS}" "$(dirname "${BACKUP_FILE}")"; then if ! check_disk_space "${SRC_DIRS}" "$(dirname "${BACKUP_FILE}")"; then
exit $? exit $?
fi
else
RBACKUP_FILE=$(echo ${REMOTE_FILE} | cut -d':' -f2)
REMOTE_HOST=$(echo ${REMOTE_FILE} | cut -d':' -f1)
# TODO Add support for a port other than 22?
fi fi
if [ ${NO_CONFIRM} -eq 0 ]; then if [ ${NO_CONFIRM} -eq 0 ]; then
@@ -1147,13 +1162,21 @@ echo "Backing up ${SRC_DIRS}..."
echo "Backing up CML data to ${BACKUP_FILE}. Please be patient, this may take a while..." echo "Backing up CML data to ${BACKUP_FILE}. Please be patient, this may take a while..."
export total=$(du -shc /PRODUCT ${SRC_DIRS} libvirt_domains.dat libvirt_networks.dat libvirt_ifaces.dat -B10k --apparent-size | tail -1 | cut -f1) export total=$(du -shc /PRODUCT ${SRC_DIRS} libvirt_domains.dat libvirt_networks.dat libvirt_ifaces.dat -B10k --apparent-size | tail -1 | cut -f1)
tar -C "${tempd}" --acls --selinux --checkpoint=2000 --exclude="*.rej" --exclude="*.orig" --checkpoint-action=exec=' printf "\e[1;31m%s of %s copied %d/100%% complete \e[0m\r" $(numfmt --to=iec-i $((10000*${TAR_CHECKPOINT})) ) $(numfmt --to=iec-i $((10000*${total})) )\t$((100*${TAR_CHECKPOINT}/${total})) ' -cvpf "${BACKUP_FILE}" /PRODUCT libvirt_domains.dat libvirt_networks.dat libvirt_ifaces.dat ${SRC_DIRS} if [ -n "${BACKUP_FILE}" ]; then
tar -C "${tempd}" --acls --selinux --checkpoint=2000 --exclude="*.rej" --exclude="*.orig" --checkpoint-action=exec=' printf "\e[1;31m%s of %s copied %d/100%% complete \e[0m\r" $(numfmt --to=iec-i $((10000*${TAR_CHECKPOINT})) ) $(numfmt --to=iec-i $((10000*${total})) )\t$((100*${TAR_CHECKPOINT}/${total})) ' -cvpf "${BACKUP_FILE}" /PRODUCT libvirt_domains.dat libvirt_networks.dat libvirt_ifaces.dat ${SRC_DIRS}
else
tar -C "${tempd}" --acls --selinux --checkpoint=2000 --exclude="*.rej" --exclude="*.orig" --checkpoint-action=exec=' printf "\e[1;31m%s of %s copied %d/100%% complete \e[0m\r" $(numfmt --to=iec-i $((10000*${TAR_CHECKPOINT})) ) $(numfmt --to=iec-i $((10000*${total})) )\t$((100*${TAR_CHECKPOINT}/${total})) ' -cvpf - /PRODUCT libvirt_domains.dat libvirt_networks.dat libvirt_ifaces.dat ${SRC_DIRS} | ssh ${REMOTE_HOST} "cat > ${RBACKUP_FILE}"
fi
rc=$? rc=$?
echo echo
if [ ${rc} != 0 ]; then if [ ${rc} != 0 ]; then
echo "Backup completed with errors. See the output above for the error details." echo "Backup completed with errors. See the output above for the error details."
else else
echo "Backup completed SUCCESSFULLY. Backup file is ${BACKUP_FILE}." if [ -n "${BACKUP_FILE}" ]; then
echo "Backup completed SUCCESSFULLY. Backup file is ${BACKUP_FILE}."
else
echo "Backup completed SUCCESSFULLY. Backup file is ${RBACKUP_FILE} on host ${REMOTE_HOST}."
fi
fi fi
cleanup_backup cleanup_backup