Skip to content

Instantly share code, notes, and snippets.

@qrkourier
Created August 9, 2020 21:25
Show Gist options
  • Save qrkourier/5bc95c168d56bb244ac942563e010cb0 to your computer and use it in GitHub Desktop.
Save qrkourier/5bc95c168d56bb244ac942563e010cb0 to your computer and use it in GitHub Desktop.
# 1) define one or more Restic repo paths
typeset -A RESTIC_REPOS
RESTIC_REPOS[gdrive]=rclone:gdrive-backup:
RESTIC_REPOS[KX1T]=/media/kbingham/KX1T/backups
#RESTIC_REPOS[bigExternalDrive]=/media/kbingham/bigExternalDrive/backups
# 2) create an exclude file with lines like:
# **/*cache/
# **/cache*/
# **/*Cache/
# **/CachedData/
# **/.Trash*/
# /home/kbingham/.local/share/Trash/
# /home/kbingham/.local/share/flatpak/
RESTIC_EXCLUDE=$HOME/etc/kbingham-backup.exclude
# 3) save the Restic repo passphrase in this file
#export RESTIC_PASSWORD="my restic passphrase"
# or provide a shell command that will yield the passphrase
RESTIC_PASSWORD_CMD="source <(gpg -qd < ~/Private/idrepo/etc/restic-passphrase.gpg)"
# 4) adjust the retention policy if desired
RESTIC_FORGET="\
--keep-tag keepers \
--host $(hostname -s) \
--keep-hourly 12 \
--keep-daily 14 \
--keep-weekly 6 \
--keep-monthly 12 \
--keep-yearly 5
"
function backup(){
[[ $# -ge 1 ]] && {
typeset -a REPOS=($@)
} || {
# zsh
# typeset -a REPOS=(${(k)RESTIC_REPOS[@]})
# bash
typeset -a REPOS=(${!RESTIC_REPOS[@]})
}
[[ ! -z ${RESTIC_PASSWORD+true} ]] || eval "$RESTIC_PASSWORD_CMD";
for REPO in ${REPOS[@]}; do
echo -e "\nBEGIN $REPO"
[[ -d ${RESTIC_REPOS[$REPO]} ]] || {
restic --repo=${RESTIC_REPOS[$REPO]} init
}
eval restic --repo=${RESTIC_REPOS[$REPO]} backup $HOME \
--exclude-file=$RESTIC_EXCLUDE --verbose
eval restic --repo=${RESTIC_REPOS[$REPO]} --cleanup-cache forget $RESTIC_FORGET
echo -e "END $REPO\n"
done
}
# 5) add a line to your ~/.bashrc file like:
# source ~/.restic.conf
# 6) save this file as ~/.restic.conf
# 7) run "backup" in terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment