Skip to content

Instantly share code, notes, and snippets.

@izikeros
Forked from zerodahero/restic_backup.sh
Created March 31, 2021 07:52
Show Gist options
  • Save izikeros/20679d3c36cedd66d2fdca5526f03964 to your computer and use it in GitHub Desktop.
Save izikeros/20679d3c36cedd66d2fdca5526f03964 to your computer and use it in GitHub Desktop.
Restic backup with .gitignore style excludes
#!/bin/bash
TEMPFILE='/tmp/restic_ignores.txt'
BACKUPDIR=$HOME
# Note: Not sure which way is better, echo nothing into the file, or remove if exists
# if [ -f $TEMPFILE ]; then
# rm $TEMPFILE
# fi
# touch $TEMPFILE
echo > $TEMPFILE
IGNOREFILES=`find $BACKUPDIR -name '.restic_ignore' -print`
for IGNOREFILE in $IGNOREFILES
do
PATTERNS=`cat $IGNOREFILE`
for PATTERN in $PATTERNS
do
printf "%s/%s\n" $(dirname $IGNOREFILE) $PATTERN >> $TEMPFILE
done
done
restic backup $BACKUPDIR --exclude-file=$TEMPFILE --exclude-caches # and any other options here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment