Unix/Linux Guru and FOSS supporter

How To Backup And Restore Files Using BorgBackup In Linux

In this article we will learn How To Backup And Restore Files Using BorgBackup In Linux. BorgBackup is a backup tool that provides an efficient way to backup your data using the deduplicating technique. It also supports compression and authenticated encryption. The data deduplication technique makes Borg suitable for daily backups since only changes are stored in a daily backup environment. The authenticated encryption technique makes it suitable for backups to not fully trusted targets.

Some of the features of BorgBackup are as follows:

  • Space efficient storage
  • Deduplication 
  • Speed
  • Compression
  • Data encryption
  • Easy installation on multiple platforms
  • Secure

Install BorgBackup:

Borg is available in the default repositories of most Linux distributions. So, we can install it using the distribution-specific package manager.

Use the following command to install BorgBackup:

dnf install borgbackup -y

You can verify BorgBackup installation using the following command:

borg --version

Backup And Restore files using Borg

First, we will initialize a backup directory as repository for creating backup.

borg init --encryption=none /home/borg/backup

To initialize backup directory with encryption AES-CTR-256 use the following commands:

borg init --encryption=repokey /home/borg/backup/
borg init --encryption=keyfile /home/borg/backup/

We will initialize without encryption.

Once the repository is initialized, you can create backup archives by running the following command:

borg create --stats --progress /home/borg/backup::25-11-2021 /home/borg/backup/

Here backup archive is create as 25-11-2021 (date) so that every backup will be segregated on the basis of date.

You can also use –list and -v flag to list the files in the backup archive while creating backup.

borg create --list -v /home/borg/backup/::27-11-2021 /home/waqar/file

By default, BorgBackup uses lz4 compression in case you want to use another compression technique you can specify using –compression compression type flag with borg create.

Get Archive Info / List backup:

You can get archive information using the following command:

borg info /home/borg/backup/::27-11-2021
Backup And Restore files using Borg
Backup And Restore files using Borg

To list the backups in your archive you can use borg list command. Using Brog list command you can query your repository to list the backup files in it.

borg list /home/borg/backup/

You can also use –json flag to list the details of backup placed in your repository.

borg list --json /home/borg/backup/

To list files in your backup archive use the following command:

borg list /home/borg/backup::25-11-2021

to rename archive you can use the following command:

borg rename /home/borg/backup/::25-11-2021 29-11-2021

Restore Files using BorgBackup:

The primary purpose of backing up the data is to restore it whenever needed. So you can use the borg extract command to restore the data from the archives. When you run the extract command, it will extract the data to the current working directory from where you are running the extract command.
Run the following command to extract an archive to the current working directory. Using -v and –list flag will show you the list of extracted files.

borg extract -v --list /home/borg/backup/::27-11-2021

You can extract a particular directory from the archive by specifying the directory name using the following command:

borg extract -v --list /home/borg/backup/::27-11-2021 home/waqar/

 Delete repository and archive:

You can delete an archive or the entire repository using the borg delete command.

To delete a single archive use the following command:

borg delete /home/borg/backup/::29-11-2021

Similarly, To delete the repository you can give path of the directory as follows:

borg delete /home/borg/backup/

You can use BorgBackup according to your need.


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook