Added option to override existing config file - the script will exit if the option is not set and there is an existing config
This commit is contained in:
parent
0c1d60ca22
commit
455dbbcd30
@ -30,6 +30,9 @@
|
||||
# - Check for already existing backup repository
|
||||
# - Check for already existing borgmatic configuration file
|
||||
|
||||
# TODO:
|
||||
# - Invert the logic for upgrades (only upgrade if DO_UPGRADE is set) - this also includes upgrading single packages
|
||||
|
||||
# SETTINGS - Make sure to adjust these settings to your needs
|
||||
DEBUG=0 # Set to 1 to enable debug mode
|
||||
|
||||
@ -58,6 +61,7 @@ NO_UPGRADE=0
|
||||
FIRST_BACKUP=0
|
||||
IS_REMOTE_SYNOLGY=0
|
||||
OVERRIDE_CRONTAB=0
|
||||
OVERRIDE_CONFIG=0
|
||||
|
||||
# constants
|
||||
readonly SCRIPT_NAME="Borgmatic Backup Setup Tool"
|
||||
@ -358,11 +362,12 @@ function is_remote_synology {
|
||||
# Available arguments:
|
||||
# -a, --auto: Enable automatic, non-interactive mode
|
||||
# -d, --debug: Enable debug mode
|
||||
# -v, --version: Show script version
|
||||
# -h, --help: Show help message
|
||||
# -n, --no-upgrade: Skip package upgrades
|
||||
# -f, --first-backup: Run the first backup after setup
|
||||
# -o, --override-crontab: Override the existing crontab file
|
||||
# -c, --override-config: Override the existing borgmatic configuration file
|
||||
# -v, --version: Show script version
|
||||
# -h, --help: Show help message
|
||||
#
|
||||
# -R, --repo: Set the backup repository path
|
||||
# -E, --encryption: Set the encryption method
|
||||
@ -435,6 +440,10 @@ while [[ $# -gt 0 ]]; do
|
||||
OVERRIDE_CRONTAB=1
|
||||
shift
|
||||
;;
|
||||
-c|--override-config)
|
||||
OVERRIDE_CONFIG=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
inf "Usage: borgmatic_setup.sh [options]"
|
||||
inf ""
|
||||
@ -450,6 +459,7 @@ while [[ $# -gt 0 ]]; do
|
||||
inf " -d, --debug: Enable debug mode"
|
||||
inf " -f, --first-backup: Run the first backup after setup"
|
||||
inf " -o, --override-crontab: Override the existing crontab file"
|
||||
inf " -c, --override-config: Override the existing borgmatic configuration file"
|
||||
inf " -v, --version: Show script version"
|
||||
inf " -h, --help: Show help message"
|
||||
inf ""
|
||||
@ -592,6 +602,14 @@ inf "Backup directories: $BACKUP_DIRS"
|
||||
inf "Backup cron schedule: $BACKUP_CRON_SCHEDULE"
|
||||
inf "Backup server host: $SSH_USER@$SSH_HOST:$SSH_PORT"
|
||||
|
||||
if [ -z $OVERRIDE_CRONTAB ]; then
|
||||
wrn "Existing cron job at /etc/cron.d/borgmatic will be overridden!"
|
||||
fi
|
||||
|
||||
if [ -z $OVERRIDE_CONFIG ]; then
|
||||
wrn "Existing borgmatic configuration file at $BORGMATIC_CONFIG_FILE will be overridden!"
|
||||
fi
|
||||
|
||||
# only ask for confirmation in interactive mode
|
||||
if [ -z $AUTO ] && ! wrnp "Do you want to continue? [y/N]"; then
|
||||
inf "Aborted."
|
||||
@ -794,6 +812,15 @@ if [ "${BACKUP_REPO:0:1}" == "/" ]; then
|
||||
BACKUP_REPO=${BACKUP_REPO:1}
|
||||
fi
|
||||
|
||||
# check if borgmatic configuration file already exists and abort if $OVERRIDE_CONFIG is not set
|
||||
if [ -f $BORGMATIC_CONFIG_FILE ] && [ $OVERRIDE_CONFIG -ne 1 ]; then
|
||||
err "A borgmatic configuration file already exists at $BORGMATIC_CONFIG_FILE."
|
||||
err "Please remove the existing configuration file or use the --override-config option."
|
||||
exit 1
|
||||
elif [ -f $BORGMATIC_CONFIG_FILE ] && [ $OVERRIDE_CONFIG -eq 1 ]; then
|
||||
wrn "Existing borgmatic configuration file will be overridden!"
|
||||
fi
|
||||
|
||||
cat > $BORGMATIC_CONFIG_FILE <<EOF
|
||||
|
||||
ssh_command: ssh -i $SSH_KEY_FILE -p $SSH_PORT
|
||||
|
Reference in New Issue
Block a user