binhex / arch-urbackup

Docker build script for Arch Linux base with UrBackup
GNU General Public License v3.0
6 stars 0 forks source link

Should create and set "/etc/urbackup/backupfolder" during container start #3

Open kcpants opened 1 year ago

kcpants commented 1 year ago

Right now, the start.sh script creates the backupfolder file in /var/urbackup and populates it with the path to the /media directory (which is mapped into the container) in the following code:

https://github.com/binhex/arch-urbackup/blob/16f5d11e6ba00b22ef226f77ea19b810d369461e/run/nobody/start.sh#L14-L15

Some urbackup features also rely on this path being set in /etc/urbackup/backupfolder. In particular, in order to enable btrfs snapshots in urbackup, the backup path must be set in /etc/urbackup/backupfolder as described here (quoted below):

In order to create and remove btrfs snapshots UrBackup installs a setuid executable urbackup_ snapshot_helper. UrBackup also uses this tool to test if cross-device reflinks are possible. Only if UrBackup can create cross-device reflinks and is able to create and destroy btrfs snapshots, is the btrfs mode enabled. urbackup_snapshot_helper needs to be told separately where the UrBackup backup folder is. This path is read from /etc/urbackup/backupfolder. Thus, if /media/backup/urbackup is the folder where UrBackup is saving the paths, following commands would properly create this file:

mkdir /etc/urbackup
echo "/media/backup/urbackup" > /etc/urbackup/backupfolder

It's possible to create this file once the container is running and it will persist through restarts, until a new container image is pulled at which point urbackup becomes unable to use btrfs snapshots and falls back on traditional backups until /etc/urbackup/backupfolder is restored.

Workaround

The directory and file can be created alongside the container by adding the following line to the post-args field in advanced settings of the docker container (note the leading semicolon); docker exec binhex-urbackup bash -c "mkdir -p /etc/urbackup; echo '/media' > /etc/urbackup/backupfolder"

binhex commented 1 year ago

thanks for this, changes included in the image and a new image has been built, please pull down latest and let me know if it works ok for you.

kcpants commented 1 year ago

Wow, amazing response time!

I created a new container based on the latest image and confirmed that /etc/urbackup/backupfolder exists and is populated as expected and that if --cap-add SYS_ADMIN is set as an extra parameter and /media is mapped to a single btrfs disk then btrfs snapshots work out of the box:

sh-5.1# urbackup_snapshot_helper test Testing for btrfs... Create subvolume '/media/testA54hj5luZtlorr494/A' Create a snapshot of '/media/testA54hj5luZtlorr494/A' in '/media/testA54hj5luZtlorr494/B' Delete subvolume (commit): '/media/testA54hj5luZtlorr494/A' Delete subvolume (commit): '/media/testA54hj5luZtlorr494/B' BTRFS TEST OK

Thank you!

The fix works for me and probably will work for most people. I did notice that /var/urbackup is symlinked to /config/urbackup meaning that /var/urbackup/backupfolder actually points to /config/urbackup/backupfolder which lives in the appdata directory and is therefore customizable so if anyone has changed /config/urbackup/backupfolder to point to a path other than /media within the container they might still need to use the workaround. Seems unlikely, but to support these folks (if they exist) it may be necessary to make /etc/urbackup/backupfolder customizable in the future as well.

kcpants commented 1 year ago

As mentioned in my comment above, the change in commit 7cf124d is perfect for enabling btrfs snapshots in my urbackup container and it's likely also sufficient for all common urbackup configurations. Feel free to close this issue or leave it open if you'd like to continue tracking making /etc/urbackup/backupfolder configurable (perhaps by symlinking it to /var/urbackup/backupfolder?).