Creating backups from Borg

Procédure

BorgBackup

BorgBackup is a deduplication backup program. Compression and encryption are also supported as options.

Borg's main objective is to provide an efficient and secure backup solution. Thanks to deduplication, the backup process with Borg is very fast and makes Borg very attractive for daily backups. You may notice that Borg is significantly faster than other methods, depending on the amount of data and the number of changes to be backed up. With Borg, all data is already encrypted on the client side, making Borg a good choice for hosted systems.

For more information on BorgBackup, visit the BorgBackup website: https://www.borgbackup.org/

Installation

Connect to your VPS server using the SSH service. (The SSH service must first be activated on your VPS server). For your information, SSH servers are not managed by LWS, so you are solely responsible for the actions performed.

To install BorgBackup on your VPS server and on your local machine, a simple command is required.

apt install borgbackup

Activate and configure Borg

You now need to create the directory for the backup repository in the storage area. For example, create a "backups" folder. The "backups" folder will then be initialised as the Borg repository in the next step.

If you are using an SSH key and this is not the default key, you can specify the desired key using the variable environment BORG_RSH. You can specify the SSH command that Borg should use.

Export BORG_RSH='ssh -i /home/user/.ssh/id_rsa

When Borg is initialised, you will be asked to enter a password for your repository. Only this password can allow you to access the repository in the future. It is therefore required for every read or write operation on the repository. You must remember the password because it cannot be restored! To avoid having to enter the password every time Borg runs, you may want to define the BORG_PASSPHRASE variable environment.

$ export BORG_PASSPHRASE="top_secret_passphrase"

First of all, you need to initialise the Borg repository. The repository is nothing more than a folder on your VPS server that Borg provides with some basic structures. All backups are stored in this folder.

The following command initializes the "backups" folder at the root of your VPS server file system.

borg init --encryption=repokey root@vpsXXXXX.lws-hosting.com:/backups

vpsXXXXX.lws-hosting.com should be replaced by the host name or IP address of your VPS server.

Create an initial backup

For example, use the following command to back up the "photos" and "documents" folders in your personal (local) directory to your VPS server's repository. You should give each backup a unique name. A timestamp is useful for creating unique names.

borg create root@vpsXXXXX.lws-hosting.com:/backups::lundi ~/photos ~/documents

Or

$ borg create root@vpsXXXXX.lws-hosting.com:/backups::01-08-2018 ~/photos ~/documents

You can run Borg using other options, for example, to display the progress of a backup while it is being processed or to display statistics about the backup when it is complete. In addition, you can specify exclusion patterns and other things.

For more information, visit the Borg documentation.

Tracking backups (incremental)

Incremental backups are identical to the first. However, thanks to deduplication, they are much faster and extremely efficient in terms of storage space, because they are incremental. You will only need to adjust the name of the backup during the follow-up backup. Remember, you need to use unique names as mentioned below. Simply use the "--stats" option on the next backup to display statistics on the archive created.

$ borg create --stats root@vpsXXXXX.lws-hosting.com:/backups::mardi ~/photos ~/documents

Or

$ borg create --stats root@vpsXXXXX.lws-hosting.com:/backups::02-08-2018 ~/photos ~/documents

Other Borg commands, including archives, restore backups

The Borg documentation provides a very detailed description of all the Borg commands. It's best to start by looking at the quick section, then dive into the usage section to get into the details.

The documentation provides numerous examples of archive lists and restoring backups. It is also possible, for example, to display the differences between backups or delete old backups to reclaim storage space.


Automate backups with cron

To automate and run backups using a cron job:

Create a bash script, for example in the "root" folder of your VPS server: "/root/backup.sh"

#!/usr/bin/env bash ## Set environment variables export BORG_RSH="ssh -i /home/user/.ssh/id_rsa" export BORG_PASSPHRASE="top_secret_passphrase" ## Set some variables BACKUP_USER="root" REPOSITORY_DIR="backups" REPOSITORY="${BACKUP_USER}@${BACKUP_USER}:/${REPOSITORY_DIR}" /usr/bin/borg create --verbose --stats $REPOSITORY::$(date "+%d-%m-%Y") /home/user/photos /home/user/documents

Now test the script before creating the cron job.

chmod u+x backup.sh $ ./backup.sh

If everything is working correctly, you can now run the script as a cronjob. Open crontab as root:

$ crontab -e

And add the following line to run a daily backup at 04:00 in the morning, for example:

0 4 * * * /root/backup.sh > /dev/null 2>&1

Tips

BorgBackup uses duplication, so you can make backups very quickly and without using up a lot of storage space. But you should also be aware that each file is saved only once. If a file is damaged, it will be corrupted in all subsequent backups.

It is therefore advisable to store your important and sensitive data in several repositories.

To avoid compatibility problems, we recommend that you use the same version of Borg Backup on your local machine and on your VPS server.

You can then use the settings to configure your backups for the folders of your choice.

Rate this article :

4.5/5 | 2 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

11mn reading

What are the VPS Dedicated Server limits/quotas at LWS?

0mn reading

Renewing a dedicated server

5mn reading

What is a VPS and OpenVZ?

0mn reading

How do I order a dedicated VPS server on the lws.fr website?


Ask the LWS team and its community a question