restic-backup.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. set -e
  3. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. # First and only argument is the name of the backup configuration
  5. BACKUP_CFG_NAME=$1
  6. # This will set RESTIC_PASSWORD and RESTIC_REPOSITORY
  7. source $DIR/restic-backup-${BACKUP_CFG_NAME}.env
  8. BASE_URL=https://dev.burdet.ch/git/jfburdet/backup-cfg/raw/master/restic/${BACKUP_CFG_NAME}
  9. INCLUDE_URL=$BASE_URL/include.list
  10. EXCLUDE_URL1=$BASE_URL/exclude.list
  11. EXCLUDE_URL2=$BASE_URL/../exclude.list
  12. include_file=$(mktemp)
  13. exclude_file1=$(mktemp)
  14. exclude_file2=$(mktemp)
  15. curl -f -s $INCLUDE_URL --output $include_file || (echo "Can't fetch include file $INCLUDE_URL" && exit 1)
  16. curl -f -s $EXCLUDE_URL1 --output $exclude_file1 || (echo "Can't fetch exclude file $EXCLUDE_URL1" && exit 1)
  17. curl -f -s $EXCLUDE_URL2 --output $exclude_file2 || (echo "Can't fetch exclude file $EXCLUDE_URL2" && exit 1)
  18. echo "Backing up :"
  19. cat $include_file
  20. # Lets make destination nice to display by removing tag string
  21. restic backup --files-from $include_file --exclude-file $exclude_file1 --exclude-file $exclude_file2 --exclude-caches
  22. rm -rf $include_file
  23. rm -rf $exclude_file1
  24. rm -rf $exclude_file2