Btrbk: Difference between revisions

From NixOS Wiki
imported>Onny
mNo edit summary
imported>Onny
Update example configuration
Line 3: Line 3:
== Configuration ==
== Configuration ==


Following example configuration will create a weekly incremental backup of a local Btrfs subvolume called <code>nixos</code> and sends it compressed to a remote host <code>myhost</code> via ssh using provided authentication credentials.
When transfering backups with btrbk of the subvolume used as a root filesystem, it is recommended to mount the Btrfs drive, in this example <code>/dev/sda1</code> subvolume with the id to a specific mountpoint. So in this case all subvolumes will be available as a subdirectory in <code>/btr_pool</code>.


<syntaxhighlight lang="nix">
{{file|/etc/nixos/hardware-configuration.nix|nix|<nowiki>
fileSystems = {
  "/btr_pool" = {
    device = "/dev/sda1";
    fsType = "btrfs";
    options = [ "subvolid=5" ];
  };
};
</nowiki>}}
 
Following example configuration will create a weekly incremental backup of a local Btrfs subvolume called <code>nixos</code> and sends it compressed to a remote host <code>myhost</code> via ssh using provided authentication credentials. Note that this references the mount point <code>/btr_pool</code> from above.
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.btrbk = {
services.btrbk = {
   extraPackages = [ pkgs.lz4 ];
   extraPackages = [ pkgs.lz4 ];
Line 14: Line 26:
       ssh_user = "btrbk";
       ssh_user = "btrbk";
       stream_compress = "lz4";
       stream_compress = "lz4";
       volume."ssh://myhost/mnt" = {
       volume."/btr_pool" = {
         target = "/mnt";
         target = "ssh://myhost/mnt/mybackups";
         subvolume = "nixos";
         subvolume = "nixos";
       };
       };
Line 21: Line 33:
   };
   };
};
};
</syntaxhighlight>
</nowiki>}}


Note that for transport stream compression using <code>lz4</code> to work, the package must also be installed on the target host.
Note that for transport stream compression using <code>lz4</code> to work, the package must also be installed on the target host.
== Usage ==
== Usage ==



Revision as of 04:53, 5 February 2023

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

Configuration

When transfering backups with btrbk of the subvolume used as a root filesystem, it is recommended to mount the Btrfs drive, in this example /dev/sda1 subvolume with the id to a specific mountpoint. 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" ];
  };
};

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";
      ssh_user = "btrbk";
      stream_compress = "lz4";
      volume."/btr_pool" = {
        target = "ssh://myhost/mnt/mybackups";
        subvolume = "nixos";
      };
    };
  };
};

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

Usage

Manually dry running and testing a btrbk configuration

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

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