Skip to content

Instantly share code, notes, and snippets.

@SigmaX
Created August 13, 2021 18:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SigmaX/e511da7fbb7b0bf1c016e1dddc080f83 to your computer and use it in GitHub Desktop.
Save SigmaX/e511da7fbb7b0bf1c016e1dddc080f83 to your computer and use it in GitHub Desktop.
#!/bin/bash
export B2_ACCOUNT_ID=<your keyID here>
export B2_ACCOUNT_KEY=<your key here>
export RESTIC_PASSWORD=<your restic repository password here>
command1="restic -r b2:mybucket-desktop-backups:alfred/ backup /home/eric/Documents/ 2>&1"
output1=$(eval "${command1}")
result1=$?
command2="restic -r b2:mybucket-desktop-backups:alfred/ backup /home/eric/repos/ 2>&1"
output2=$(eval "${command2}")
result2=$?
message="
----------Alfred Backup Report----------
$(date)
"
if [[ $result1 != 0 ]] || [[ $result2 != 0 ]]; then
message="${message}
----------------------------------------
BACKUP FAILED!! See output below.
----------------------------------------
"
subject="Backup FAILED---$(date)"
else
message="${message}
----------------------------------------
Backup SUCCEEDED.
----------------------------------------
"
subject="Backup successful---$(date)"
fi
message="${message}
\$ ${command1}
${output1}
\$ ${command2}
${output2}
----------------------------------------
Snapshot history:
----------------------------------------
$(restic -r b2:mybucket-desktop-backups:alfred/ snapshots)
"
echo "Subject: ${subject}"
echo "Message: ${message}"
echo "${message}" | mailx --subject "${subject}" username@gmail.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment