Glob-Expansion (of source directories) does not work on "working directory" #609

Closed
opened 2022-10-29 10:18:24 +00:00 by simon-77 · 6 comments

Hi, it's me again :)

What I'm trying to do and why

I try to use relative paths during backup via working_directory field.

Issue: using relative-path globs in source_directories field are not resolved relative to working_directory

Steps to reproduce

location:
    working_directory: /path/to/work-dir
    source_directories:
        - "*"

Actual behavior

running $ sudo borgmatic create --verbosity 2 --dry-run lists the create command with * expanded to a list of all files/folders in current directory (where this command is executed)

Partial output:

borg create --dry-run <path-to-repo>::{hostname}-user-{now} /root/.borgmatic <a list of files/folders in current directory> --debug --show-rc

Additionally I am curious why /root/.borgmatic is always included in the backup ?

Expected behavior

  1. a list of files in <path/to/work-dir>
  2. not having /root/.borgmatic in the backup included - although, if it has a reason that this directory is always included, I am fine with this fact.

Other notes / implementation ideas

Notes about the location.source_directories field:

I expected - * to work, but this throws an YAML-parser error: did not find expected alphabetic or numeric character

Additionally I tried - ./* which gives the same result as - "*" - resolving relative to current directory instead of working directory.

Environment

borgmatic version: 1.4.4

borgmatic installation method: openSUSE package manger

Borg version: 1.2.2

Python version: 3.10.7

operating system and version:
Operating System: openSUSE Tumbleweed 20221026
Kernel Version: 6.0.3-1-default (64-bit)

Hi, it's me again :) #### What I'm trying to do and why I try to use relative paths during backup via `working_directory` field. Issue: using relative-path globs in `source_directories` field are not resolved relative to `working_directory` #### Steps to reproduce ``` YAML location: working_directory: /path/to/work-dir source_directories: - "*" ``` #### Actual behavior running `$ sudo borgmatic create --verbosity 2 --dry-run` lists the create command with `*` expanded to a list of all files/folders in current directory (where this command is executed) Partial output: ``` borg create --dry-run <path-to-repo>::{hostname}-user-{now} /root/.borgmatic <a list of files/folders in current directory> --debug --show-rc ``` Additionally I am curious why `/root/.borgmatic` is always included in the backup ? #### Expected behavior 1) a list of files in <path/to/work-dir> 2) not having /root/.borgmatic in the backup included - although, if it has a reason that this directory is always included, I am fine with this fact. #### Other notes / implementation ideas Notes about the `location.source_directories` field: I expected `- *` to work, but this throws an YAML-parser error: `did not find expected alphabetic or numeric character` Additionally I tried `- ./*` which gives the same result as `- "*"` - resolving relative to current directory instead of working directory. #### Environment borgmatic version: 1.4.4 borgmatic installation method: openSUSE package manger Borg version: 1.2.2 Python version: 3.10.7 operating system and version: Operating System: openSUSE Tumbleweed 20221026 Kernel Version: 6.0.3-1-default (64-bit)
Author

Additional Note:

The Level-2 output of borgmatic create has no info that the relative working_directory path is used.

I gues borgmatic simply does a cd bevore. Maybe include this in Level-2 output.

Additional Note: The Level-2 output of `borgmatic create` has no info that the relative `working_directory` path is used. I gues borgmatic simply does a `cd` bevore. Maybe include this in Level-2 output.
Author

I now have a work-around:

location:
    working_directory: /path/to/work-dir
    source_directories:
        - .

includes all directories and files of /path/to/work-dir in a relative manner.

My initial goal was to only include directories (and files) that do not start with a dot. For this I found the following glob pattern to work: [!.]*
This is how I came up with the simplified example in the original post.

I just noticed: for not having .* directories/files in the repo I could also simply use the exclude patterns.

I now have a work-around: ``` YAML location: working_directory: /path/to/work-dir source_directories: - . ``` includes all directories and files of `/path/to/work-dir` in a relative manner. My initial goal was to only include directories (and files) that do not start with a dot. For this I found the following glob pattern to work: `[!.]*` This is how I came up with the simplified example in the original post. I just noticed: for not having `.*` directories/files in the repo I could also simply use the exclude patterns.
Owner

I apologize for the delay in getting to this. Supporting globs relative to the configured working directory seems like a totally reasonable feature!

I expected - * to work, but this throws an YAML-parser error: did not find expected alphabetic or numeric character

Yeah, this is a YAML limitation. You need to quote the asterisk, as you discovered.

The Level-2 output of borgmatic create has no info that the relative working_directory path is used.

Agreed.. This would be a good thing to log!

Additionally I am curious why /root/.borgmatic is always included in the backup ?

The short answer is that ~/.borgmatic is included to support backing up database dumps. More info is here: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/

I apologize for the delay in getting to this. Supporting globs relative to the configured working directory seems like a totally reasonable feature! > I expected - * to work, but this throws an YAML-parser error: did not find expected alphabetic or numeric character Yeah, this is a YAML limitation. You need to quote the asterisk, as you discovered. > The Level-2 output of borgmatic create has no info that the relative working_directory path is used. Agreed.. This would be a good thing to log! > Additionally I am curious why /root/.borgmatic is always included in the backup ? The short answer is that `~/.borgmatic` is included to support backing up database dumps. More info is here: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/
witten added the
good first issue
label 2023-03-27 03:18:46 +00:00

I ran into the same issue with.
I would workaround this limitation with specifying the directory without globs as i only use them to workaround another limitation.
My top-level directory to backup is a symbolic link (unraid share using single disk). So defining top-level directory in source_directories results in only backup the symbolic link.

Situation:
Content to backup: /mnt/user/myshare.
In unraid this may be a symbolic link to the actual disk mount.

source_directories:
  - /mnt/user/myshare

results in having an archive containing only the symbolic link myshare.
I don't want to open a discussion to how symbolic links should be backed up... In my eyes in general they should as they are. Current behavior. But in this special case of a top-level directory it would make sense to make a exception. In most shells you can append a trailing / to symbolic links which most of the time works perfect for this exception.
Unfortunately this workaround doesn't work with borg/borgmatic.

So a workaround would be:

source_directories:
  - /mnt/user/myshare/*
  - /mnt/user/myshare/.*

But this does not work in combination with working_directory if you want to "hide" the common location from the backup.

working_directory: /mnt/user/myshare
source_directories:
  - "*"
  - ".*"

results in all directories and files in the working directory of borg/borgmatic instead the defined working_directory.

I ran into the same issue with. I would workaround this limitation with specifying the directory without globs as i only use them to workaround another limitation. My top-level directory to backup is a symbolic link (unraid share using single disk). So defining top-level directory in `source_directories` results in only backup the symbolic link. Situation: Content to backup: `/mnt/user/myshare`. In unraid this may be a symbolic link to the actual disk mount. ``` source_directories: - /mnt/user/myshare ``` results in having an archive containing only the symbolic link `myshare`. I don't want to open a discussion to how symbolic links should be backed up... In my eyes in general they should as they are. Current behavior. But in this special case of a top-level directory it would make sense to make a exception. In most shells you can append a trailing `/` to symbolic links which most of the time works perfect for this exception. Unfortunately this workaround doesn't work with borg/borgmatic. So a workaround would be: ``` source_directories: - /mnt/user/myshare/* - /mnt/user/myshare/.* ``` But this does not work in combination with `working_directory` if you want to "hide" the common location from the backup. ``` working_directory: /mnt/user/myshare source_directories: - "*" - ".*" ``` results in all directories and files in the working directory of borg/borgmatic instead the defined `working_directory`.
Owner

So in working on this ticket, I, uh, kind of expanded scope. Now working_directory applies to all borgmatic actions, not just create. And as part of that work, the original ask in this ticket was also implemented.

This will be part of the next release. Thanks to @simon-77 for filing this (and to @spali for weighing in)!

So in working on this ticket, I, uh, kind of expanded scope. Now `working_directory` applies to *all* borgmatic actions, not just `create`. And as part of that work, the original ask in this ticket was also implemented. This will be part of the next release. Thanks to @simon-77 for filing this (and to @spali for weighing in)!
Owner

Released in borgmatic 1.9.0!

Released in borgmatic 1.9.0!
Sign in to join this conversation.
No Milestone
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#609
No description provided.