Last active
October 25, 2021 21:40
-
-
Save clonejo/da27d3fe50fd511b588a2b5bdecbbf4c to your computer and use it in GitHub Desktop.
My scripts for automated restic backups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
if [[ ${1:-} != "-f" ]]; then | |
if ! ip route | head -n 1 | grep --quiet 'dev en' ; then | |
echo "Not connected to Ethernet, skipping backup." >&2 | |
exit 0 | |
fi | |
ac=$(cat /sys/class/power_supply/AC/online) | |
if [[ $ac = 0 ]]; then | |
echo "Running on battery, skipping backup." >&2 | |
exit 0 | |
fi | |
fi | |
headerBackupPath=/var/lib/luks-header-backup-nvme0n1p2 | |
rm "$headerBackupPath" | |
cryptsetup luksHeaderBackup /dev/nvme0n1p2 --header-backup-file "$headerBackupPath" | |
/usr/bin/pacman -Qe > /etc/pacman.d/installed-packages | |
/usr/bin/restic \ | |
-r sftp:restic-target:/backups/restic-repo \ | |
--password-file=/etc/restic-key \ | |
backup /etc /home /root /usr/local/bin \ | |
--tag=full \ | |
--exclude-caches \ | |
--exclude=/home/clonejo/.cache \ | |
--exclude=/home/clonejo/.cargo/registry \ | |
--exclude=/home/clonejo/.local/share \ | |
--exclude=/home/clonejo/.rustup/toolchains \ | |
--exclude=/home/clonejo/Downloads \ | |
--exclude=target/classes \ | |
--exclude=target/debug \ | |
--exclude=target/doc \ | |
--exclude=target/release | |
date --iso-8601=seconds >/var/lib/restic-last-successfull-backup | |
# That file can be used to trigger warnings about your backups not working. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=restic backups | |
[Service] | |
Type=oneshot | |
Nice=10 | |
Environment=HOME=/root | |
ExecStart=/usr/local/bin/restic-backup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Run restic backup every three hours | |
[Timer] | |
OnBootSec=10min | |
OnUnitInactiveSec=3h | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment