Table of contents of the article:
A disaster recovery plan is essential for businesses, as it ensures business continuity in the event of unexpected events such as power outages, fires, floods, cyber attacks and other natural or man-made disasters. Borg is an Open Source, free and highly performing solution for data backup, which allows you to create backup copies of company data in a simple and reliable way. Thanks to its high compression and data deduplication function, Borg allows you to make the best use of available storage space, while minimizing storage costs. Additionally, Borg offers easy integration with other systems and tools, making it a great choice for businesses of any size.
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.
consult installation manual or, if you've already downloaded Borg, docs/installation.rst
to 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 --encryption
flag.
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 --compression
flag 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 lz4
, zstd
, zlib
e lzma
. Compression is lz4
by default. COMPRESSION_LEVEL
may vary from 0
a 9
, 9
being the tallest. For example, to use zlib
with 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 [email protected]:/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 [email protected]:/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 help
or by visiting the Borg documentation page!