1 <chapter xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xmlns:xi="http://www.w3.org/2001/XInclude"
5 xml:id="module-borgbase">
6 <title>BorgBackup</title>
8 <emphasis>Source:</emphasis>
9 <filename>modules/services/backup/borgbackup.nix</filename>
12 <emphasis>Upstream documentation:</emphasis>
13 <link xlink:href="https://borgbackup.readthedocs.io/"/>
16 <link xlink:href="https://www.borgbackup.org/">BorgBackup</link> (short: Borg)
17 is a deduplicating backup program. Optionally, it supports compression and
18 authenticated encryption.
21 The main goal of Borg is to provide an efficient and secure way to backup
22 data. The data deduplication technique used makes Borg suitable for daily
23 backups since only changes are stored. The authenticated encryption technique
24 makes it suitable for backups to not fully trusted targets.
26 <section xml:id="module-services-backup-borgbackup-configuring">
27 <title>Configuring</title>
29 A complete list of options for the Borgbase module may be found
30 <link linkend="opt-services.borgbackup.jobs">here</link>.
33 <section xml:id="opt-services-backup-borgbackup-local-directory">
34 <title>Basic usage for a local backup</title>
37 A very basic configuration for backing up to a locally accessible directory
41 opt.services.borgbackup.jobs = {
44 exclude = [ "/nix" "/path/to/local/repo" ];
45 repo = "/path/to/local/repo";
49 passphrase = "secret";
51 compression = "auto,lzma";
60 If you do not want the passphrase to be stored in the world-readable
61 Nix store, use passCommand. You find an example below.
65 <section xml:id="opt-services-backup-create-server">
66 <title>Create a borg backup server</title>
67 <para>You should use a different SSH key for each repository you write to,
68 because the specified keys are restricted to running borg serve and can only
69 access this single repository. You need the output of the generate pub file.
73 <prompt># </prompt>sudo ssh-keygen -N '' -t ed25519 -f /run/keys/id_ed25519_my_borg_repo
74 <prompt># </prompt>cat /run/keys/id_ed25519_my_borg_repo
75 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID78zmOyA+5uPG4Ot0hfAy+sLDPU1L4AiIoRYEIVbbQ/ root@nixos</screen>
78 Add the following snippet to your NixOS configuration:
81 services.borgbackup.repos = {
84 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID78zmOyA+5uPG4Ot0hfAy+sLDPU1L4AiIoRYEIVbbQ/ root@nixos"
86 path = "/var/lib/my_borg_repo" ;
93 <section xml:id="opt-services-backup-borgbackup-remote-server">
94 <title>Backup to the borg repository server</title>
95 <para>The following NixOS snippet creates an hourly backup to the service
96 (on the host nixos) as created in the section above. We assume
97 that you have stored a secret passphrasse in the file
98 <code>/run/keys/borgbackup_passphrase</code>, which should be only
104 services.borgbackup.jobs = {
105 backupToLocalServer = {
106 paths = [ "/etc/nixos" ];
108 repo = "borg@nixos:." ;
110 mode = "repokey-blake2";
111 passCommand = "cat /run/keys/borgbackup_passphrase";
113 environment = { BORG_RSH = "ssh -i /run/keys/id_ed25519_my_borg_repo"; };
114 compression = "auto,lzma";
120 <para>The following few commands (run as root) let you test your backup.
122 > nixos-rebuild switch
123 ...restarting the following units: polkit.service
124 > systemctl restart borgbackup-job-backupToLocalServer
126 > systemctl restart borgbackup-job-backupToLocalServer
127 > export BORG_PASSPHRASE=topSecrect
128 > borg list --rsh='ssh -i /run/keys/id_ed25519_my_borg_repo' borg@nixos:.
129 nixos-backupToLocalServer-2020-03-30T21:46:17 Mon, 2020-03-30 21:46:19 [84feb97710954931ca384182f5f3cb90665f35cef214760abd7350fb064786ac]
130 nixos-backupToLocalServer-2020-03-30T21:46:30 Mon, 2020-03-30 21:46:32 [e77321694ecd160ca2228611747c6ad1be177d6e0d894538898de7a2621b6e68]</programlisting>
134 <section xml:id="opt-services-backup-borgbackup-borgbase">
135 <title>Backup to a hosting service</title>
138 Several companies offer <link
139 xlink:href="https://www.borgbackup.org/support/commercial.html">(paid)
140 hosting services</link> for Borg repositories.
143 To backup your home directory to borgbase you have to:
148 Generate a SSH key without a password, to access the remote server. E.g.
151 <programlisting>sudo ssh-keygen -N '' -t ed25519 -f /run/keys/id_ed25519_borgbase</programlisting>
156 Create the repository on the server by following the instructions for your
162 Initialize the repository on the server. Eg.
164 sudo borg init --encryption=repokey-blake2 \
165 -rsh "ssh -i /run/keys/id_ed25519_borgbase" \
166 zzz2aaaaa@zzz2aaaaa.repo.borgbase.com:repo</programlisting>
170 <para>Add it to your NixOS configuration, e.g.
173 services.borgbackup.jobs = {
176 exclude = [ "/nix" "'**/.cache'" ];
177 repo = "zzz2aaaaa@zzz2aaaaa.repo.borgbase.com:repo";
179 mode = "repokey-blake2";
180 passCommand = "cat /run/keys/borgbackup_passphrase";
182 BORG_RSH = "ssh -i /run/keys/id_ed25519_borgbase";
183 compression = "auto,lzma";
192 <section xml:id="opt-services-backup-borgbackup-vorta">
193 <title>Vorta backup client for the desktop</title>
195 Vorta is a backup client for macOS and Linux desktops. It integrates the
196 mighty BorgBackup with your desktop environment to protect your data from
197 disk failure, ransomware and theft.
200 It can be installed in NixOS e.g. by adding <package>pkgs.vorta</package>
201 to <xref linkend="opt-environment.systemPackages" />.
204 Details about using Vorta can be found under <link
205 xlink:href="https://vorta.borgbase.com/usage">https://vorta.borgbase.com