[ code. keyboards. terminals. cyber. ]



"No backup - No pity" knows everyone I think.
Who does not want to hear that anymore, should make backups.
There is an exorbitant amount of GUI backup tools for Linux. GUI you do not want to have but under circumstances.
The command-line is more suitable and for the command-line there is BORG (just because of the name you should use BORG).

What is BORG?

BORG is a "deduplicate backup tool". BORG checks the data to be backed up for redundancy and backs up only the data that has changed.
So exactly what you want to have to create space-saving backups.
BORG itself also encrypts the created backups and can also compress them if needed.

The compression methods are as follows:

- lz4 (very fast, low compression)
- zstd (from Fast and no compression to High compression and slow)
- zlib (medium speed and compression)
- lzma (slow but high compression)

BORG can also off-site backups. That means as soon as a SSH connection exists it can be used to write backups there with BORG.

The created backups are even mountable as their own filesystem.

So the perfect backup system.

Installation (NixOS)

. The BORG packages are present in the NixOS packages and can either be written to configarations.nix and is then rebuilt with the following command:

nixos-rebuild switch

The packages can also be installed via nix-env:

nix-env -iA nixos.borgbackup

So ready installed and ready to use.


At BORG, repositories are created for backups.

borg init -e repokey /path/to/repo

Instead of "repo" here of course the name of the repository is assigned.
When creating the password is assigned directly, which you should remember of course, otherwise the backup would no longer be usable.

To create a backup and write it to the repository use the following command:

borg create /path/to/repo::DATE ~/Documents ~/Mail

Here at "::DATE" the name of the individual backup is given (recommended is of course the date in some way) and then all folders that are to be backed up are listed one after the other. In this case "Documents" and "Mail".

This would create the first local backup.

Off-site backups

. Now backups, however, should not be backed up to the machine the backup came from. The reasons should be clear.
On the one hand there is the possibility to outsource the backups to external storage media, on the other hand via SSH to servers.
The latter is done as follows. First, of course, the remote repo must be created:

borg init user@hostname:/path/to/repo

you have created your target repository.
To now write backups out remotely you use:

borg create user@hostname:/path/to/repo::Monday ~/src ~/Documents


Restore Backup

Now every now and then there is a need to restore a backup.
With BORG there are two possibilities "mount" and "extract".
"Mount" mounted as the name suggests, the backup as a filesystem to restore individual files.
"Extract" extracts the entire backup, for example to restore a complete system.

For local backups:

borg list /mnt/backup/borg_repo
borg mount /mnt/backup/borg_repo::myserver-system-2021-06-09 /mnt/borg
borg mount /mnt/backup/borg_repo /mnt/borg

mkdir borg_restore
cd borg_restore
borg list /mnt/backup/borg_repo
borg list /mnt/backup/borg_repo::myserver-system-2021-06-09
borg extract /mnt/backup/borg_repo::myserver-system-2021-06-09 path/to/extract
borg extract /mnt/backup/borg_repo::myserver-system-2021-06-09

For Remote (SSH) Backups:

borg mount ssh:// /mnt/borg

borg extract ssh://

BORG brings of course still many many options of the adjustment. These are available in the documentation (LINK).
For a simple backup, the above commands should be sufficient.

Have fun with your backup!