flycat

restic

Nov 3rd, 2022 (edited)
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. # Begin:
  2. restic init --repo /var/backups
  3. # passwd
  4.  
  5. # Backup:
  6. restic backup --repo /var/backups /home/maria
  7.  
  8. # View:
  9. restic snapshots
  10. restic diff a8aa6cef 4228f83e
  11. restic stats a8aa6cef
  12.  
  13. # Mount snapshot:
  14. restic mount /mnt
  15.  
  16. # Restore
  17. restic restore latest --target ~/restored-data
  18.  
  19. # Script for auto backup and cleanup:
  20. LOGFILE=/var/log/restic.log
  21. LOCKFILE=/var/backups.remote/restic.lock
  22. RESTIC_REPOSITORY=/var/backups
  23. RESTIC_PASSWORD=*****
  24.  
  25. if [ ! -d ${RESTIC_REPOSITORY} ]
  26. then
  27.         echo "$(date) Repository not found, trying to mount"
  28.         mount /var/backups.remote 2>&1
  29. fi >>${LOGFILE}
  30. if [ ! -d ${RESTIC_REPOSITORY} ]
  31. then
  32.         echo "$(date) Repository still not mounted, exiting"
  33.         exit 1
  34. fi >>${LOGFILE}
  35.  
  36. Delay=$(( ${RANDOM} / 1000 ))
  37. echo "$(date) First, sleeping for ${Delay} sec..." >>${LOGFILE}; sleep ${Delay}
  38. while [ -f ${LOCKFILE} ]
  39. do
  40.  Delay=$(( ${RANDOM} / 1000 ))
  41.  echo "$(date) Lock file found, sleeping for ${Delay} sec..." >>${LOGFILE}; sleep ${Delay}
  42. done
  43. echo "$(date) Now processing backup..." >>${LOGFILE}
  44. touch ${LOCKFILE}
  45. (restic backup /usr/share/nginx/html) >>${LOGFILE} 2>&1 && date >/tmp/restic-success
  46. (restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3          
  47. restic prune) >>${LOGFILE}
  48. echo "$(date) Backup is done" >>${LOGFILE}
  49. rm -f ${LOCKFILE}
  50. exit 0
Advertisement
Add Comment
Please, Sign In to add comment