rustic-rs / rustic_core

rustic_core - library for fast, encrypted, deduplicated backups that powers rustic-rs
https://rustic.cli.rs/ecosystem/rustic-core/
Apache License 2.0
36 stars 14 forks source link

Allow multiple `as-path` arguments (for multiple sources) in `backup` command #159

Open aawsome opened 8 months ago

aawsome commented 8 months ago

Example using rustic: rustic backup src1/ src2/ --as-path /path1/ --as-path /path2/ would backup src1/ as /path1 and src2/ as /path2/.

aawsome commented 8 months ago

@dimitarvp: Please have a look if this is what you are requesting and feel free to add missing points!

dimitarvp commented 8 months ago

Not precisely. Let me explain.

So I have a script that converts Borg backup repos to other backup programs' repos. I extract Borg backups one by one in e.g. /tmp/borgbackup. Inside I have everything from $HOME that is usually in, you know, $HOME, but now it's in /tmp/borgbackup, f.ex. .config, .gitconfig, .gitignore, .vimrc and many others.

So, original paths:

$HOME/.config
$HOME/.vimrc

Paths while working with extracted snapshots (in this case from Borg):

/tmp/borgbackup/.config
/tmp/borgbackup/.vimrc

When I backup $HOME with the proper inclusion + exclusion glob files, I get output like this:

| ID       | Time                | Host          | Label | Tags | Paths                                       | Action | Reason  |
|----------|---------------------|---------------|-------|------|---------------------------------------------|--------|---------|
| 56a9398d | 2024-02-10 13:50:04 | robeast.local |       |      | /Users/dimi/.config                         | keep   | hourly  |
|          |                     |               |       |      | /Users/dimi/.vimrc                          |        | daily   |

BUT when I backup /tmp/borgbackup and include --as-path $HOME, I get this output:

| ID       | Time                | Host          | Label | Tags | Paths                                       | Action | Reason  |
|----------|---------------------|---------------|-------|------|---------------------------------------------|--------|---------|
| 56a9398d | 2024-02-10 13:50:04 | robeast.local |       |      | /Users/dimi                                 | keep   | hourly  |

I can give you the full script and you can see for yourself if you like. It's not secret or anything, I just didn't feel it's generic enough to be shared but I can adapt it slightly and paste it here so you can have a hands-on experience with what I need.

And that is: I would like snapshots made from different directories BUT WHICH HAVE EXACTLY THE SAME FILES AS THE ORIGINAL DIRECTORY to yield identical output in rustic snapshots for full reproducibility.

Or in other words, I would love the following two commands to produce 100% identical output visually and on the disk:

  1. cd /tmp/borgbackup && rustic backup --time $ORIGINAL_TIME --as-path $HOME . (the /tmp/borgbackup directory contains only .config and .vimrc)
  2. cd $HOME && rustic backup .config .vimrc
aawsome commented 8 months ago

@dimitarvp Sorry, I didn't get it - and I am somehow confused.

First, if you run your second command cd $HOME && rustic backup .config .vimrc, you get an output like this:

snapshots for (host [latitude], label [], paths [.config,.vimrc])
| ID            | Time                | Host     | Label | Tags | Paths   | Files | Dirs |      Size |
|---------------|---------------------|----------|-------|------|---------|-------|------|-----------|
| 22abed0c      | 2024-02-11 22:42:30 | latitude |       |      | .config |   129 |  118 | 935.9 kiB |
|               |                     |          |       |      | .vimrc  |       |      |           |

And you get the same result, if you run with cd /tmp/borgbackup && rustic backup --time $ORIGINAL_TIME .config .vimrc (note that relative paths are saved as relative paths and therefore you don't need as-path in this example. Also note that- the path . is an exception and is resolved to the actual full path).

Second, if you do run rustic backup . rustic only gets one source and will always just display one source path - IMO everything else would be not logical. I dont't think what you wrote after "When I backup $HOME with the proper inclusion + exclusion glob files, I get output like this:" is correct.

Third, what don't you like about using cd /tmp/borgbackup && rustic backup --time $ORIGINAL_TIME .config .vimrc --as-path $HOME/.config --as-path $HOME/.vimrc? This is what I wanted to propose in this feature request...

dimitarvp commented 8 months ago

Sorry, I'm just too over-fixated on what I originally did.

Now that you showed the multiple --as-path switches with my paths, it clicked for me.

Let me get back to you after trying your suggestions.

aawsome commented 8 months ago

I had a small look into the code to check how easy it is to implement this feature. I must say that I would like to combine this with a refactoring of how rustic handles backup sources. That would then also allow to combine sources of different types, e.g. something like rustic backup --as-path /my-dir/ --as-path /my-stdin-backup/ /my/real/dir -. (and maybe we can even combine this with a possibility to backup remote sources in future). But this means there needs to be a bit more groundwork before we can start with this feature..

dimitarvp commented 8 months ago

I dont't think what you wrote after "When I backup $HOME with the proper inclusion + exclusion glob files, I get output like this:" is correct.

You got me here, one part of my script was not updated and was still using a list of relative backup sources so indeed it was not showing only one path; it was showing all relative paths, just like I wanted. My mistake, thanks for the catch.

The part that was showing only one path (/Users/dimi) was in another script. I ran both side by side for tests and of course I eventually forgot which one was the source of truth; typical.

Also note that- the path . is an exception and is resolved to the actual full path). Second, if you do run rustic backup . rustic only gets one source and will always just display one source path - IMO everything else would be not logical.

I see, I had no idea that just using . was a special case. Now I know to avoid it.

I have corrected my borg2rustic.bash script (to use a list of relative backup sources) and I see what I want to see in rustic snapshots output now, thank you.


RE: the original multiple --as-path topic, it's a great idea that can help a lot when your backup repo includes e.g. stuff from different filesystems or even servers and I would love it if you work on it.

dimitarvp commented 8 months ago

btw this part:

rustic backup src1/ src2/ --as-path /path1/ --as-path /path2/

Could be confusing to people: they have to count and compare two lists left to right. Perhaps you should do it like Docker volume mounts i.e.

rustic backup --path ~/src1:/path1 --path ~/src2:/path2, maybe? Or without a CLI switch even.