Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- restic -r /Volumes/BackupManual/restic-backups snapshots
- ID Date Host Tags Directory
- ----------------------------------------------------------------------
- dbc3943d 2017-02-07 18:50:47 User.fritz.box /Users/user/Documents
- bd355ca9 2017-02-07 19:57:59 User.fritz.box /Users/user/Documents
- restic -r /Volumes/BackupManual/restic-backups forget IDxxxxxx
- #!/bin/bash
- # USER CONFIGURATION:
- resticuser=restic
- srcdir=/Users/user/data
- backupvolume=/Volumes/usb-storage-name
- backupdir=${backupvolume}/restic-backups
- # Script vars:
- longname=$0
- shortname=$(/usr/bin/basename "${longname}")
- printf '%s %s (%s) running...n' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${shortname}" "${longname}"
- if [[ ! -d "${srcdir}" ]]; then
- printf '%s %s does NOT exist.' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${srcdir}" >&2
- exit 1
- else
- if [[ $(mount | grep "${backupvolume}") ]]; then
- # See: http://blog.macromates.com/2006/keychain-access-from-shell/
- # Parse output of 'security' and set RESTIC_PASSWORD:
- export RESTIC_PASSWORD=$(security 2>&1 >/dev/null find-generic-password -ga ${resticuser} |ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/')
- # Run backup, capturing output in case of error:
- output=$(restic -r ${backupdir} backup "${srcdir}")
- error=$?
- if [[ "${error}" == "0" ]]; then
- printf '%s Restic backup completed successfully.n' "$(date -u "+%Y-%m-%d %H:%M:%S")"
- else
- printf '%s Restic backup failed: error code: %s, error: %sn'
- "$(date -u "+%Y-%m-%d %H:%M:%S")" "${error}" "${output}" >&2
- fi
- else
- printf '%s %s is NOT mounted.' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${backupvolume}" >&2
- exit 1
- fi
- fi
- printf '%s %s ended.n' "$(date -u "+%Y-%m-%d %H:%M:%S")" "${shortname}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement