Disable recursion

Hello, I need to backup only files from path source with subdirs.
It’s possible to include only files from source (or exclude subdirs)?
I’m trying some pattern with --exclude with no success

It’s quite unclear what you mean by this. But if you want to back up only the files in a given path/folder, try using the --files-from option with a plain text file that lists the files you want to back up.

Note that this will make the set of paths you back up change if the list changes, which means that restic can’t know which parent snapshot to use when scanning files. This just means it has to re-scan the files so it might not be a problem for you at all.

I understand --files-from option but it implies a known files list.
I want to backup something like c:\dir\to\backup:

subdir1\
subdir2\
file1.txt
file2.jpg
file3.pdf
...

and I would like to tell restic to consider only files in c:\dir\to\backup

Yeah. Thanks for the clarification!

There’s no way to tell restic to only back up files and not folders in general.

Perhaps if you do this though, assuming that all of the files you want to back up actually has a dot in their name, and the subfolders don’t: restic backup c:\dir\to\backup\*.*

Otherwise, you can simply generate the list of files in that folder. I don’t know how to do it in Windows off the top of my head, but in BSD/Linux shell scripting it would be like find /dir/to/backup -depth 1 -type f > filelist.txt and then you just give that file to --files-from.

What might your use case for this be anyway? First time I heard of wanting to do this.

Yes it sounds good!
But I saw now that

restic backup c:\dir\to\backup --exclude=c:\dir\to\backup\*\*

make a snapshot with all files and only empty subdirs name with non recursion.

I think this is the best compromise for my needs… thanks @rawtaz!

Yeah your suggestion there is indeed a workaround, and it doesn’t have the requirement with the dots, so it’s a better workaround than mine :slight_smile:

1 Like