Advertisement
flycat

restic

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