--exclude pattern with two args


#1

Is there a way to exclude two folders in the same “–exclude”?

example: --exclude “/home/folder1 /home/folder2”


#2

You can make an array but the simpler method is to use an exclude file. You make a list in a plain text file with all your excludes and use --exclude-file="/path/to/your/exlusion-list.txt".


#4

Ha! You just beat me to it :stuck_out_tongue:

Just one addition: @cberni please also take a look at the documentation over at https://restic.readthedocs.io/en/latest/040_backup.html#including-and-excluding-files

Here it says

  • --exclude Specified one or more times to exclude one or more items

Which states exactly what @Dj0k3 said. The “right” way would be to specify --exclude multiple times OR to create an exclude file - in there you specify the directories to be excluded on a new line each.

Benefit of the exclude file is that you can update and alter the files/directories to be excluded without touching the restic command.

Hope this helps :slight_smile:


#5

I would disagree that using a file is a benefit. It’s much simpler to specify them as part of the backup command.

#!/bin/sh

restic backup \
  -r /path/to/repo \
  --one-file-system \
  --exclude-caches \
  --exclude=/a \
  --exclude=/b \
  /path/to/backup

Having two files instead of one sounds like unnecessary complexity, and needlessly spreads the information out over several files.

The only cases where it makes sense to use an exclude file are:

  • You’re using the same set of excludes with multiple backup commands and want to keep them in sync.
  • You need to specify more exclude information than will fit in a single process command line. (Unlikely.)

#6

Interesting point! I think it then is just a personal preference which way is more clean/works better. But good addition for this thought experiment.


#7

I agree but with the time I noticed my $HOME folder increasing in size (which is what I backup on my personal machine) and I decided to use an exclude file instead of what you’re doing, which is what I was doing in the past. The reason is that, for example, I didn’t have Chrome installed on my machine. Later I installed chrome but didn’t wanted to backup the configuration files because for my personal use, that’s unnecessary and it can take a lot of space of my external HDD. That happened with a bunch of other programs so that’s why I decided to switch to a file instead of editing my script every time I wanted to add a new exclusion rule. Believe me, I wanted to keep things as simple as possible at the beginning but this was an inevitable change in my case. For system backups, in my case the exclusion list is not necessary because the folders I have to exclude are like 5 or 6. It will all depend on the use case and personal preference.

If you want to make an array in a script this could be the easiest way:

EXCLUDES=(
    --exclude=$HOME/Downloads
    --exclude=$HOME/.mozilla
)

This way you can run restic backup "$EXCLUDES" without the need of an exclusion list. You can do that for --keep policies too.

EDIT:

Sorry, I tried that after writing the comment and at least for me it doesn’t work. I saw that method in a restic script called restic-runner. I’m using another script called rescript that contains an option to build an exclusion file. It was actually helpful for what I was trying to do.


#8

I’m still not sure why that would be necessary, but whatever works.