The cart is empty

In today's digital era, data backup is a crucial component of protecting against data loss, corruption, or cyber attacks. BorgBackup, also known as Borg, represents an excellent tool for creating and managing backups on CentOS servers. With its ability to perform encrypted, deduplicated backups, Borg allows users to efficiently safeguard their data while minimizing the need for storage space. This article provides a detailed guide on setting up and using BorgBackup on CentOS.

Prerequisites

Before we begin, it's important to ensure you have access to a CentOS server with root privileges or sudo user rights. BorgBackup is compatible with most Linux distributions, including CentOS. Make sure your system is up-to-date using the sudo yum update command.

Installing BorgBackup

You can install BorgBackup on CentOS using the yum command. The first step is to add the EPEL (Extra Packages for Enterprise Linux) repository, which contains the BorgBackup package. You can do this as follows:

sudo yum install epel-release
sudo yum update

After adding the EPEL repository, install BorgBackup:

sudo yum install borgbackup

Initializing the Repository

Before performing the first backup, it is necessary to initialize the Borg repository. The Borg repository is the location where backups will be stored. During initialization, you can choose whether to encrypt the repository. For encryption, we recommend using the repokey or keyfile option, ensuring the security of your data.

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

Replace /path/to/repository with the path where you want to place the repository.

Creating a Backup

With the repository prepared, you can start creating backups. The command to create a backup looks like this:

borg create --verbose --progress --stats /path/to/repository::backup-name /path/to/files-to-backup

/path/to/files-to-backup denotes the files or directories you want to back up. backup-name is a unique identifier for the backup, making it easy to find and restore in the future.

Restoring from a Backup

If you need to restore data, you can use the following command:

borg extract /path/to/repository::backup-name

Automating Backups

For regular backups, it's advisable to set up a cron job that will execute a backup script according to a defined schedule. This ensures that your data is backed up regularly without manual intervention. Setting up a cron job for BorgBackup could look like this:

  1. Open the crontab editor for the current user:
    crontab -e
    ​
  2. Add a line specifying the timing and the command to run the backup. For example, for daily backup at 2:00 AM:
    0 2 * * * /usr/bin/borg create --verbose --stats /path/to/repository::'backup-{now:%Y-%m-%d}' /path/to/files-to-backup
    ​

 

Managing Backups

BorgBackup offers various tools for managing backups, including listing available backups, verifying their integrity, and removing old backups. Here are some basic commands for managing backups:

  • List all backups in the repository:
    borg list /path/to/repository
    ​
  • Verify backup integrity:
    borg check /path/to/repository
    ​
  • Delete a specific backup:
    borg delete /path/to/repository::backup-name
    ​
  • Prune backups to free up space and retain only a certain number of the latest backups:
    borg prune -v --list /path/to/repository --keep-daily=7 --keep-weekly=4 --keep-monthly=6
    ​

This command retains the last 7 daily backups, 4 weekly backups, and 6 monthly backups while removing older backups.

Utilizing BorgBackup on CentOS for creating and managing backups offers an efficient, encrypted, and deduplicated solution for backup. With its flexibility and automation capabilities, Borg is an ideal choice for any application requiring regular data backup. Follow the steps outlined above to secure your important data and ensure its protection against loss or corruption.