1 # BorgBackup {#module-borgbase}
3 *Source:* {file}`modules/services/backup/borgbackup.nix`
5 *Upstream documentation:* <https://borgbackup.readthedocs.io/>
7 [BorgBackup](https://www.borgbackup.org/) (short: Borg)
8 is a deduplicating backup program. Optionally, it supports compression and
9 authenticated encryption.
11 The main goal of Borg is to provide an efficient and secure way to backup
12 data. The data deduplication technique used makes Borg suitable for daily
13 backups since only changes are stored. The authenticated encryption technique
14 makes it suitable for backups to not fully trusted targets.
16 ## Configuring {#module-services-backup-borgbackup-configuring}
18 A complete list of options for the Borgbase module may be found
19 [here](#opt-services.borgbackup.jobs).
21 ## Basic usage for a local backup {#opt-services-backup-borgbackup-local-directory}
23 A very basic configuration for backing up to a locally accessible directory is:
26 opt.services.borgbackup.jobs = {
29 exclude = [ "/nix" "/path/to/local/repo" ];
30 repo = "/path/to/local/repo";
34 passphrase = "secret";
36 compression = "auto,lzma";
44 If you do not want the passphrase to be stored in the world-readable
45 Nix store, use passCommand. You find an example below.
48 ## Create a borg backup server {#opt-services-backup-create-server}
50 You should use a different SSH key for each repository you write to,
51 because the specified keys are restricted to running borg serve and can only
52 access this single repository. You need the output of the generate pub file.
55 # sudo ssh-keygen -N '' -t ed25519 -f /run/keys/id_ed25519_my_borg_repo
56 # cat /run/keys/id_ed25519_my_borg_repo
57 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID78zmOyA+5uPG4Ot0hfAy+sLDPU1L4AiIoRYEIVbbQ/ root@nixos
60 Add the following snippet to your NixOS configuration:
63 services.borgbackup.repos = {
66 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID78zmOyA+5uPG4Ot0hfAy+sLDPU1L4AiIoRYEIVbbQ/ root@nixos"
68 path = "/var/lib/my_borg_repo" ;
74 ## Backup to the borg repository server {#opt-services-backup-borgbackup-remote-server}
76 The following NixOS snippet creates an hourly backup to the service
77 (on the host nixos) as created in the section above. We assume
78 that you have stored a secret passphrasse in the file
79 {file}`/run/keys/borgbackup_passphrase`, which should be only
84 services.borgbackup.jobs = {
85 backupToLocalServer = {
86 paths = [ "/etc/nixos" ];
88 repo = "borg@nixos:." ;
90 mode = "repokey-blake2";
91 passCommand = "cat /run/keys/borgbackup_passphrase";
93 environment = { BORG_RSH = "ssh -i /run/keys/id_ed25519_my_borg_repo"; };
94 compression = "auto,lzma";
101 The following few commands (run as root) let you test your backup.
103 > nixos-rebuild switch
104 ...restarting the following units: polkit.service
105 > systemctl restart borgbackup-job-backupToLocalServer
107 > systemctl restart borgbackup-job-backupToLocalServer
108 > export BORG_PASSPHRASE=topSecrect
109 > borg list --rsh='ssh -i /run/keys/id_ed25519_my_borg_repo' borg@nixos:.
110 nixos-backupToLocalServer-2020-03-30T21:46:17 Mon, 2020-03-30 21:46:19 [84feb97710954931ca384182f5f3cb90665f35cef214760abd7350fb064786ac]
111 nixos-backupToLocalServer-2020-03-30T21:46:30 Mon, 2020-03-30 21:46:32 [e77321694ecd160ca2228611747c6ad1be177d6e0d894538898de7a2621b6e68]
114 ## Backup to a hosting service {#opt-services-backup-borgbackup-borgbase}
116 Several companies offer [(paid) hosting services](https://www.borgbackup.org/support/commercial.html)
117 for Borg repositories.
119 To backup your home directory to borgbase you have to:
121 - Generate a SSH key without a password, to access the remote server. E.g.
123 sudo ssh-keygen -N '' -t ed25519 -f /run/keys/id_ed25519_borgbase
125 - Create the repository on the server by following the instructions for your
127 - Initialize the repository on the server. Eg.
129 sudo borg init --encryption=repokey-blake2 \
130 --rsh "ssh -i /run/keys/id_ed25519_borgbase" \
131 zzz2aaaaa@zzz2aaaaa.repo.borgbase.com:repo
133 - Add it to your NixOS configuration, e.g.
136 services.borgbackup.jobs = {
139 exclude = [ "/nix" "'**/.cache'" ];
140 repo = "zzz2aaaaa@zzz2aaaaa.repo.borgbase.com:repo";
142 mode = "repokey-blake2";
143 passCommand = "cat /run/keys/borgbackup_passphrase";
145 environment = { BORG_RSH = "ssh -i /run/keys/id_ed25519_borgbase"; };
146 compression = "auto,lzma";
152 ## Vorta backup client for the desktop {#opt-services-backup-borgbackup-vorta}
154 Vorta is a backup client for macOS and Linux desktops. It integrates the
155 mighty BorgBackup with your desktop environment to protect your data from
156 disk failure, ransomware and theft.
158 It can be installed in NixOS e.g. by adding `pkgs.vorta`
159 to [](#opt-environment.systemPackages).
161 Details about using Vorta can be found under
162 [https://vorta.borgbase.com](https://vorta.borgbase.com/usage) .