12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #!/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"
- # Build the list of existing directories
- EXISTING_DIRECTORIES=$(for DIR in $SOURCE_DIRECTORIES; do
- if [ -d "$DIR" ]; then
- echo "$DIR"
- else
- echo "Directory does not exist: $DIR"
- fi
- done)
- # If we have valid directories, run the backup
- if [ -n "$EXISTING_DIRECTORIES" ]; then
- echo "Backing up directories: $EXISTING_DIRECTORIES"
- touch exclude.txt
- sudo -E borg create --verbose --filter AME --list --stats --compression zstd,10 --exclude-caches --exclude-from exclude.txt "$SERVER_USER@$SERVER_IP:$REPOSITORY::{hostname}-{now}" $EXISTING_DIRECTORIES
- if [ $? -ne 0 ]; then
- echo "Borg backup failed."
- exit 1
- fi
- 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
|