borg icon indicating copy to clipboard operation
borg copied to clipboard

Exclude directory if some relative file is present in the filesystem

Open wkordalski opened this issue 3 years ago • 4 comments

Sometimes it is reasonable to exclude directory, but only if some file is present.

Example

Rust projects are defined by Cargo.toml file. All build files are placed to target directory in the project structure.

(project root)
 |- Cargo.toml
 |- src       (contains source files)
 |   |- ...
 |- target    (contains build files generated by Rust tooling)
 |   |- ...
 |- ...

We would like to exclude target directory only if the directory containing target directory contains also Cargo.toml. In ZSH syntax it would be: **/target(e:'[[ -f $REPLY/../Cargo.toml ]]':)

Is it possible in Borg now?

wkordalski avatar Jan 17 '22 18:01 wkordalski

https://borgbackup.readthedocs.io/en/stable/usage/create.html

see --exclude-if-present and --keep-tag-files.

ThomasWaldmann avatar Jan 20 '22 13:01 ThomasWaldmann

I don't see how my case can be achieved by using these flags. The problematic thing is that the "tag file" (<project root>/Cargo.toml) is not a member of the excluded directory (<project root>/target/).

The only thing I can do is to write some shell script that will find directories I want to exclude, and add .nobackup file to them. Then I can exclude all directories that contain .nobackup file using --exclude-if-present flag. But it is not a solution, but a hack.

wkordalski avatar Jan 21 '22 18:01 wkordalski

Oh, sorry, I didn't read your post good enough. You're correct, the tagfile needs to be in the to-be-excluded directory, not in its parent directory.

So, you can't do that with borg right now.

What you can do:

  • manually exclude all the undesired directories, obviously
  • try borg 1.2.0 beta and write your own backup file discovery and feed all the pathes you want in your backup into borg using borg create --paths-from-stdin or (preferable) --paths-from-command.

ThomasWaldmann avatar Jan 21 '22 19:01 ThomasWaldmann

(This applies ONLY for the example case given by @wkordalski (Rust target directories) and other programs that implement CACHEDIR)

Abstract

Many applications create and manage directories containing cached information about content stored elsewhere, such as cached Web content or thumbnail-size versions of images or movies. For speed and storage efficiency we would often like to avoid backing up, archiving, or otherwise unnecessarily copying such directories around, but it is a pain to identify and individually exclude each such directory during data transfer operations. I propose an extremely simple convention by which applications can reliably "tag" any cache directories they create, for easy identification by backup systems and other data management utilities. Data management utilities can then heed or ignore these tags as the user sees fit.

Simply check if CACHEDIR.TAG exists, it was made specifically for this reason!

FountainOfInk avatar Aug 23 '23 23:08 FountainOfInk