Skip to content

Instantly share code, notes, and snippets.

@rmetzler
Forked from SigmaX/backup_script.sh
Created September 18, 2021 04:56
Show Gist options
  • Save rmetzler/4d3d156ee18e21488e674bf438644994 to your computer and use it in GitHub Desktop.
Save rmetzler/4d3d156ee18e21488e674bf438644994 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