Skip to content

Instantly share code, notes, and snippets.

@zerodahero
Last active March 31, 2021 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zerodahero/1d6602a9c33d3762d8569e6d3988495a to your computer and use it in GitHub Desktop.
Save zerodahero/1d6602a9c33d3762d8569e6d3988495a 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