digint / btrbk

Tool for creating snapshots and remote backups of btrfs subvolumes
https://digint.ch/btrbk/
GNU General Public License v3.0
1.67k stars 122 forks source link

Feature request: create symlinks to latest snapshots #495

Open Forza-tng opened 1 year ago

Forza-tng commented 1 year ago

I saw another topic about grub-btrfs and I thought it would be easier to simply have symlinks to the last n snapshots. Then it is easy to have a static grub menu to select them. It is of course possible to manually change the kernel command line, but guessing the snapshot names using long date format isn't so easy.

IMHO I'd like to have the last 5 hourly/manual snapshots plus last 5 dailys, but this should be configurable.

Arthur-D commented 1 year ago

This would be very useful for me as well, though I only need the very latest one. My use case is that I want to be using btrbk to incrementally back up my locally created media library to a media server via SSH. And I can't point the media server software to a single always updated folder or symlink as is unless I find some way to automate creating a symlink to the latest snapshot myself. But I think btrbk doing it would make the most sense since it always knows its own snapshot name at the time of snapshotting.

Arthur-D commented 1 year ago

I found a solution that works for me with one symlink to the latest snapshot, but there might be corner cases where it could fail. The script I wrote is the following:


#!/usr/bin/env bash
set -eu

btrbk run
latest_path=$(btrbk list latest --format col:h:target_subvolume)
ssh -i '/etc/btrbk/ssh/id_rsa' btrbk@arthur-server ln -fns ${latest_path} /media/Media/Jellyfin/latest

The most important part is obviously the variable latest_path calling the btrbk function to list the latest subvolume with the right format to only get the path of that subvolume, not the whole table. This does not solve the original feature request of having the 5 latest snapshots symlinked, but maybe it can give a slight idea on how to possibly do that too.

It would probably be hairy to do in a script without doing some sed or awk magic to get 5 paths separated from each other, so the original feature request of btrbk taking care of it still makes the most sense I think. Just wanted to post a solution here for anyone needing just one continually updated symlink to the very latest snapshot.

dkebler commented 1 year ago

What I'm after is a relative link in every directory of snapshots. (like what many rsync incremental backups do)

i.e. subovolumename.latest

this gets me latest for a conf file

sudo btrbk -c <name>.conf list latest --format col:h:snapshot_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D'

since I call run from a bash script I can then do the above and use it to create a relative link in each snapshot/target directory. But this would be much better incorporated into btkbk. Without a latest link it's had for a human or a script to identify the latest snaphost in a directory. That being needed for example to write a restore script.

Hmm..I'm a basher but maybe I need to try out perl.

spmp commented 1 year ago

Just a +1 I would love this feature