Added check for existing repository on remote end and new option --override-repository
This commit is contained in:
parent
455dbbcd30
commit
504ba365b9
@ -56,12 +56,13 @@ SSH_KEY_FILE="/root/.ssh/${SSH_KEY_NAME}_${SSH_KEY_TYPE}"
|
|||||||
# SCRIPT - DO NOT EDIT
|
# SCRIPT - DO NOT EDIT
|
||||||
|
|
||||||
# internal variables
|
# internal variables
|
||||||
AUTO=0
|
AUTO=0 # Set to 1 to enable automatic, non-interactive mode
|
||||||
NO_UPGRADE=0
|
NO_UPGRADE=0 # Set to 1 to skip package upgrades
|
||||||
FIRST_BACKUP=0
|
FIRST_BACKUP=0 # Set to 1 to run the first backup after setup
|
||||||
IS_REMOTE_SYNOLGY=0
|
IS_REMOTE_SYNOLGY=0 # Set to 1 if the remote end is a Synology NAS
|
||||||
OVERRIDE_CRONTAB=0
|
OVERRIDE_CRONTAB=0 # Set to 1 to override the existing crontab file
|
||||||
OVERRIDE_CONFIG=0
|
OVERRIDE_CONFIG=0 # Set to 1 to override the existing borgmatic configuration file
|
||||||
|
OVERRIDE_REPOSITORY=0 # Set to 1 to override the existing backup repository
|
||||||
|
|
||||||
# constants
|
# constants
|
||||||
readonly SCRIPT_NAME="Borgmatic Backup Setup Tool"
|
readonly SCRIPT_NAME="Borgmatic Backup Setup Tool"
|
||||||
@ -366,6 +367,7 @@ function is_remote_synology {
|
|||||||
# -f, --first-backup: Run the first backup after setup
|
# -f, --first-backup: Run the first backup after setup
|
||||||
# -o, --override-crontab: Override the existing crontab file
|
# -o, --override-crontab: Override the existing crontab file
|
||||||
# -c, --override-config: Override the existing borgmatic configuration file
|
# -c, --override-config: Override the existing borgmatic configuration file
|
||||||
|
# -r, --override-repository: Override the existing backup repository
|
||||||
# -v, --version: Show script version
|
# -v, --version: Show script version
|
||||||
# -h, --help: Show help message
|
# -h, --help: Show help message
|
||||||
#
|
#
|
||||||
@ -444,6 +446,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
OVERRIDE_CONFIG=1
|
OVERRIDE_CONFIG=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-r|--override-repository)
|
||||||
|
OVERRIDE_REPOSITORY=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
inf "Usage: borgmatic_setup.sh [options]"
|
inf "Usage: borgmatic_setup.sh [options]"
|
||||||
inf ""
|
inf ""
|
||||||
@ -460,6 +466,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
inf " -f, --first-backup: Run the first backup after setup"
|
inf " -f, --first-backup: Run the first backup after setup"
|
||||||
inf " -o, --override-crontab: Override the existing crontab file"
|
inf " -o, --override-crontab: Override the existing crontab file"
|
||||||
inf " -c, --override-config: Override the existing borgmatic configuration file"
|
inf " -c, --override-config: Override the existing borgmatic configuration file"
|
||||||
|
inf " -r, --override-repository: Override the existing backup repository"
|
||||||
inf " -v, --version: Show script version"
|
inf " -v, --version: Show script version"
|
||||||
inf " -h, --help: Show help message"
|
inf " -h, --help: Show help message"
|
||||||
inf ""
|
inf ""
|
||||||
@ -859,6 +866,25 @@ if ! inf_follow "Validating borgmatic configuration..." "\e[1;32mOK\e[0m" "\e[1;
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check for existing borg repository and abort if $OVERRIDE_REPOSITORY is not set
|
||||||
|
if inf_follow "Checking for existing borgmatic repository..." "\e[1;32mYes\e[0m" "\e[1;31mNo\e[0m" run_command /root/.local/pipx/venvs/borgmatic/bin/borgmatic info; then
|
||||||
|
if [ $OVERRIDE_REPOSITORY -ne 1 ]; then
|
||||||
|
if [ -z $AUTO ] && ! wrnp "A borgmatic repository already exists. Do you want to override it? [y/N]"; then
|
||||||
|
err "A borgmatic repository already exists."
|
||||||
|
err "Please remove the existing repository or use the --override-repository option."
|
||||||
|
exit 1
|
||||||
|
elif [ $AUTO -eq 1 ]; then
|
||||||
|
err "A borgmatic repository already exists."
|
||||||
|
err "Please remove the existing repository or use the --override-repository option."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
wrn "Existing borgmatic repository will be overridden!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
inf "No existing borgmatic repository found."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ask for backup passphrase if none is set and encryption is enabled
|
# ask for backup passphrase if none is set and encryption is enabled
|
||||||
if [ -z "$BACKUP_PASSPHRASE" ] && [ "$BACKUP_ENCRYPTION" != "none" ]; then
|
if [ -z "$BACKUP_PASSPHRASE" ] && [ "$BACKUP_ENCRYPTION" != "none" ]; then
|
||||||
wrn "Please enter the passphrase for the backup encryption."
|
wrn "Please enter the passphrase for the backup encryption."
|
||||||
|
Reference in New Issue
Block a user