[Borg backups](https://borgbackup.readthedocs.io/)
Install
sudo pacman -S python-llfuse borg
Init a repo
borg init --encryption=repokey /path/to/repository
borg init --encryption=keyfile /path/to/repository
repokey
(default) will save the key inside the repository in the config file; keyfile
will not.
If you lose the key you lose access to the files.
With repokey
you can move the repository to another computer and it will work because the key is inside the config file.
To export the key use borg key export <repo> <filename>
where <filename>
is the file name of the exported key.
Import it with borg key import <repo> <filename>
man borg-init
Do a backup
borg create <repo>::<backup_name> /path/to/folder
borg create backups::"dots $(date +'%Y-%m-%d-%H-%M')" /home/yu/.config
borg create -v --stats --progress --compression zlib backups::'Work-{now:%Y-%m-%d-%H-%M}' /mnt --exclude '/mnt/System\ Volume\ Information'
The name <backup_name>
of the backup must be unique.
man borg-create
Export the key
borg key export <repo> <filename>
borg key export --paper /path/to/repo repokey.borg
Remote backups
Init the repository
# Remote repository (accesses a remote borg via ssh)
# keyfile: stores the (encrypted) key into ~/.config/borg/keys/
$ borg init --encryption=keyfile user@hostname:backup
Create a backup
borg create user@10.0.0.1:/backups::documentation /path/to/folder
borg create server:/backups::projects /path/to/folder
pass(1) and borg
BORG_PASSCOMMAND='<command>' borg create <repo>::<backup_name> /path/to/folder
BORG_PASSCOMMAND='pass show borg-backups' borg create /backups::documentation /path/to/folder
List all the backups inside a repository
borg list <repo>
-----------------
Monday Mon, 2016-02-15 19:15:11
repo Mon, 2016-02-15 19:26:54
root-2016-02-15 Mon, 2016-02-15 19:36:29
newname Mon, 2016-02-15 19:50:19
...
List the files inside a backup
borg list <repo>::<backup_name>
--------------------------------
drwxr-xr-x root root 0 Mon, 2016-02-15 17:44:27 .
drwxrwxr-x root root 0 Mon, 2016-02-15 19:04:49 bin
-rwxr-xr-x root root 1029624 Thu, 2014-11-13 00:08:51 bin/bash
lrwxrwxrwx root root 0 Fri, 2015-03-27 20:24:26 bin/bzcmp -> bzdiff
-rwxr-xr-x root root 2140 Fri, 2015-03-27 20:24:22 bin/bzdiff
...
Extract all the files from a backup
borg extract <repo>::<backup_name>
By default borg removes the first /
so /mnt/hdd/folder/file.ext
will be mnt/hdd/folder/file.ext
and will be extracted in the folder where you run the command.
Extract a single file
borg extract <repo>::<backup_name> path/to/file
Example:
## Create the backup
## Year (Y); month (m); day (d); hour (H); minute (M).
borg create backups::Weekly-{now:%Y-%m-%d} /home/yu/dots
## Extract one (1) file from the backup
borg extract backups::Weekly-2019-03-04 dots/.config/i3/config
## Same applies for folders
borg extract backups::Weekly-2019-03-04 dots/.config/borg
Mount a repo
borg mount <repo> </path/to/mount/point>
umount </path/to/mount/point>
Verify integrity
borg --info check --verify-data <repo>
Remove old backups (prune)
Use --dry-run
to see the result without executing it.
# Keep all backups in the last 10 days, 4 additional end of week archives,
# and an end of month archive for every month:
borg prune -v --list --keep-within=10d --keep-weekly=6 --keep-monthly=-1 --prefix='{hostname}-' <repo>
man borg-prune
Remove a backup
borg delete <repo>::<backup_name>
Remove a repo (This will delete all data)
borg delete <repo>
Benchmark
BORG_PASSPHRASE=<password> borg benchmark crud <repo> /path/to/somewhere
Results
C-Z-BIG 508.33 MB/s (10 * 100.00 MB all-zero files: 1.97s)
R-Z-BIG 495.32 MB/s (10 * 100.00 MB all-zero files: 2.02s)
U-Z-BIG 3709.53 MB/s (10 * 100.00 MB all-zero files: 0.27s)
D-Z-BIG 12992.62 MB/s (10 * 100.00 MB all-zero files: 0.08s)
C-R-BIG 292.58 MB/s (10 * 100.00 MB random files: 3.42s)
R-R-BIG 514.11 MB/s (10 * 100.00 MB random files: 1.95s)
U-R-BIG 4226.89 MB/s (10 * 100.00 MB random files: 0.24s)
D-R-BIG 2401.23 MB/s (10 * 100.00 MB random files: 0.42s)
C-Z-MEDIUM 668.84 MB/s (1000 * 1.00 MB all-zero files: 1.50s)
R-Z-MEDIUM 592.89 MB/s (1000 * 1.00 MB all-zero files: 1.69s)
U-Z-MEDIUM 4549.01 MB/s (1000 * 1.00 MB all-zero files: 0.22s)
D-Z-MEDIUM 12338.22 MB/s (1000 * 1.00 MB all-zero files: 0.08s)
C-R-MEDIUM 352.13 MB/s (1000 * 1.00 MB random files: 2.84s)
R-R-MEDIUM 597.51 MB/s (1000 * 1.00 MB random files: 1.67s)
U-R-MEDIUM 5353.34 MB/s (1000 * 1.00 MB random files: 0.19s)
D-R-MEDIUM 2760.41 MB/s (1000 * 1.00 MB random files: 0.36s)
C-Z-SMALL 73.76 MB/s (10000 * 10.00 kB all-zero files: 1.36s)
R-Z-SMALL 169.01 MB/s (10000 * 10.00 kB all-zero files: 0.59s)
U-Z-SMALL 83.71 MB/s (10000 * 10.00 kB all-zero files: 1.19s)
D-Z-SMALL 621.43 MB/s (10000 * 10.00 kB all-zero files: 0.16s)
C-R-SMALL 49.91 MB/s (10000 * 10.00 kB random files: 2.00s)
R-R-SMALL 172.88 MB/s (10000 * 10.00 kB random files: 0.58s)
U-R-SMALL 73.80 MB/s (10000 * 10.00 kB random files: 1.36s)
D-R-SMALL 183.45 MB/s (10000 * 10.00 kB random files: 0.55s)
Backup plan (WIP)
A backup it's not an archive.