45 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
# Variables
SOURCE_DIR="/tmp/db1_backup/"
DEST_DIR="thevault:/nexus/postgresql/db1/"
DATE=$(date +%Y%m%d%H%M)
PG_USER="postgres"
SOURCE_SERVER="zcluster.technodrome1.sshjunkie.com" # Source server (database server)
SOURCE_REMOTE="technodrome1" # rclone remote for source server (configured earlier)
DEST_REMOTE="thevault" # rclone remote for destination server (The Vault)
# Step 1: SSH into the database server and run pg_basebackup
echo "Starting pg_basebackup for db1 on $SOURCE_SERVER..."
ssh doc@$SOURCE_SERVER "pg_basebackup -h localhost -D $SOURCE_DIR$DATE -U $PG_USER -Ft -z -P"
# Check if pg_basebackup was successful
if [ $? -eq 0 ]; then
echo "pg_basebackup completed successfully. Proceeding to rclone transfer..."
# Step 2: Use rclone to copy the backup from the source server to The Vault
rclone copy $SOURCE_REMOTE:$SOURCE_DIR$DATE/ $DEST_REMOTE:$DEST_DIR --progress --checksum
# Check if rclone was successful
if [ $? -eq 0 ]; then
echo "Rclone transfer completed successfully. Proceeding to snapshot..."
# Step 3: Create a ZFS snapshot on The Vault
ssh root@thevault.sshjunkie.com "sudo zfs snapshot nexus/postgresql/db1@$DATE"
# Verify snapshot creation on The Vault
if [ $? -eq 0 ]; then
echo "ZFS snapshot nexus/postgresql/db1@$DATE created successfully on The Vault."
else
echo "Error creating ZFS snapshot on The Vault."
fi
else
echo "Error during rclone transfer. Backup not transferred."
exit 1
fi
else
echo "Error during pg_basebackup. Backup not created."
exit 1
fi