Baksnapper is a script for backing up snapshots created by the program snapper using btrfs send and receive.
Disclaimer: Baksnapper is still very new therefore it haven't been fully tested yet, so use with caution.
Clone the reposity
$ git clone git@github.com:plattfot/baksnapper.git
$ cd baksnapper
$ make install PREFIX=<install dir>
Default the scripts will be installed in /usr/bin, the systemd files in /usr/lib/systemd/system and the config file in /etc/baksnapper/example. If you are only packaging up the source please change BSCONF_ROOT to where the final path for baksnapper/example will be. Otherwise the systemd unit files will not work.
For example
$ make install PREFIX=pkg BSCONF_ROOT=/etc
Will install everything into the directory pkg, and the systemd unit file will search for the config files in /etc/baksnapper/.
Clone this repo and then build the package using the PKBUILD:
$ git clone https://github.com/plattfot/baksnapper.git
$ cd build-aux/baksnapper
$ makepkg -ic
What the latest release supports, and what the goals are for the next release.
First set up snapper to take snapshots of one of your subvolumes, see this page on how to do it for Arch Linux.
For example if you want to back up you snapshots from your home subvolumes to an external hdd mounted at /mnt/backup, run
$ baksnapper -c home /mnt/backup
This will send the last snapshots of home to
/mnt/backup/home/
To backup all snapshots run:
$ baksnapper --config home --all /mnt/backup
This will mirror what's in /home/.snapshots to /mnt/backup/home.
To remove backups that snapper has discarded add the flag -p/--prune:
$ baksnapper --config home --all --prune /mnt/backup
To delete specific backups from the backup directory, run:
$ baksnapper --config home /mnt/backup --delete 1,2,3,63
This will only delete 1,2,3 and 63 if they only contain a info.xml file and a snapshot dir. Otherwise it will issue a warning and skip the directory.
For help use the -h/--help flag
$ baksnapper --help
In order to be able to backup to a remote location you first need to install baksnapper on the remote machine, or atleast copy over the baksnapperd script.
Next up is to create a ssh key that baksnapper can use to access the remote machine.
Note: that you need to run this as root, since baksnapper needs root access to copy the snapshots.
$ su -
$ ssh-keygen -t rsa -b 4096 -C "$(whoami)@$(hostname)-$(date -I)"
Leave the passphrase blank and set the file to something like /home/username/.ssh/baksnapper_rsa
Append the public key (the one you just created), to .ssh/authorized_keys for the root account on the remote machine. Open up the .ssh/authorized_keys file on the remote machine and prepend this to the key
command="baksnapperd $SSH_ORIGINAL_COMMAND"
Your file should look something like this after.
command="baksnapperd $SSH_ORIGINAL_COMMAND" ssh-rsa <BAKSNAPPERD-PUBLIC-KEY>
After that test that everything is working by running.
$ (ssh <remote machine> test-connection) && echo "Connection works"
It should print out "Connection works".
If everything is working you can now use remote backup with baksnapper. It uses the same syntax as scp, i.e.
:$ baksnapper --config home --all foo:/mnt/backup
Tip: If your are using a nonstandard ssh port you can specify it in the .ssh/config, for example
Host foo
Port 666
Tip: If you have multiple keys, you can specify what key baksnapper should use either with the option
$ baksnapper config home --all foo:/mnt/backup --private-key /root/.ssh/<BAKSNAPPERD-PRIVATE-KEY>
Or specify that in the Config file using PRIVATE_KEY.
It can be tiresome to pass the options to baksnapper all the time, you
can therefore also create a config files in which you specify the
options you wish baksnapper to use. This is also what the systemd unit
file is using, more on that later. To read a config file use the
command line option -f
The config file syntax is pretty simple:
For boolean parameters YES, yes, yes and 1 are interpret as on/true and anything else as off/false.
The supported options are:
Note: Command line options will take precendence over config file options. Note: No variable expansion is supported in the config files, for example you cannot for example type ~/backup, instead you need to expand ~ yourself i.e /home/bob/backup if $USER = bob.
Baksnapper also supplies a timer and service file so that you can use systemd to handle the backup. For example to use root.bsconf you simply call
systemctl start baksnapper@root.bsconf.timer
Where it looks for config files depends on what BSCONF_ROOT was set to when installing the package, by default this will be /etc/baksnapper/.
Known limitations for version 0.4.0.
You cannot pack option flags i.e:
$ baksnapper -apc home /mnt/backup
instead you have to do:
$ baksnapper -a -p -c home /mnt/backup
Config files doesn't support variable expansion,