From 47ae1f2930411faa83db0893781f61c9771379c7 Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 15 Dec 2024 19:43:40 -0600 Subject: [PATCH] Update backups cript --- .../software/cli/scripts/btrfs-backup.sh | 28 +++++++++---------- wallpapers | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) mode change 100644 => 100755 nixos/common/software/cli/scripts/btrfs-backup.sh diff --git a/nixos/common/software/cli/scripts/btrfs-backup.sh b/nixos/common/software/cli/scripts/btrfs-backup.sh old mode 100644 new mode 100755 index 7a835606..a9813f61 --- a/nixos/common/software/cli/scripts/btrfs-backup.sh +++ b/nixos/common/software/cli/scripts/btrfs-backup.sh @@ -13,7 +13,7 @@ SNAPPER_CONFIG="$1" # Get the actual snapshot location from snapper config SOURCE_PATH=$(sudo snapper -c "$SNAPPER_CONFIG" get-config | grep '^SUBVOLUME' | cut -d'=' -f2 | tr -d '"'| awk {'print $3'}) -echo "SOURCE_PATH: $SOUCE_PATH" +echo "SOURCE_PATH: $SOURCE_PATH" if [ -z "$SOURCE_PATH" ]; then echo "ERROR: Could not determine snapshot path for config '$SNAPPER_CONFIG'" exit 1 @@ -26,11 +26,17 @@ if [ ! -d "$SNAPSHOT_PATH" ]; then exit 1 fi + +# Get latest snapshot number from snapper +LATEST_SNAPSHOT=$(sudo snapper -c "$SNAPPER_CONFIG" list | tail -n 1 | awk '{print $1}') + REMOTE_HOST="root@synology" -DEST_PATH="/volume1/backups/btrfs_`hostname`_${SNAPPER_CONFIG}" +DEST_PATH="/volume1/BTRFS_Receives/`hostname`/${SNAPPER_CONFIG}/${LATEST_SNAPSHOT}" STATE_FILE="/var/lib/snapper-backup-${SNAPPER_CONFIG}.state" LOG_FILE="/var/log/snapper-backup-${SNAPPER_CONFIG}.log" KEEP_SNAPSHOTS=5 +# Get latest successful transfer number +LAST_TRANSFERRED=$(cat "$STATE_FILE" 2>/dev/null || echo "") # Ensure we exit on any error set -e @@ -43,7 +49,7 @@ fi # Logging function log() { - echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | sudo tee -a "$LOG_FILE" } # Function to verify snapshot exists @@ -94,12 +100,6 @@ log "Using snapshot path: $SNAPSHOT_PATH" # Verify remote connectivity first verify_remote -# Get latest successful transfer number -LAST_TRANSFERRED=$(cat "$STATE_FILE" 2>/dev/null || echo "") - -# Get latest snapshot number from snapper -LATEST_SNAPSHOT=$(sudo snapper -c "$SNAPPER_CONFIG" list | tail -n 1 | awk '{print $1}') - # Verify snapshots exist verify_snapshot "$LATEST_SNAPSHOT" || exit 1 if [ -n "$LAST_TRANSFERRED" ]; then @@ -120,9 +120,9 @@ if [ -z "$LAST_TRANSFERRED" ]; then # First time backup - full send log "Performing full send of snapshot $LATEST_SNAPSHOT" sudo btrfs send "$SNAPSHOT_PATH/$LATEST_SNAPSHOT/snapshot" | \ - pv -bytes | \ + pv --bytes | \ ssh "$REMOTE_HOST" "btrfs receive '$DEST_PATH'" && { - echo "$LATEST_SNAPSHOT" > "$STATE_FILE" + sudo echo "$LATEST_SNAPSHOT" > "$STATE_FILE" log "Full send completed successfully" } || { log "ERROR: Full send failed" @@ -133,9 +133,9 @@ else log "Performing incremental send from $LAST_TRANSFERRED to $LATEST_SNAPSHOT" sudo btrfs send -p "$SNAPSHOT_PATH/$LAST_TRANSFERRED/snapshot" \ "$SNAPSHOT_PATH/$LATEST_SNAPSHOT/snapshot" | \ - pv -bytes | \ + pv --bytes | \ ssh "$REMOTE_HOST" "btrfs receive '$DEST_PATH'" && { - echo "$LATEST_SNAPSHOT" > "$STATE_FILE" + sudo echo "$LATEST_SNAPSHOT" > "$STATE_FILE" log "Incremental send completed successfully" } || { log "ERROR: Incremental send failed" @@ -148,7 +148,7 @@ cleanup_remote_snapshots # Verify remote snapshots log "Current remote snapshots:" -get_remote_snapshots | tee -a "$LOG_FILE" +get_remote_snapshots | sudo tee -a "$LOG_FILE" # Final verification if ! ssh "$REMOTE_HOST" "btrfs subvolume show '$DEST_PATH/snapshot'" &>/dev/null; then diff --git a/wallpapers b/wallpapers index 8ed82c9a..26552d8b 160000 --- a/wallpapers +++ b/wallpapers @@ -1 +1 @@ -Subproject commit 8ed82c9afaac6359cf4603196f7a5bd4b399a4b5 +Subproject commit 26552d8bade6fa39188ebf68e9ffa1a8dcd75108