June 20 2022

Back up with Borg

Linux Backup and Restore with Borg Backup. Back up, compress and encrypt files.

Borg Backup
Print Friendly, PDF & Email

What is Borg

BorgBackup (abbreviation: Borg) is a backup program for deduplication. Optionally, it supports compression and authenticated encryption.

Borg's primary goal is to provide an efficient and secure way to back up your data. The data deduplication technique used makes Borg suitable for daily backups as only changes are archived. The authenticated encryption technique makes it suitable for backups to not fully trusted destinations.

Borg Backup Screenshot

consult installation manual or, if you've already downloaded Borg, docs/installation.rstto start with Borg. One is also available offline documentation , in multiple formats.

On Linux systems, you have many options for creating and maintaining backups of your files. Today, let's talk about another tool you might find useful: BorgBackup.

BorgBackup, or “Borg” for short, is a backup program that supports deduplication, compression and encryption. Borg provides an efficient and safe way to back up your data.

Main features of Borg Backup

Space-efficient storage

Deduplication based on content-defined chunking is used to reduce the number of bytes stored: each file is split into a number of blocks of varying length, and only blocks that have never been seen before are added to the repository.

A piece is considered to be a duplicate if its id_hash value is identical. A cryptographically strong hash or MAC function is used as id_hash, for example (hmac-) sha256.

All chunks in the same repository are considered for deduplication, regardless of whether they come from different machines, from previous backups, from the same backup or even from the same single file.

Compared to other deduplication approaches, this method does NOT depend on:

  • file / directory names remain the same: so you can move your stuff without breaking deduplication, even between machines sharing a repository.
  • Complete files or timestamps remain the same - if a large file changes slightly, only a few new blocks need to be archived - this is great for virtual machines or raw disks.
  • The absolute position of a block of data within a file - things may be moved and will still be found by the deduplication algorithm.
Speed
  • the performance-critical code (chunking, compression, encryption) is implemented in C / Cython
  • local caching of index data files / blocks
  • fast detection of unmodified files
Data encryption
All data can be protected using AES 256-bit encryption, data integrity and authenticity are verified using HMAC-SHA256. The data is encrypted on the client side.
Obfuscation
Optionally, borg can actively obfuscate, for example, the file / block size to make fingerprinting attacks more difficult.
Compression

All data can optionally be compressed:

  • lz4 (super fast, low compression)
  • zstd (wide range from high speed and low compression to high compression and low speed)
  • zlib (average speed and compression)
  • lzma (low speed, high compression)
Offsite backup
Borg can store data on any remote host accessible via SSH. If Borg is installed on the remote host, it is possible to achieve large performance gains compared to using a network filesystem (sshfs, nfs,…).
Backups mountable as filesystems
Backup archives can be mounted as user space filesystems for easy interactive review of backups and restores (for example using a regular file manager).
Easy installation on multiple platforms

We offer single file binaries that don't require installation of anything - you can just run them on these platforms:

  • Linux
  • Mac OS X
  • FreeBSD
  • OpenBSD and NetBSD (no support for xattr / ACL or binaries yet)
  • Cygwin (experimental, not yet binary)
  • Windows 10 Linux subsystem (experimental)
Free and open source software
  • safety and functionality can be independently verified
  • licensed under the BSD license (3 clauses), see License for full license

Why use Borg?

Due to Borg's deduplication feature, it only stores changes between directories. This makes backup with Borg fast! Borg also gives you an option to compress files and directories, so that your backups are space-efficient too.

Finally, Borg supports client-side encryption of your files. This means you can back up to storage spaces that you don't completely trust as your data would be encrypted before it is transferred!

Install BorgBackup

BorgBackup is not installed on Linux systems by default. So, to start using Borg, you'll need to install it first. You can install Borg with just one command.

sudo apt-get install borgbackup

Create a backup archive

Now that you have Borg installed, let's start backing up your files! Before the backups can be archived, you will need to start a Borg backup repository. To create an encrypted backup repository, you need to use the --encryptionflag.

borg init --encryption = repokey / path / to / backup_repo

Borg will ask you to enter the passphrase that should be used to encrypt the repository.

Create a backup

And now it's time to create our first backup! You can create a backup of the source_dir in a backup archive called "archive1" in backup_repo:

borg create / path / to / backup_repo :: archive1 / path / to / source_directory

You can also use the --compressionflag to create a compressed backup archive.

borg create --compression COMPRESSION_ALGORITHM.COMPRESSION_LEVEL / path / to / backup_repo :: archive1 / path / to / source_directory

Borg offers you four COMPRESSION_ALGORITHM to choose from lz4zstdzliblzma. Compression is lz4by default. COMPRESSION_LEVELmay vary from 099being the tallest. For example, to use zlibwith the highest compression level, you can do:

borg create --compression zlib, 9 / path / to / backup_repo :: archive1 / path / to / source_directory

Retrieve a backup

You will probably want to restore a backup at some point. Thankfully, recovering a backup with Borg is just as simple!

First, you can list all the backup archives in your backup repository.

borg list / path / to / backup_repo

Borg will list all backup archives stored in the repository:

archive1 Thu, 23-04-2020 01:20:30 archive2 Fri, 24-04-2020 01:20:30

You can also list the contents within an archive.

borg list / path / to / backup_repo :: archive1

To extract a backup and download its files to the current directory, you can use:

borg extract / path / to / backup_repo :: archive1

Before extracting a particular archive file, you may want to compare different archives to find the right version you want to use. You can compare archives without extracting them using:

borg diff / path / to / backup_repo :: archive1 archive2

You can also use Borg to operate on a remote backup directory. All the syntax would be the same, but you will need to specify the username and server in the backup repository path.

borg extract username @ server: / path / to / backup_repo :: archive1

Mount a backup repository

Finally, if you don't know which files you want to restore and need to examine the files, you can mount an archive or the entire backup directory. This will allow you to browse the archive and restore individual files.

To mount a remote directory, you must first create a writable local directory. Then, you can go ahead and mount the repository.

mkdir / tmp / mountborg mount username @ server: / path / to / backup_repo / tmp / mount

After you're done working on the backup repository, you can unmount it:

borg unmount / tmp / mount

Conclusion

Borg is an efficient way to back up your files! In this post, we've covered most of the basic uses of Borg. Remember, you can always get help using the command borg helpor by visiting the Borg documentation page!

Do you have doubts? Not sure where to start? Contact us


We have all the answers to your questions to help you make the right choice.

Write to us

Chat directly with our technical support.

0256569681

Call us immediately during office hours 9:30 - 19:30

Receive assistance

Open a ticket directly in the support area.

INFO

ManagedServer.it is the leading Italian provider of high performance hosting solutions. Our subscription model is affordable and predictable, so customers can access our reliable hosting technologies, dedicated servers and the cloud. ManagedServer.it also offers excellent support and consulting services on Hosting of the main Open Source CMS such as WordPress, WooCommerce, Drupal, Prestashop, Magento.

Press release: Our company has been 100% Italian since June Find out more
+ +
Back to top