2022-05-20 15:06:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-10-29 15:34:17 +00:00
|
|
|
set -eu
|
2022-05-20 15:06:41 +00:00
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
2023-02-01 19:44:05 +00:00
|
|
|
# this script backups up a source path to a destination folder on the remote VM
|
|
|
|
# then pulls that data down to the maanagement environment
|
2022-09-29 17:14:51 +00:00
|
|
|
|
|
|
|
# if the source files to backup don't exist on the remote host, we return.
|
2022-10-08 16:44:46 +00:00
|
|
|
if ! ssh "$PRIMARY_WWW_FQDN" "[ -d $REMOTE_SOURCE_BACKUP_PATH ]"; then
|
2022-09-29 17:14:51 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-10-08 16:44:46 +00:00
|
|
|
ssh "$PRIMARY_WWW_FQDN" sudo PASSPHRASE="$DUPLICITY_BACKUP_PASSPHRASE" duplicity "$REMOTE_SOURCE_BACKUP_PATH" "file://$REMOTE_BACKUP_PATH"
|
|
|
|
ssh "$PRIMARY_WWW_FQDN" sudo chown -R ubuntu:ubuntu "$REMOTE_BACKUP_PATH"
|
2022-09-28 17:59:01 +00:00
|
|
|
|
|
|
|
SSHFS_PATH="/tmp/sshfs_temp"
|
|
|
|
mkdir -p "$SSHFS_PATH"
|
2022-05-20 15:06:41 +00:00
|
|
|
|
|
|
|
# now let's pull down the latest files from the backup directory.
|
|
|
|
# create a temp directory to serve as the mountpoint for the remote machine backups directory
|
2022-10-08 16:44:46 +00:00
|
|
|
sshfs "$PRIMARY_WWW_FQDN:$REMOTE_BACKUP_PATH" "$SSHFS_PATH"
|
2022-05-20 15:06:41 +00:00
|
|
|
|
|
|
|
# rsync the files from the remote server to our local backup path.
|
|
|
|
rsync -av "$SSHFS_PATH/" "$LOCAL_BACKUP_PATH/"
|
|
|
|
|
|
|
|
# step 4: unmount the SSHFS filesystem and cleanup.
|
|
|
|
umount "$SSHFS_PATH"
|
|
|
|
rm -rf "$SSHFS_PATH"
|