2015-02-07 15:53:21 +01:00
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
|
|
|
|
btrbk is a backup tool for btrfs subvolumes, taking advantage of btrfs
|
|
|
|
specific capabilities to create atomic snapshots and transfer them
|
|
|
|
incrementally to your backup locations.
|
|
|
|
|
2015-05-25 17:13:36 +02:00
|
|
|
The source and target locations are specified in a config file, which
|
|
|
|
allows to easily configure simple scenarios like "laptop with locally
|
|
|
|
attached backup disks", as well as more complex ones, e.g. "server
|
|
|
|
receiving backups from several hosts via ssh, with different retention
|
|
|
|
policy".
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
Key Features:
|
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
* Atomic snapshots
|
|
|
|
* Incremental backups
|
|
|
|
* Configurable retention policy
|
|
|
|
* Backups to multiple destinations
|
|
|
|
* Transfer via ssh
|
|
|
|
* Resume of backups (if backup target was not reachable for a while)
|
|
|
|
* Encrypted backups to non-btrfs destinations
|
2016-04-13 19:56:35 +02:00
|
|
|
* Wildcard subvolumes (useful for docker and lxc containers)
|
2016-02-29 13:57:51 +01:00
|
|
|
* Transaction log
|
2016-04-15 22:00:10 +02:00
|
|
|
* Comprehensive list and statistics output
|
|
|
|
* Resolve and trace btrfs parent-child and received-from relationships
|
2016-02-29 13:57:51 +01:00
|
|
|
* Display file changes between two backups
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2016-04-13 19:56:35 +02:00
|
|
|
btrbk is designed to run as a cron job for triggering periodic
|
|
|
|
snapshots and backups, as well as from the command line (e.g. for
|
|
|
|
instantly creating additional snapshots).
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
Installation
|
|
|
|
============
|
|
|
|
|
2018-10-10 01:54:51 +02:00
|
|
|
Btrbk is a single perl script, and does not require any special
|
|
|
|
installation procedures or libraries. Simply download the latest
|
|
|
|
[btrbk source tarball] and run the "btrbk" executable.
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2018-10-10 01:54:51 +02:00
|
|
|
For more information, read the [installation documentation].
|
2016-02-29 13:57:51 +01:00
|
|
|
|
2018-10-10 01:54:51 +02:00
|
|
|
[btrbk source tarball]: https://digint.ch/download/btrbk/releases/
|
|
|
|
[installation documentation]: doc/install.md
|
|
|
|
|
|
|
|
|
|
|
|
### Prerequisites
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2019-01-04 15:49:10 +01:00
|
|
|
* [btrfs-progs]: Btrfs filesystem utilities >= v4.12
|
2016-04-15 01:22:19 +02:00
|
|
|
* [Perl interpreter]: Probably already installed on your system
|
2017-03-17 21:57:05 +01:00
|
|
|
* [OpenSSH]: If you want to transfer backups from/to remote locations
|
2017-07-05 17:27:10 +02:00
|
|
|
* [Pipe Viewer]: If you want rate limiting and progress bars
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2018-10-10 01:40:19 +02:00
|
|
|
[btrfs-progs]: https://www.kernel.org/pub/linux/kernel/people/kdave/btrfs-progs/
|
2016-04-13 19:56:35 +02:00
|
|
|
[Perl interpreter]: https://www.perl.org
|
2018-10-10 01:40:19 +02:00
|
|
|
[OpenSSH]: https://www.openssh.org
|
|
|
|
[Pipe Viewer]: https://www.ivarch.com/programs/pv.shtml
|
2015-03-24 13:13:00 +01:00
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
Synopsis
|
|
|
|
========
|
|
|
|
|
2016-07-14 14:00:14 +02:00
|
|
|
Please consult the [btrbk(1)] man-page provided with this package for
|
|
|
|
a full description of the command line options.
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2017-10-11 18:14:26 +02:00
|
|
|
[btrbk(1)]: https://digint.ch/btrbk/doc/btrbk.1.html
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
Configuration File
|
|
|
|
==================
|
|
|
|
|
2015-03-27 00:46:48 +01:00
|
|
|
Before running `btrbk`, you will need to create a configuration
|
|
|
|
file. You might want to take a look at `btrbk.conf.example` provided
|
|
|
|
with this package. For a detailed description, please consult the
|
2015-09-29 15:59:15 +02:00
|
|
|
[btrbk.conf(5)] man-page.
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
When playing around with config-files, it is highly recommended to
|
|
|
|
check the output using the `dryrun` command before executing the
|
|
|
|
backups:
|
|
|
|
|
2017-04-29 18:47:04 +02:00
|
|
|
btrbk -c /path/to/myconfig -v dryrun
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
This will read all btrfs information on the source/target filesystems
|
|
|
|
and show what actions would be performed (without writing anything to
|
|
|
|
the disks).
|
|
|
|
|
2017-10-11 18:14:26 +02:00
|
|
|
[btrbk.conf(5)]: https://digint.ch/btrbk/doc/btrbk.conf.5.html
|
2015-03-27 00:46:48 +01:00
|
|
|
|
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
Example: laptop with usb-disk for backups
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
In this example, we assume you have a laptop with:
|
|
|
|
|
2017-04-29 18:47:04 +02:00
|
|
|
* a disk having a btrfs root subvolume (subvolid=5) mounted on
|
|
|
|
`/mnt/btr_pool`, containing a subvolume `rootfs` for the root
|
|
|
|
filesystem (i.e. mounted on `/`) and a subvolume `home` for the
|
|
|
|
user data,
|
|
|
|
* a directory or subvolume `/mnt/btr_pool/btrbk_snapshots` which
|
|
|
|
will hold the btrbk snapshots,
|
2016-02-29 13:57:51 +01:00
|
|
|
* a backup disk having a btrfs volume mounted as `/mnt/btr_backup`,
|
2017-04-29 18:47:04 +02:00
|
|
|
containing a subvolume or directory `mylaptop` for the incremental
|
|
|
|
backups.
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
Retention policy:
|
|
|
|
|
2016-04-12 12:07:33 +02:00
|
|
|
* keep all snapshots for 2 days, no matter how frequently you (or
|
|
|
|
your cron-job) run btrbk
|
2017-03-30 22:34:48 +02:00
|
|
|
* keep daily snapshots for 14 days (very handy if you are on
|
2016-04-12 12:07:33 +02:00
|
|
|
the road and the backup disk is not attached)
|
2016-02-29 13:57:51 +01:00
|
|
|
* keep monthly backups forever
|
|
|
|
* keep weekly backups for 10 weeks
|
|
|
|
* keep daily backups for 20 days
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
/etc/btrbk/btrbk-mylaptop.conf:
|
|
|
|
|
2016-04-12 19:55:29 +02:00
|
|
|
snapshot_preserve_min 2d
|
2016-04-12 12:07:33 +02:00
|
|
|
snapshot_preserve 14d
|
2016-04-19 21:07:04 +02:00
|
|
|
|
2016-05-30 13:19:07 +02:00
|
|
|
target_preserve_min no
|
2016-04-12 12:07:33 +02:00
|
|
|
target_preserve 20d 10w *m
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
snapshot_dir btrbk_snapshots
|
|
|
|
|
|
|
|
volume /mnt/btr_pool
|
2015-03-27 00:57:43 +01:00
|
|
|
subvolume rootfs
|
2015-02-07 15:53:21 +01:00
|
|
|
target send-receive /mnt/btr_backup/mylaptop
|
|
|
|
|
2015-03-27 00:57:43 +01:00
|
|
|
subvolume home
|
2015-02-07 15:53:21 +01:00
|
|
|
target send-receive /mnt/btr_backup/mylaptop
|
|
|
|
|
|
|
|
|
|
|
|
/etc/cron.daily/btrbk:
|
|
|
|
|
2015-09-16 15:28:47 +02:00
|
|
|
#!/bin/sh
|
2015-09-16 15:27:56 +02:00
|
|
|
exec /usr/sbin/btrbk -q -c /etc/btrbk/btrbk-mylaptop.conf run
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
* This will create snapshots on a daily basis:
|
|
|
|
* `/mnt/btr_pool/btrbk_snapshots/rootfs.YYYYMMDD`
|
|
|
|
* `/mnt/btr_pool/btrbk_snapshots/home.YYYYMMDD`
|
|
|
|
* And create incremental backups in:
|
|
|
|
* `/mnt/btr_backup/mylaptop/rootfs.YYYYMMDD`
|
|
|
|
* `/mnt/btr_backup/mylaptop/home.YYYYMMDD`
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2015-05-20 21:51:20 +02:00
|
|
|
If you want the snapshots to be created only if the backup disk is
|
|
|
|
attached, simply add the following line to the config:
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2015-05-20 21:51:20 +02:00
|
|
|
snapshot_create ondemand
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2019-04-20 14:51:31 +02:00
|
|
|
For a quick additional snapshot of your home, run:
|
|
|
|
|
|
|
|
# btrbk snapshot home
|
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
Example: host-initiated backup on fileserver
|
|
|
|
--------------------------------------------
|
|
|
|
|
2015-05-25 17:13:36 +02:00
|
|
|
Let's say you have a fileserver at "myserver.mydomain.com" where you
|
2015-02-07 15:53:21 +01:00
|
|
|
want to create backups of your laptop disk, the config would look like
|
|
|
|
this:
|
|
|
|
|
|
|
|
ssh_identity /etc/btrbk/ssh/id_rsa
|
|
|
|
|
|
|
|
volume /mnt/btr_pool
|
2015-03-27 00:57:43 +01:00
|
|
|
subvolume rootfs
|
2015-02-07 15:53:21 +01:00
|
|
|
target send-receive /mnt/btr_backup/mylaptop
|
|
|
|
target send-receive ssh://myserver.mydomain.com/mnt/btr_backup/mylaptop
|
|
|
|
|
|
|
|
In addition to the backups on your local usb-disk mounted at
|
|
|
|
`/mnt/btr_backup/mylaptop`, incremental backups would also be pushed
|
|
|
|
to `myserver.mydomain.com`.
|
|
|
|
|
|
|
|
|
|
|
|
Example: fileserver-initiated backups from several hosts
|
|
|
|
--------------------------------------------------------
|
|
|
|
|
|
|
|
If you're a sysadmin and want to trigger backups directly from your
|
|
|
|
fileserver, the config would be something like:
|
|
|
|
|
|
|
|
ssh_identity /etc/btrbk/ssh/id_rsa
|
|
|
|
|
|
|
|
volume ssh://alpha.mydomain.com/mnt/btr_pool
|
|
|
|
subvolume rootfs
|
|
|
|
target send-receive /mnt/btr_backup/alpha
|
|
|
|
|
|
|
|
subvolume home
|
|
|
|
target send-receive /mnt/btr_backup/alpha
|
|
|
|
|
|
|
|
volume ssh://beta.mydomain.com/mnt/btr_pool
|
|
|
|
subvolume rootfs
|
|
|
|
target send-receive /mnt/btr_backup/beta
|
|
|
|
|
|
|
|
subvolume dbdata
|
|
|
|
target send-receive /mnt/btr_backup/beta
|
|
|
|
|
2016-07-14 14:00:14 +02:00
|
|
|
This will pull backups from alpha/beta.mydomain.com and locally
|
|
|
|
create:
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
* `/mnt/btr_backup/alpha/rootfs.YYYYMMDD`
|
|
|
|
* `/mnt/btr_backup/alpha/home.YYYYMMDD`
|
|
|
|
* `/mnt/btr_backup/beta/rootfs.YYYYMMDD`
|
|
|
|
* `/mnt/btr_backup/beta/dbdata.YYYYMMDD`
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
Example: local time-machine (hourly snapshots)
|
|
|
|
----------------------------------------------
|
2015-03-27 00:34:32 +01:00
|
|
|
|
2015-05-25 17:13:36 +02:00
|
|
|
If all you want is to create snapshots of your home directory on a
|
2015-05-20 21:51:20 +02:00
|
|
|
regular basis:
|
2015-03-27 00:34:32 +01:00
|
|
|
|
2015-05-20 21:51:20 +02:00
|
|
|
/etc/btrbk/btrbk.conf:
|
2015-03-27 00:34:32 +01:00
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
timestamp_format long
|
|
|
|
snapshot_preserve_min 18h
|
|
|
|
snapshot_preserve 48h 20d 6m
|
|
|
|
|
2015-03-27 00:34:32 +01:00
|
|
|
volume /mnt/btr_pool
|
2015-05-20 21:51:20 +02:00
|
|
|
snapshot_dir btrbk_snapshots
|
2015-03-27 00:34:32 +01:00
|
|
|
subvolume home
|
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
/etc/cron.hourly/btrbk:
|
2015-03-27 00:34:32 +01:00
|
|
|
|
2015-09-16 15:28:47 +02:00
|
|
|
#!/bin/sh
|
2015-09-16 15:27:56 +02:00
|
|
|
exec /usr/sbin/btrbk -q run
|
2015-05-20 21:51:20 +02:00
|
|
|
|
2017-03-17 21:57:05 +01:00
|
|
|
Note that you can run btrbk more than once an hour, e.g. by calling
|
2016-04-19 21:07:04 +02:00
|
|
|
`sudo btrbk run` from the command line. With this setup, all those
|
|
|
|
extra snapshots will be kept for 18 hours.
|
2015-05-20 21:51:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
Example: multiple btrbk instances
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
Let's say we have a host (at 192.168.0.42) running btrbk with the
|
|
|
|
setup of the time-machine example above, and we need a backup server
|
|
|
|
to only fetch the snapshots.
|
|
|
|
|
|
|
|
/etc/btrbk/btrbk.conf (on backup server):
|
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
target_preserve_min no
|
|
|
|
target_preserve 0d 10w *m
|
|
|
|
|
2015-05-20 21:51:20 +02:00
|
|
|
volume ssh://192.168.0.42/mnt/btr_pool
|
|
|
|
subvolume home
|
2016-04-19 21:07:04 +02:00
|
|
|
snapshot_dir btrbk_snapshots
|
|
|
|
snapshot_preserve_min all
|
|
|
|
snapshot_create no
|
2015-05-20 21:51:20 +02:00
|
|
|
|
|
|
|
target send-receive /mnt/btr_backup/my-laptop.com
|
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
If the server runs btrbk with this config, 10 weeklies and all
|
|
|
|
monthlies are received from 192.168.0.42. The source filesystem is
|
|
|
|
never altered because of `snapshot_preserve_min all`.
|
2015-03-27 00:34:32 +01:00
|
|
|
|
|
|
|
|
2019-04-01 20:12:38 +02:00
|
|
|
Example: virtual machine setup
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
Common virtual machine setups have multiple volume sections with same
|
|
|
|
host, but distinct port numbers for each machine.
|
|
|
|
|
|
|
|
/etc/btrbk/btrbk.conf:
|
|
|
|
|
|
|
|
# This propagates to all subvolume sections:
|
|
|
|
target send-receive /mnt/btr_backup/
|
|
|
|
|
|
|
|
volume ssh://localhost:2201/mnt/btr_pool
|
2019-04-19 15:23:01 +02:00
|
|
|
group vm vm01
|
2019-04-01 20:12:38 +02:00
|
|
|
subvolume home
|
|
|
|
snapshot_name vm01-home
|
|
|
|
subvolume data
|
|
|
|
snapshot_name vm01-data
|
|
|
|
|
|
|
|
volume ssh://localhost:2202/mnt/btr_pool
|
2019-04-19 15:23:01 +02:00
|
|
|
group vm vm02
|
2019-04-01 20:12:38 +02:00
|
|
|
subvolume home
|
|
|
|
snapshot_name vm02-home
|
|
|
|
|
|
|
|
volume ssh://localhost:2203/mnt/btr_pool
|
|
|
|
[...]
|
|
|
|
|
|
|
|
This will create `/mnt/btr_backup/vm[NN]-home`, `vm[NN]-data`, ...
|
|
|
|
|
|
|
|
Note that btrbk holds a single reference to every btrfs filesystem
|
|
|
|
tree, regarding UUID's as "globally unique". If the configured
|
|
|
|
subvolumes point to the same filesystem on different machines (ports),
|
|
|
|
you will see log lines like this when running `btrbk -v`:
|
|
|
|
|
|
|
|
```
|
|
|
|
Assuming same filesystem: "ssh://localhost:2201/dev/sda1", "ssh://localhost:2202/dev/sda1"
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2015-10-23 21:15:49 +02:00
|
|
|
Example: backup from non-btrfs source
|
|
|
|
-------------------------------------
|
|
|
|
|
|
|
|
First create a btrfs subvolume on the backup server:
|
|
|
|
|
|
|
|
# btrfs subvolume create /mnt/btr_backup/myhost_sync
|
|
|
|
|
|
|
|
In your daily cron script, prior to running btrbk, sync your source to
|
|
|
|
`myhost_sync`, something like:
|
|
|
|
|
2016-08-17 14:49:27 +02:00
|
|
|
rsync -a --inplace --delete -e ssh myhost.mydomain.com:/data/ /mnt/btr_backup/myhost_sync/
|
2015-10-23 21:15:49 +02:00
|
|
|
|
|
|
|
Then run btrbk, with myhost_sync configured *without any targets* as
|
|
|
|
follows:
|
|
|
|
|
|
|
|
volume /mnt/btr_backup
|
|
|
|
subvolume myhost_sync
|
2016-04-19 21:07:04 +02:00
|
|
|
snapshot_name myhost
|
2015-10-23 21:15:49 +02:00
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
snapshot_preserve_min latest
|
|
|
|
snapshot_preserve 14d 20w *m
|
2015-10-23 21:15:49 +02:00
|
|
|
|
|
|
|
This will produce daily snapshots `/mnt/btr_backup/myhost.20150101`,
|
2016-04-12 12:07:33 +02:00
|
|
|
with retention as defined with the snapshot_preserve option.
|
2015-10-23 21:15:49 +02:00
|
|
|
|
|
|
|
Note that the provided script: "contrib/cron/btrbk-mail" has support
|
|
|
|
for this!
|
|
|
|
|
|
|
|
|
2015-09-29 15:59:15 +02:00
|
|
|
Example: encrypted backup to non-btrfs target
|
|
|
|
---------------------------------------------
|
|
|
|
|
|
|
|
If your backup server does not support btrfs, you can send your
|
|
|
|
subvolumes to a raw file.
|
|
|
|
|
2015-10-23 19:26:35 +02:00
|
|
|
This is an _experimental_ feature: btrbk supports "raw" targets,
|
|
|
|
meaning that similar to the "send-receive" target the btrfs subvolume
|
|
|
|
is being sent using `btrfs send` (mirroring filesystem level data),
|
|
|
|
but instead of instantly being received (`btrfs receive`) by the
|
|
|
|
target filesystem, it is being redirected to a file, optionally
|
|
|
|
compressed and piped through GnuPG.
|
2015-09-29 15:59:15 +02:00
|
|
|
|
|
|
|
/etc/btrbk/btrbk.conf:
|
|
|
|
|
2016-04-19 21:07:04 +02:00
|
|
|
raw_target_compress xz
|
|
|
|
raw_target_encrypt gpg
|
|
|
|
gpg_keyring /etc/btrbk/gpg/pubring.gpg
|
|
|
|
gpg_recipient btrbk@mydomain.com
|
2015-09-29 15:59:15 +02:00
|
|
|
|
|
|
|
volume /mnt/btr_pool
|
|
|
|
subvolume home
|
2015-10-23 19:26:35 +02:00
|
|
|
target raw ssh://cloud.example.com/backup
|
2016-04-19 21:07:04 +02:00
|
|
|
ssh_user btrbk
|
2015-10-23 19:26:35 +02:00
|
|
|
# incremental no
|
2015-09-29 15:59:15 +02:00
|
|
|
|
2015-10-23 19:26:35 +02:00
|
|
|
This will create a GnuPG encrypted, compressed files on the target
|
2017-06-16 17:43:17 +02:00
|
|
|
host. For each backup, two files are created:
|
2015-09-29 15:59:15 +02:00
|
|
|
|
2017-06-16 17:43:17 +02:00
|
|
|
* `/backup/home.YYYYMMDD.btrfs.xz.gpg`: main data file containing
|
|
|
|
the btrfs send-stream,
|
|
|
|
* `/backup/home.YYYYMMDD.btrfs.xz.gpg.info`: sidecar file containing
|
|
|
|
metadata used by btrbk.
|
2015-10-23 19:26:35 +02:00
|
|
|
|
|
|
|
I you are using raw _incremental_ backups, please make sure you
|
|
|
|
understand the implications (see [btrbk.conf(5)], TARGET TYPES).
|
2015-09-29 15:59:15 +02:00
|
|
|
|
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
Setting up SSH
|
|
|
|
==============
|
|
|
|
|
2018-10-10 00:37:38 +02:00
|
|
|
Since btrbk needs root access, it is *very advisable* to take all the
|
|
|
|
security precautions you can. In most cases backups are generated
|
|
|
|
periodically without user interaction, so it is not possible to
|
|
|
|
protect your ssh key with a password. The steps below will give you
|
|
|
|
hints on how to secure your ssh server for a backup scenario. Note
|
|
|
|
that the `btrbk` executable is not needed on the remote side, but you
|
|
|
|
will need the `btrfs` executable from the [btrfs-progs] package.
|
|
|
|
|
|
|
|
|
|
|
|
### Step 1: Create SSH keypair
|
|
|
|
|
|
|
|
On the client side, create a ssh key dedicated to btrbk, without
|
|
|
|
password protection:
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
ssh-keygen -t rsa -b 2048 -f /etc/btrbk/ssh/id_rsa -C btrbk@mydomain.com -N ""
|
|
|
|
|
2018-10-10 00:37:38 +02:00
|
|
|
The content of the public key (/etc/btrbk/ssh/id_rsa.pub) is used for
|
|
|
|
authentication in "authorized_keys" on the server side (see [sshd(8)]
|
|
|
|
for details).
|
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2018-10-10 00:37:38 +02:00
|
|
|
### Step 2 (option): root login restricted by "ssh_filter_btrbk.sh"
|
|
|
|
|
|
|
|
Btrbk comes with a shell script "ssh_filter_btrbk.sh", which restricts
|
|
|
|
ssh access to sane calls to the "btrfs" command needed for snapshot
|
|
|
|
creation and send/receive operations (see [ssh_filter_btrbk(1)]).
|
|
|
|
|
|
|
|
Copy "ssh_filter_btrbk.sh" to "/backup/scripts/", and configure sshd
|
|
|
|
to run it whenever the key is used for authentication. Example
|
|
|
|
"/root/.ssh/authorized_keys":
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2015-09-04 00:30:10 +02:00
|
|
|
# example backup source (also allowing deletion of old snapshots)
|
|
|
|
command="/backup/scripts/ssh_filter_btrbk.sh -l --source --delete" <pubkey>...
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2015-09-04 00:30:10 +02:00
|
|
|
# example backup target (also allowing deletion of old snapshots)
|
|
|
|
command="/backup/scripts/ssh_filter_btrbk.sh -l --target --delete" <pubkey>...
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2016-04-12 19:55:29 +02:00
|
|
|
# example fetch-only backup source (snapshot_preserve_min=all, snapshot_create=no),
|
2015-09-04 00:30:10 +02:00
|
|
|
# restricted to subvolumes within /home or /data
|
|
|
|
command="/backup/scripts/ssh_filter_btrbk.sh -l --send -p /home -p /data" <pubkey>...
|
|
|
|
|
|
|
|
|
2018-10-10 00:37:38 +02:00
|
|
|
### Step 2 (option): dedicated user login, using different backend
|
|
|
|
|
|
|
|
Create a user dedicated to btrbk and add the public key to
|
|
|
|
"/home/btrbk/.ssh/authorized_keys". In "btrbk.conf", choose either:
|
|
|
|
|
|
|
|
* `backend btrfs-progs-btrbk` to use separated binaries with elevated
|
|
|
|
privileges (suid or fscaps) instead of the "btrfs" command (see
|
|
|
|
[btrfs-progs-btrbk]).
|
|
|
|
|
|
|
|
* `backend btrfs-progs-sudo`, configure "/etc/sudoers" and add the
|
|
|
|
`ssh_filter_btrbk.sh --sudo` option.
|
2015-09-04 00:30:10 +02:00
|
|
|
|
|
|
|
|
2018-10-10 00:37:38 +02:00
|
|
|
### Further considerations
|
|
|
|
|
|
|
|
You might also want to restrict ssh access to a static IP address
|
|
|
|
within your network:
|
2016-11-21 14:15:57 +01:00
|
|
|
|
2018-10-10 00:37:38 +02:00
|
|
|
from="192.168.0.42",command=... <pubkey>...
|
2016-11-21 14:15:57 +01:00
|
|
|
|
|
|
|
For even more security, set up a chroot environment in
|
2018-10-10 00:37:38 +02:00
|
|
|
"/etc/ssh/sshd_config" (see [sshd_config(5)]).
|
2015-09-04 00:30:10 +02:00
|
|
|
|
|
|
|
|
2017-10-11 18:14:26 +02:00
|
|
|
[ssh_filter_btrbk(1)]: https://digint.ch/btrbk/doc/ssh_filter_btrbk.1.html
|
2018-10-10 01:40:19 +02:00
|
|
|
[sshd(8)]: https://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8
|
|
|
|
[sshd_config(5)]: https://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/sshd_config
|
2016-11-21 14:15:57 +01:00
|
|
|
[btrfs-progs-btrbk]: https://github.com/digint/btrfs-progs-btrbk
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
|
2015-05-05 12:44:18 +02:00
|
|
|
Restoring Backups
|
|
|
|
=================
|
|
|
|
|
|
|
|
btrbk does not provide any mechanism to restore your backups, this has
|
|
|
|
to be done manually. In the examples below, we assume that you have a
|
|
|
|
btrfs volume mounted at `/mnt/btr_pool`, and the subvolume you want to
|
|
|
|
have restored is at `/mnt/btr_pool/data`.
|
|
|
|
|
2017-05-08 14:28:17 +02:00
|
|
|
**Important**: don't use `btrfs property set` to make a subvolume
|
|
|
|
read-write after restoring. This is a low-level command, and leaves
|
|
|
|
"Received UUID" in a false state which causes btrbk to fail on
|
|
|
|
subsequent incremental backups. Instead, use `btrfs subvolume
|
|
|
|
snapshot` (without `-r` flag) as described below.
|
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
|
2015-05-05 12:44:18 +02:00
|
|
|
Example: Restore a Snapshot
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
First, pick a snapshot to be restored:
|
|
|
|
|
2015-10-22 17:45:27 +02:00
|
|
|
btrbk list snapshots
|
2015-05-05 12:44:18 +02:00
|
|
|
|
|
|
|
From the list, pick the snapshot you want to restore. Let's say it's
|
|
|
|
`/mnt/btr_pool/_btrbk_snap/data.20150101`.
|
|
|
|
|
|
|
|
If the broken subvolume is still present, move it away:
|
|
|
|
|
|
|
|
mv /mnt/btr_pool/data /mnt/btr_pool/data.BROKEN
|
|
|
|
|
|
|
|
Now restore the snapshot:
|
|
|
|
|
|
|
|
btrfs subvolume snapshot /mnt/btr_pool/_btrbk_snap/data.20150101 /mnt/btr_pool/data
|
|
|
|
|
2015-05-25 17:13:36 +02:00
|
|
|
That's it; your `data` subvolume is restored. If everything went fine,
|
2015-05-05 12:44:18 +02:00
|
|
|
it's time to nuke the broken subvolume:
|
|
|
|
|
|
|
|
btrfs subvolume delete /mnt/btr_pool/data.BROKEN
|
|
|
|
|
|
|
|
|
|
|
|
Example: Restore a Backup
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
First, pick a backup to be restored:
|
|
|
|
|
2015-10-22 17:45:27 +02:00
|
|
|
btrbk list backups
|
2015-05-05 12:44:18 +02:00
|
|
|
|
|
|
|
From the list, pick the backup you want to restore. Let's say it's
|
|
|
|
`/mnt/btr_backup/data.20150101`.
|
|
|
|
|
|
|
|
If the broken subvolume is still present, move it away:
|
|
|
|
|
|
|
|
mv /mnt/btr_pool/data /mnt/btr_pool/data.BROKEN
|
|
|
|
|
|
|
|
Now restore the backup:
|
|
|
|
|
|
|
|
btrfs send /mnt/btr_backup/data.20150101 | btrfs receive /mnt/btr_pool/
|
|
|
|
btrfs subvolume snapshot /mnt/btr_pool/data.20150101 /mnt/btr_pool/data
|
|
|
|
btrfs subvolume delete /mnt/btr_pool/data.20150101
|
|
|
|
|
|
|
|
Alternatively, if you're restoring data on a remote host, do something
|
|
|
|
like this:
|
|
|
|
|
|
|
|
btrfs send /mnt/btr_backup/data.20150101 | ssh root@my-remote-host.com btrfs receive /mnt/btr_pool/
|
|
|
|
|
2018-10-13 14:24:26 +02:00
|
|
|
Hint: If you still have common snapshot / backup pairs (i.e. both
|
|
|
|
"snapshot_subvol" and "target_subvol" are listed) consider sending the
|
|
|
|
backup incrementally by specifying a parent subvolume:
|
|
|
|
|
|
|
|
btrfs send -p /mnt/btr_backup/<parent-subvolume> [...]
|
|
|
|
|
|
|
|
This allows btrbk to continue using the parent subvolume for
|
|
|
|
incremental backups later.
|
|
|
|
|
2015-05-05 12:44:18 +02:00
|
|
|
If everything went fine, nuke the broken subvolume:
|
|
|
|
|
|
|
|
btrfs subvolume delete /mnt/btr_pool/data.BROKEN
|
|
|
|
|
|
|
|
|
2015-07-17 00:44:12 +02:00
|
|
|
FAQ
|
|
|
|
===
|
|
|
|
|
|
|
|
Make sure to also read the [btrbk FAQ page](doc/FAQ.md).
|
|
|
|
Help improve it by asking!
|
|
|
|
|
|
|
|
|
2017-07-13 12:54:08 +02:00
|
|
|
Donate
|
|
|
|
======
|
|
|
|
|
|
|
|
So btrbk saved your day?
|
|
|
|
|
|
|
|
I will definitively continue developing btrbk for free, but if you
|
|
|
|
want to support me you can do so:
|
|
|
|
|
|
|
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WFQSSCD9GNM4S)
|
|
|
|
|
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
Development
|
|
|
|
===========
|
|
|
|
|
|
|
|
Source Code Repository
|
|
|
|
----------------------
|
|
|
|
|
2017-10-13 14:02:50 +02:00
|
|
|
The source code for btrbk is managed using Git.
|
|
|
|
|
|
|
|
Official repository:
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2017-10-13 13:51:03 +02:00
|
|
|
git clone https://dev.tty0.ch/btrbk.git
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2017-10-13 14:02:50 +02:00
|
|
|
Mirror on GitHub:
|
|
|
|
|
|
|
|
git clone https://github.com/digint/btrbk.git
|
|
|
|
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
How to Contribute
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
Your contributions are welcome!
|
|
|
|
|
2015-05-25 17:13:36 +02:00
|
|
|
If you would like to contribute or have found bugs:
|
2015-03-01 15:19:15 +01:00
|
|
|
|
2016-02-29 13:57:51 +01:00
|
|
|
* Visit the [btrbk project page on GitHub] and use the
|
|
|
|
[issues tracker] there.
|
|
|
|
* Talk to us on Freenode in `#btrbk`.
|
|
|
|
* Contact the author via email (the email address can be found in
|
|
|
|
the sources).
|
2015-03-01 15:19:15 +01:00
|
|
|
|
|
|
|
Any feedback is appreciated!
|
|
|
|
|
2018-10-10 01:40:19 +02:00
|
|
|
[btrbk project page on GitHub]: https://github.com/digint/btrbk
|
|
|
|
[issues tracker]: https://github.com/digint/btrbk/issues
|
2015-02-07 15:53:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
License
|
|
|
|
=======
|
|
|
|
|
|
|
|
btrbk is free software, available under the [GNU General Public
|
2019-04-16 17:04:16 +02:00
|
|
|
License, Version 3 or later][GPL-3.0-or-later].
|
2015-02-07 15:53:21 +01:00
|
|
|
|
2019-04-16 17:04:16 +02:00
|
|
|
[GPL-3.0-or-later]: https://www.gnu.org/licenses/gpl.html
|