backup2l restore utility

Procédure

backup2l

backup2l is a command-line tool for creating and restoring backups on a remote backup system. In a default installation, backups are created autonomously by a cron script.

backup2l supports hierarchical differential backups with a user-specified number of levels and backups per level. With this scheme, the total number of archives to be stored only increases logarithmically with the number of differential backups since the last full backup. As a result, small incremental backups can be generated at short intervals, while there is little need for time- and space-consuming full backups.

The restore function makes it easy to restore the state of the file system or arbitrary directories/files from previous points in time. File and directory ownership and authorisation attributes are correctly restored.

An open driver architecture means that virtually any archiving program can be used as a backend. Built-in drivers support .tar.gz, .tar.bz2 or .afioz files. Other user-defined drivers can be added, as described in the supplied configuration file "first-time.conf".

All control files are stored with the archives on the remote backup system, and their contents are usually self-explanatory. Therefore, in an emergency, a user must not only rely on backup2l's restore functionality, but can - if necessary - browse the files and extract the archives manually.

To decide whether a file is new or modified, backup2l examines its name, modification time, size, ownership and permissions.

It is also possible to perform "Hot Copies", for example of MySQL databases.

Install backup2l

Included as a package with most distributions.

To install backup2l on your local machine, a simple command is required.

⌨ Command
apt-get install backup2l

Configure backup2l

Create these two backup folders:

⌨ Command
$ mkdir -p /var/backup.d/final $ mkdir -p /var/backup.d/preliminary/mysql

The "final" folder contains the archives of the backups performed and the "premilinary" folder contains the "hot copies" of the backups performed.

Edit the backup2 configuration file, for example using the nano text editor:

⌨ Command
$ nano /etc/backup2l.conf

At line:

Code
SRCLIST=(/var/www/mondomaine.fr /var/backup.d/preliminary)

Choose the folders you want to back up. In this example, the folders backed up will be: /var/www/mondomaine.fr and /var/backup.d/preliminary, which contains the "hot copies".

⌨ Command
SKIPCOND=(-path "/var/www/mondomaine.fr/log/*")

As space on the backup target is mostly limited, you should exclude larger directories and files that don't really need to be backed up, such as the log files associated with your website.

⌨ Command
BACKUP_DIR="/var/backup.d/final"

The backup is configured in this directory. The files here are then transferred to the backup server. If necessary, files can also be encrypted.

⌨ Command
MAX_LEVEL=1 MAX_PER_LEVEL=9 MAX_FULL=1 GENERATIONS=1 CREATE_CHECK_FILE=1

This configuration provides a full backup and 9 incremental backups. If a new incremental backup is to be made every week, max_per_level should be set to 6. A full backup and the increments are always required for a restore.

⌨ Command
PRE_BACKUP () { echo "start pre backup scripts" sh /root/backup/hotcopy_mysql.sh chmod -R u=rw,go-rwx /var/backup.d/preliminary/* echo "pre backup scripts completed" }

⌨ Command
POST_BACKUP () { echo "Executing post backup actions." chown -R root:backup /var/backup.d/final chmod -R u=rw,g=r /var/backup.d/final/* sh /root/backup/scp.sh echo "The backup has been completed." echo "----------------------------------------------" }

These functions are implemented before and/or after backups.

In this section, the "PRE_BACKUP()" function is executed before the backup and the "POST_BACKUP()" function is executed after the backup. The backup upload bash script /root/backup/scp.sh is appended to the "POST_BACKUP()" function.

Your backup2l.conf file is now configured, so that backup2l can take your configuration into account, edit this directive as follows:

⌨ Command
UNCONFIGURED=0

Making "hot copies

Some files cannot simply be backed up by copy, because they are constantly accessible. For example, MySQL databases.

  • MySQL
⌨ Command
nano /root/backup/hotcopy_mysql.sh

Here, the "mysqldump" program is used to make data backups of our MySQL databases.

⌨ Command
#!/bin/sh # Removing old dumps and creating directory rm /var/backup.d/preliminary/mysql/alldb.sql.gz mysqldump --user=root --password=XXXXX --all-databases --skip-lock-tables | gzip > /var/backup.d/preliminary/mysql/alldb.sql.gz

Setting up the cron job

To do this, configure the /etc/cron.daily/zz-backup2l file with the following content (this file may already have been configured when backup2l was installed)

⌨ Command
#!/bin/bash # The following command invokes 'backup2l' with the default configuration # file (/etc/backup2l.conf). # # (Re)move it or this entire script if you do not want automatic backups. # # Redirect its output if you do not want automatic e-mails after each backup. ! which backup2l > /dev/null || nice -n 19 backup2l -b

File transfer

There are generally two ways of recovering files from the backup server. The first and most plausible option is to copy from the server on which the backup was made to the target server (backup server): Push Data. This could be done using scp for example. The second option is the data from the backup server, again using scp: Pull Data. The last option is preferable in my opinion because a hacker cannot simply access the backups.

For both options, I recommend using scp, as the backup server probably has an SSH login anyway and performance shouldn't be a factor with a single copy at night. Also, the transmission is encrypted. You can also use rsync.

Files can also be encrypted with gpg and transmitted encrypted only. The data on the backup server is then protected from unauthorised third parties. The decryption key should not be left on a server but copied locally to a removable storage medium such as a USB stick.

Create an SSH key and attach it to the backup server. I invite you to follow this documentation for adding an SSH key to the backup server.

⌨ Command
$ ssh-keygen -b 4096 -t rsa

Next, create a backup bash script in /root/backup

⌨ Command
nano /root/backup/scp.sh

In order to arrange the commands, the "rsyncscpdrive" utility under the name cdXXXX will be used as an example.

⌨ Command
#!/bin/bash SOURCE_DIRECTORY=/var/backup.d/final USER=cdXXXX TARGET_DIRECTORY=/files SERVER=rs1.cloudlws.com scp ${SOURCE_DIRECTORY}/* ${USER}@${SERVER}:${TARGET_DIRECTORY}

Summary of the LWS Cloud Drive packages available, and their prices excluding VAT:

Monthly prices for Cloud Drive packages :
Cloud Drive S
Cloud Drive M
Cloud Drive L
Cloud Drive XL
100GB 250 GB 500GB 1TB
4.99€* 9.99€* 14.99€* 19.99€*

*Price excl.

By following this documentation, you will be able to use the backup2l utility to restore your data.
You can consult our various online backup offers on our sales site.

help.lws.net/a/1238
Was this article helpful?

Yes

No

Read 13 391 times

Thank you! Feel free to ask questions about our documentation if you would like more information, and help us improve it.

Similar articles

A question about this article?

Ask the LWS team and the community. Answers are published after moderation.

Ask the LWS team and its community a question

GDPR: Controller: LWS-Ligne Web Services. Purpose: moderation and public publication of your question, possible notification of an answer. Legal basis: consent (Art. 6(1)(a) GDPR). Email retention: 90 days after notification, 12 months maximum without an answer. To exercise your rights, see the GDPR section of our Terms and Conditions.