Update script
This commit is contained in:
parent
e2eaf98653
commit
e86c3276ae
1 changed files with 9 additions and 9 deletions
|
@ -229,7 +229,7 @@ verify_snapshot() {
|
||||||
|
|
||||||
# Function to verify remote connectivity
|
# Function to verify remote connectivity
|
||||||
verify_remote() {
|
verify_remote() {
|
||||||
if ! ssh -i /run/secrets/btrfs-backup/ssh_key -q "$REMOTE_HOST" "exit"; then
|
if ! ssh -i /run/secrets/btrfs-backups/ssh_key -q "$REMOTE_HOST" "exit"; then
|
||||||
send_notification "Backup Failed" "Cannot connect to remote host from $HOSTNME" 8
|
send_notification "Backup Failed" "Cannot connect to remote host from $HOSTNME" 8
|
||||||
log "ERROR: Cannot connect to remote host"
|
log "ERROR: Cannot connect to remote host"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -238,7 +238,7 @@ verify_remote() {
|
||||||
|
|
||||||
# Function to get remote snapshots
|
# Function to get remote snapshots
|
||||||
get_remote_snapshots() {
|
get_remote_snapshots() {
|
||||||
ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "find '$BASE_DEST_PATH' -maxdepth 1 -type d -name '[0-9]*' | sort -n"
|
ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "find '$BASE_DEST_PATH' -maxdepth 1 -type d -name '[0-9]*' | sort -n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to get local backup snapshots
|
# Function to get local backup snapshots
|
||||||
|
@ -260,13 +260,13 @@ cleanup_snapshots() {
|
||||||
local snapshot="${local_snapshots[$i]}"
|
local snapshot="${local_snapshots[$i]}"
|
||||||
|
|
||||||
# Delete remote snapshot first
|
# Delete remote snapshot first
|
||||||
if ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "[ -d '$BASE_DEST_PATH/$snapshot' ]"; then
|
if ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "[ -d '$BASE_DEST_PATH/$snapshot' ]"; then
|
||||||
log "Deleting remote snapshot: $snapshot"
|
log "Deleting remote snapshot: $snapshot"
|
||||||
if ! ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "btrfs subvolume delete '$BASE_DEST_PATH/$snapshot/snapshot'"; then
|
if ! ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "btrfs subvolume delete '$BASE_DEST_PATH/$snapshot/snapshot'"; then
|
||||||
send_notification "Backup Warning" "Failed to delete remote snapshot $snapshot on $HOSTNME" 6
|
send_notification "Backup Warning" "Failed to delete remote snapshot $snapshot on $HOSTNME" 6
|
||||||
log "WARNING - Failed to delete remote snapshot $snapshot"
|
log "WARNING - Failed to delete remote snapshot $snapshot"
|
||||||
fi
|
fi
|
||||||
if ! ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "rm -rf '$BASE_DEST_PATH/$snapshot'"; then
|
if ! ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "rm -rf '$BASE_DEST_PATH/$snapshot'"; then
|
||||||
send_notification "Backup Warning" "Failed to cleanup remote snapshot directory $snapshot on $HOSTNME" 6
|
send_notification "Backup Warning" "Failed to cleanup remote snapshot directory $snapshot on $HOSTNME" 6
|
||||||
log "WARNING - Failed to cleanup remote snapshot directory $snapshot"
|
log "WARNING - Failed to cleanup remote snapshot directory $snapshot"
|
||||||
fi
|
fi
|
||||||
|
@ -297,7 +297,7 @@ if [ -n "$LAST_TRANSFERRED" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create destination directory if it doesn't exist
|
# Create destination directory if it doesn't exist
|
||||||
ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "mkdir -p '$DEST_PATH'"
|
ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "mkdir -p '$DEST_PATH'"
|
||||||
|
|
||||||
# Perform the transfer
|
# Perform the transfer
|
||||||
if [ -z "$LAST_TRANSFERRED" ]; then
|
if [ -z "$LAST_TRANSFERRED" ]; then
|
||||||
|
@ -305,7 +305,7 @@ if [ -z "$LAST_TRANSFERRED" ]; then
|
||||||
log "Performing full send of snapshot $NEW_SNAPSHOT"
|
log "Performing full send of snapshot $NEW_SNAPSHOT"
|
||||||
sudo btrfs send "$SNAPSHOT_PATH/$NEW_SNAPSHOT/snapshot" | \
|
sudo btrfs send "$SNAPSHOT_PATH/$NEW_SNAPSHOT/snapshot" | \
|
||||||
pv --bytes | \
|
pv --bytes | \
|
||||||
ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "btrfs receive '$DEST_PATH'" && {
|
ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "btrfs receive '$DEST_PATH'" && {
|
||||||
echo "$NEW_SNAPSHOT" | sudo tee "$STATE_FILE"
|
echo "$NEW_SNAPSHOT" | sudo tee "$STATE_FILE"
|
||||||
log "Full send completed successfully"
|
log "Full send completed successfully"
|
||||||
} || {
|
} || {
|
||||||
|
@ -320,7 +320,7 @@ else
|
||||||
sudo btrfs send -p "$SNAPSHOT_PATH/$LAST_TRANSFERRED/snapshot" \
|
sudo btrfs send -p "$SNAPSHOT_PATH/$LAST_TRANSFERRED/snapshot" \
|
||||||
"$SNAPSHOT_PATH/$NEW_SNAPSHOT/snapshot" | \
|
"$SNAPSHOT_PATH/$NEW_SNAPSHOT/snapshot" | \
|
||||||
pv --bytes | \
|
pv --bytes | \
|
||||||
ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "btrfs receive '$DEST_PATH'" && {
|
ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "btrfs receive '$DEST_PATH'" && {
|
||||||
echo "$NEW_SNAPSHOT" | sudo tee "$STATE_FILE"
|
echo "$NEW_SNAPSHOT" | sudo tee "$STATE_FILE"
|
||||||
log "Incremental send completed successfully"
|
log "Incremental send completed successfully"
|
||||||
} || {
|
} || {
|
||||||
|
@ -353,7 +353,7 @@ if [ -n "$LAST_TRANSFERRED" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Final verification
|
# Final verification
|
||||||
if ! ssh -i /run/secrets/btrfs-backup/ssh_key "$REMOTE_HOST" "btrfs subvolume show '$DEST_PATH/snapshot'" &>/dev/null; then
|
if ! ssh -i /run/secrets/btrfs-backups/ssh_key "$REMOTE_HOST" "btrfs subvolume show '$DEST_PATH/snapshot'" &>/dev/null; then
|
||||||
send_notification "Backup Failed" "Final verification failed for $SNAPPER_CONFIG on $HOSTNME" 8
|
send_notification "Backup Failed" "Final verification failed for $SNAPPER_CONFIG on $HOSTNME" 8
|
||||||
log "WARNING - Final verification failed"
|
log "WARNING - Final verification failed"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue