System Backups with Borg

Create 2023-02-13

mockup

by Georg R. Pollak

In this blog post, we’ll show you how to use Borg and an external disk to backup your system:

Borg is an open-source command-line backup tool that provides encrypted, incremental backups of your data. It is known for its fast, efficient, and secure backup capabilities, making it a popular choice among Linux users. Compared to other backup tools, Borg stands out for its repository-level encryption, which allows you to encrypt your backups while still being able to easily manage your repository metadata. Its incremental backup feature allows you to save storage space and bandwidth by only backing up the changes made to your files.

Mount The Disk

List all block devices to find out the name of the external disk:

lsblk

Mount the external disk:

sudo mount /dev/<name_of_disk> path/to/empty/dir

Initialization

The first step in using Borg is to create a backup folder. This folder will serve as the repository for your backups. To create the folder, use the following command:

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

In this example, --encryption=repokey specifies that Borg should use repository-level encryption, which means that your backups will be encrypted, but the repository metadata (such as the list of backups) will not.

Creating a New Backup

Once your external disk is mounted and you have a backup repository set up, you can create a new backup by running the following command:

borg create --stats </mnt/backup>::<home-user>-{now} /home/<user>
  • --stats: Specifies that Borg should display progress information while creating the backup.
  • </mnt/backup>: This is the location of your backup repository. Replace </mnt/backup> with the actual path to your backup repository.
  • <home-user>: This is the name you want to give to the new backup. Replace <home-user> with a meaningful name for your backup. For example, you could use your username or any identifier that helps you recognize the backup.
  • /home/: This is the directory you want to back up. Replace /home/ with the specific directory path you want to include in the backup. For instance, if you want to back up the entire home directory of a user named "john," you would replace /home/ with /home/john/.

The {now} placeholder in the backup name will be automatically expanded to the current date and time, ensuring that each backup has a unique and timestamped name.

Get Information about Backups

List Backups:
The following command will list all the backups that have been created in the specified backup repository:

sudo borg list path/to/backup_repo_folder

List Top Level Fodlers:
The following command will list all the top-level directories in the specified Borg backup:

borg list <backuprepo>::<backup_name> | awk -F/ '{print $2}' | sort -u

In conclusion, using Borg and an external disk is an effective way to backup your system and protect your data. With these simple steps, you can easily create and manage your backups to ensure that your data is safe and secure.