KenKundert / emborg

Interactive command line interface to Borg Backup
GNU General Public License v3.0
94 stars 8 forks source link

How to include a subfolder of an excluded folder? #26

Closed stefanobartoletti closed 4 years ago

stefanobartoletti commented 4 years ago

I need to backup a folder which is located inside an excluded folder. More precisely, I need to backup ~/.cache/evolution/, while ~/.cache/ is excluded.

This is my current configuration

src_dirs = '''
    ~/
    ~/.cache/evolution/
    /home/shared/
'''.split()   # absolute path to directory to be backed up

excludes = '''
    ~/**/__pycache__
    ~/**/*.pyc
    ~/**/.*.swp
    ~/**/.*.swo
    ~/**/node_modules
    ~/.cache
    ~/.npm
    ~/.pnpm-store
    ~/.local/share/baloo
    ~/.local/share/Trash
    ~/.thumbnails
'''.split()

But it does not seem to work. Is it possible to do so? And how?

KenKundert commented 4 years ago

Borg has recently implemented that functionality using patterns (see borg help patterns). This is an experimental feature in borg, but it has been available for several years, so it is probably pretty stable. I will look into adding support for patterns in emborg. I'll need a little time to consider the interaction between excludes and patterns.

stefanobartoletti commented 4 years ago

Thank you, as usual. I was not aware of the status if this feature directly in Borg.

KenKundert commented 4 years ago

I have just pushed a new version of Emborg that supports Borg patterns. It is version 1.14.5 and currently available only from github. I think you can get what you want by replacing your src_dirs and excludes specifications with:

patterns = '''
    R ~
    R /home/shared
    + ~/.cache/evolution/
    - ~/**/__pycache__
    - ~/**/*.pyc
    - ~/**/.*.swp
    - ~/**/.*.swo
    - ~/**/node_modules
    - ~/.cache
    - ~/.npm
    - ~/.pnpm-store
    - ~/.local/share/baloo
    - ~/.local/share/Trash
    - ~/.thumbnails
'''

Notice that each line has a key and a path. The key R signifies a root path. These are your src dirs. The + key signifies a file or directory that should be included. The - key signifies files or directories that should be excluded. A subdirectory will be archived as long as you include it before excluding the directory that contains it.

Notice that you no longer need to pass the multi-line string through split. Emborg splits it for you assuming that each key-path pair is on a separate line.

Emborg was heavily modified to support this functionality, so please check your results carefully to make sure everything is working as expected before counting on it. Once I am confident that this version is stable I will upload it to pypi. That might take a while.

stefanobartoletti commented 4 years ago

Thank you, I'll test this as soon as possible.

KenKundert commented 4 years ago

Please let me know when you have had a chance to try out the latest version. I think it is ready to go, but I would feel more comfortable releasing it if a few more people told me that it worked for them without issues.

stefanobartoletti commented 4 years ago

I'm sorry for the late answer, I finally had a chance to extensively test this and it just works as expected, without any problem to report. Thank you again!