Преглед изворни кода

split borg scripts to keep cleaning up after failure

subDesTagesMitExtraKaese пре 2 месеци
родитељ
комит
237717826c
5 измењених фајлова са 53 додато и 17 уклоњено
  1. 15 0
      borg_compact.sh
  2. 0 15
      borg_create.sh
  3. 16 0
      borg_prune.sh
  4. 10 0
      break_lock.sh
  5. 12 2
      run_backup_process.sh

+ 15 - 0
borg_compact.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# Load environment variables from .env file
+source .env
+
+# Export Borg passphrase
+export BORG_PASSPHRASE=$PASSPHRASE
+export BORG_RSH="ssh -i $SSH_KEY -p $SSH_PORT"
+
+sudo -E borg compact --verbose "$SERVER_USER@$SERVER_IP:$REPOSITORY"
+
+if [ $? -ne 0 ]; then
+    echo "Borg compact failed."
+    exit 1
+fi

+ 0 - 15
run_backup.sh → borg_create.sh

@@ -28,19 +28,4 @@ if [ -n "$EXISTING_DIRECTORIES" ]; then
 else
     echo "No valid directories to back up."
     exit 1
-fi
-
-# Prune old backups using a custom SSH port
-sudo -E borg prune --glob-archives '{hostname}-*' --keep-daily=7 --keep-weekly=4 --keep-monthly=6 --keep-yearly=10 "$SERVER_USER@$SERVER_IP:$REPOSITORY"
-
-if [ $? -ne 0 ]; then
-    echo "Borg prune failed."
-    exit 1
-fi
-
-sudo -E borg compact "$SERVER_USER@$SERVER_IP:$REPOSITORY"
-
-if [ $? -ne 0 ]; then
-    echo "Borg compact failed."
-    exit 1
 fi

+ 16 - 0
borg_prune.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# Load environment variables from .env file
+source .env
+
+# Export Borg passphrase
+export BORG_PASSPHRASE=$PASSPHRASE
+export BORG_RSH="ssh -i $SSH_KEY -p $SSH_PORT"
+
+# Prune old backups
+sudo -E borg prune --verbose --glob-archives '{hostname}-*' --keep-daily=7 --keep-weekly=4 --keep-monthly=6 --keep-yearly=10 "$SERVER_USER@$SERVER_IP:$REPOSITORY"
+
+if [ $? -ne 0 ]; then
+    echo "Borg prune failed."
+    exit 1
+fi

+ 10 - 0
break_lock.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Load environment variables from .env file
+source .env
+
+# Export Borg passphrase
+export BORG_PASSPHRASE=$PASSPHRASE
+export BORG_RSH="ssh -i $SSH_KEY -p $SSH_PORT"
+
+sudo -E borg break-lock "$SERVER_USER@$SERVER_IP:$REPOSITORY"

+ 12 - 2
run_backup_process.sh

@@ -46,11 +46,19 @@ echo "Mounting HDD..."
 
 # Run backup
 echo "Running backup..."
-./run_backup.sh || handle_error "run_backup.sh"
+./borg_create.sh || handle_error "borg_create.sh"
 
 # Log stats to influxdb
 echo "Logging backup to influxdb..."
-./log_to_influx.sh || handle_error "log_to_influx.sh"
+./log_to_influx.sh || echo "Error occurred in script: log_to_influx.sh"
+
+# Log stats to influxdb
+echo "Pruning old backups..."
+./borg_prune.sh || echo "Error occurred in script: borg_prune.sh"
+
+# Log stats to influxdb
+echo "Compacting archives..."
+./borg_compact.sh || echo "Error occurred in script: borg_compact.sh"
 
 # Delay before unmounting
 echo "Waiting before unmounting HDD..."
@@ -69,3 +77,5 @@ echo "Turning off HDD power..."
 ./power_off_hdd.sh || handle_error "power_off_hdd.sh"
 
 echo "Backup process completed successfully."
+trap - EXIT
+exit 0