Btrbk: Difference between revisions

From NixOS Wiki
imported>Onny
mNo edit summary
imported>Asymmetric
m add note about ssh key
Line 3: Line 3:
== Setup ==
== Setup ==


When transfering backups of root filesystem snapshots using Btrbk, it is recommended to mount the root Btrfs drive with subvolume id 5 (in this example <code>/dev/sda1</code>) to a specific mountpoint where Btrbk can operate with. So in this case all subvolumes will be available as a subdirectory in <code>/btr_pool</code>.
When transferring backups of root filesystem snapshots using Btrbk, it is recommended to mount the root Btrfs drive with subvolume id 5 (in this example <code>/dev/sda1</code>) to a specific mountpoint where Btrbk can operate with. So in this case all subvolumes will be available as a subdirectory in <code>/btr_pool</code>.


{{file|/etc/nixos/hardware-configuration.nix|nix|<nowiki>
{{file|/etc/nixos/hardware-configuration.nix|nix|<nowiki>
Line 25: Line 25:
     onCalendar = "weekly";
     onCalendar = "weekly";
     settings = {
     settings = {
       ssh_identity = "/etc/btrbk_key";
       ssh_identity = "/etc/btrbk_key"; # NOTE: must be readable by user btrbk
       ssh_user = "btrbk";
       ssh_user = "btrbk";
       stream_compress = "lz4";
       stream_compress = "lz4";
Line 39: Line 39:
For transport stream compression using <code>lz4</code> to work, the package must also be installed on the target host.
For transport stream compression using <code>lz4</code> to work, the package must also be installed on the target host.


== On the remote host ==
This m
== Manual usage ==
== Manual usage ==



Revision as of 12:39, 12 March 2023

Btrbk, a tool for creating snapshots and remote backups of btrfs subvolumes.

Setup

When transferring backups of root filesystem snapshots using Btrbk, it is recommended to mount the root Btrfs drive with subvolume id 5 (in this example /dev/sda1) to a specific mountpoint where Btrbk can operate with. So in this case all subvolumes will be available as a subdirectory in /btr_pool.

/etc/nixos/hardware-configuration.nix
fileSystems = {
  "/btr_pool" = {
    device = "/dev/sda1";
    fsType = "btrfs";
    options = [ "subvolid=5" ];
  };
};

Configuration

Following example configuration will create a weekly incremental backup of a local Btrfs subvolume called nixos and sends it compressed to a remote host myhost via ssh using provided authentication credentials. Note that this references the mount point /btr_pool from above.

/etc/nixos/configuration.nix
services.btrbk = {
  extraPackages = [ pkgs.lz4 ];
  instances.remote = {
    onCalendar = "weekly";
    settings = {
      ssh_identity = "/etc/btrbk_key"; # NOTE: must be readable by user btrbk
      ssh_user = "btrbk";
      stream_compress = "lz4";
      volume."/btr_pool" = {
        target = "ssh://myhost/mnt/mybackups";
        subvolume = "nixos";
      };
    };
  };
};

For transport stream compression using lz4 to work, the package must also be installed on the target host.

On the remote host

This m

Manual usage

Manually dry running and testing a btrbk configuration

btrbk -c /etc/btrbk/remote.conf --dry-run --progress --verbose run

The filename remote.conf references the instance name choosen in the example configuration above.