66 lines
1.4 KiB
Bash
Executable file
66 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 TARGET"
|
|
exit -2
|
|
fi
|
|
|
|
err_report() {
|
|
echo "Error on line $1"
|
|
backup_post
|
|
exit -1
|
|
}
|
|
|
|
trap 'err_report $LINENO' ERR
|
|
|
|
ssh() {
|
|
/usr/bin/env -S ssh -o PasswordAuthentication=no "$@"
|
|
}
|
|
|
|
backup_host="rex.do.netdeneb.com"
|
|
backup_user="backupuser"
|
|
timestamp="$(date +%Y-%m-%d_%H%M)"
|
|
|
|
# MUST set up the following:
|
|
# - backup_pre()
|
|
# - backup_post()
|
|
# - $local_path (directly or in backup_pre())
|
|
# - $backup_path (directly or in backup_pre())
|
|
# MUST NOT call backup_pre or backup_post
|
|
# MAY set up $rsync_extra_args
|
|
# MAY rely on $backup_host, $backup_user and $timestamp
|
|
source "/opt/backuprunner/targets/$1.sh"
|
|
|
|
|
|
backup_pre
|
|
|
|
|
|
if ! ssh "$backup_user"@"$backup_host" "stat \"$backup_path\"" >/dev/null 2>&1; then
|
|
echo "Creating repository '$backup_path'"
|
|
borg init \
|
|
--encryption=none \
|
|
--make-parent-dirs \
|
|
"$backup_user"@"$backup_host":"$backup_path"
|
|
fi
|
|
|
|
pushd "$local_path"
|
|
echo "Creating archive '$backup_path::$timestamp'"
|
|
borg create \
|
|
--stats \
|
|
--compression=zstd,5 \
|
|
"${borg_extra_args[@]}" \
|
|
"$backup_user"@"$backup_host":"$backup_path"::"$timestamp" \
|
|
.
|
|
popd
|
|
|
|
|
|
#ssh "$backup_user"@"$backup_host" "mkdir -p \"$backup_path\""
|
|
|
|
#echo "Synchronise backup folder with local state"
|
|
#rsync --compress --archive --delete \
|
|
# "${rsync_extra_args[@]}" \
|
|
# "$local_path" \
|
|
# "$backup_user"@"$backup_host":"$backup_path"
|
|
|
|
|
|
backup_post
|