Make rsync command args semi-customizable

This commit is contained in:
Alice Gaudon 2019-11-17 09:53:14 +01:00
parent 6408d54edb
commit 2e76ca954f

View File

@ -14,7 +14,7 @@ if ! lockfile-create -p -r 2 $0; then
echo "Another backup is running, aborting" echo "Another backup is running, aborting"
exit 1 exit 1
fi fi
### Program arguments ### ### Program arguments ###
# Backup target directory # Backup target directory
@ -39,6 +39,8 @@ BACKUP_ROOT=$6
# Backup archive path, change it for each backup # Backup archive path, change it for each backup
BACKUP_ARCHIVE=$7 BACKUP_ARCHIVE=$7
# Backup additional arguments
BACKUP_ARGS=$8
### Backup automatic properties ### ### Backup automatic properties ###
BACKUP_ROOT_PATH="$(cat /etc/hostname)" BACKUP_ROOT_PATH="$(cat /etc/hostname)"
@ -46,17 +48,32 @@ BACKUP_BASE_PATH="$BACKUP_ROOT_PATH/$BACKUP_ROOT"
BACKUP_CONTENTS_PATH="$BACKUP_BASE_PATH/_backup/" BACKUP_CONTENTS_PATH="$BACKUP_BASE_PATH/_backup/"
RSYNC_BASE_CMD=(rsync --timeout=30 --protocol=30 -avzhP)
RSYNC_BASE_CMD+=("$BACKUP_ARGS")
RSYNC_STRUCTURE_CMD=${RSYNC_BASE_CMD[*]}
RSYNC_STRUCTURE_CMD+=(--relative $BACKUP_CONTENTS_PATH $BACKUP_TARGET)
RSYNC_DATA_CMD=${RSYNC_BASE_CMD[*]}
RSYNC_DATA_CMD+=(--delete --inplace $BACKUP_EXCLUSIONS --backup --backup-dir=../$BACKUP_ARCHIVE $BACKUP_DIRECTORY $BACKUP_TARGET/$BACKUP_CONTENTS_PATH)
echo "Starting backup. Target: $BACKUP_BASE_PATH. Archive: $BACKUP_ARCHIVE" echo "Starting backup. Target: $BACKUP_BASE_PATH. Archive: $BACKUP_ARCHIVE"
### Before Script ### ### Before Script ###
echo "Before script ..."
eval "$BEFORE_SCRIPT" eval "$BEFORE_SCRIPT"
echo "Done"
### Create local model of the remote's backup directory tree and send it ### ### Create local model of the remote's backup directory tree and send it ###
echo "Directory structure..."
mkdir -p "$BACKUP_CONTENTS_PATH" mkdir -p "$BACKUP_CONTENTS_PATH"
rsync --timeout=30 --protocol=30 -avzhP --relative $BACKUP_CONTENTS_PATH $BACKUP_TARGET eval ${RSYNC_STRUCTURE_CMD[*]}
echo "Done"
### Backup home directory except some unwanted files ### ### Backup home directory except some unwanted files ###
rsync --timeout=30 --protocol=30 -avzhP --delete --inplace $BACKUP_EXCLUSIONS --backup --backup-dir=../$BACKUP_ARCHIVE $BACKUP_DIRECTORY $BACKUP_TARGET/$BACKUP_CONTENTS_PATH echo "Backup data..."
eval ${RSYNC_DATA_CMD[*]}
echo "Done"
### Remove local model of the backup directory tree ### ### Remove local model of the backup directory tree ###
rm -R "$BACKUP_ROOT_PATH" rm -R "$BACKUP_ROOT_PATH"