Advertisement
pilasguru

Restic backup to B2 Cloud Storage

Aug 17th, 2022 (edited)
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #######
  2. # /usr/local/etc/restic-env.sh
  3. #######
  4. export B2_ACCOUNT_ID='005853df61406f00002'
  5. export B2_ACCOUNT_KEY='K02WMXFAh6MOVxyh1b233lMLyk\4vo'
  6. export RESTIC_REPOSITORY=b2:server-01:restic
  7. export RESTIC_PASSWORD_FILE=/root/restic/pw.restic
  8. export BACKUP_PATHS="/opt /root /var/lib/automysqlbackup"
  9. export EXCLUDES="--exclude data/logs/ --exclude database/"
  10.  
  11.  
  12. #######
  13. # /root/restic/pw.restic
  14. #######
  15. passw0rd
  16.  
  17.  
  18. #######
  19. # MAIN SCRIPT
  20. #######
  21. #!/usr/bin/env bash
  22. # This script is to backup with restic to b2
  23.  
  24. # Exit on failure or pipefail
  25. set -e -o pipefail
  26.  
  27. BACKUP_TAG=rundeck-restic
  28.  
  29. # How many backups to keep.
  30. RETENTION_DAYS=14
  31. RETENTION_WEEKS=16
  32. RETENTION_MONTHS=18
  33. RETENTION_YEARS=3
  34.  
  35. source /usr/local/etc/restic-env.sh
  36. echo "To backup: $BACKUP_PATHS"
  37.  
  38. # Remove locks in case other stale processes kept them in
  39. restic unlock &
  40. wait $!
  41.  
  42. #Do the backup
  43. restic backup \
  44.     --verbose \
  45.     --tag $BACKUP_TAG \
  46.     $BACKUP_PATHS \
  47.     $EXCLUDES &
  48.  
  49. wait $!
  50.  
  51. # Remove old Backups
  52. restic forget \
  53.     --verbose \
  54.     --tag $BACKUP_TAG \
  55.     --prune \
  56.     --keep-daily $RETENTION_DAYS \
  57.     --keep-weekly $RETENTION_WEEKS \
  58.     --keep-monthly $RETENTION_MONTHS \
  59.     --keep-yearly $RETENTION_YEARS &
  60. wait $!
  61.  
  62. # Check if everything is fine
  63. restic check &
  64. wait $!
  65.  
  66. echo "Backup done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement