Borg backups
Find more resources at borgbackup/community
Commands
borg create <repo>::<backup_name> /path/to/folderCreate a backupborg list <repo>List all the backups inside a repositoryborg list <repo>::<backup_name>List the files inside a backupborg --info check --verify-data <repo>Verify integrityborg mount <repo> </path/to/mount/point>Mount a repoborg delete <repo>::<backup_name>Remove a backupborg delete <repo>Remove a repo (This will delete all data)
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
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
Extract all the files from a backup
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
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
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
Benchmark
ResultsC-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)