Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. restic -r /Volumes/BackupManual/restic-backups snapshots
  2.  
  3. ID Date Host Tags Directory
  4. ----------------------------------------------------------------------
  5. dbc3943d 2017-02-07 18:50:47 User.fritz.box /Users/user/Documents
  6. bd355ca9 2017-02-07 19:57:59 User.fritz.box /Users/user/Documents
  7.  
  8. restic -r /Volumes/BackupManual/restic-backups forget IDxxxxxx
  9.  
  10. #!/bin/bash
  11.  
  12. # USER CONFIGURATION:
  13. resticuser=restic
  14. srcdir=/Users/user/data
  15. backupvolume=/Volumes/usb-storage-name
  16. backupdir=${backupvolume}/restic-backups
  17.  
  18. # Script vars:
  19. longname=$0
  20. shortname=$(/usr/bin/basename "${longname}")
  21.  
  22. printf '%s %s (%s) running...n' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${shortname}" "${longname}"
  23.  
  24. if [[ ! -d "${srcdir}" ]]; then
  25. printf '%s %s does NOT exist.' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${srcdir}" >&2
  26. exit 1
  27. else
  28. if [[ $(mount | grep "${backupvolume}") ]]; then
  29. # See: http://blog.macromates.com/2006/keychain-access-from-shell/
  30. # Parse output of 'security' and set RESTIC_PASSWORD:
  31. export RESTIC_PASSWORD=$(security 2>&1 >/dev/null find-generic-password -ga ${resticuser} |ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/')
  32. # Run backup, capturing output in case of error:
  33. output=$(restic -r ${backupdir} backup "${srcdir}")
  34. error=$?
  35. if [[ "${error}" == "0" ]]; then
  36. printf '%s Restic backup completed successfully.n' "$(date -u "+%Y-%m-%d %H:%M:%S")"
  37. else
  38. printf '%s Restic backup failed: error code: %s, error: %sn'
  39. "$(date -u "+%Y-%m-%d %H:%M:%S")" "${error}" "${output}" >&2
  40. fi
  41. else
  42. printf '%s %s is NOT mounted.' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${backupvolume}" >&2
  43. exit 1
  44. fi
  45. fi
  46.  
  47. printf '%s %s ended.n' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${shortname}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement