A cautious or disaster experience will make every system management aware of the importance of frequent system backups. You can do the backup task by writing a legacy shell script that works, or by using a backup tool (or several) that is appropriate for the job. Therefore, the more backup tools you know when you implement a backup solution, the wiser your decisions will be.
In this article, we'll introduce you to Backupninja, a lightweight and easily configurable system Backup tool. With the help of programs such as Rdiff-backup, duplicity, mysqlhotcopy, and mysqldump, Backupninja can provide commonly used backup functions, such as remote, secure, and incremental file system backups, encrypted backups, and MYSQL/MARIADB database backup. You can selectively turn on the Email Status Report feature, or you can back up the general hardware and system information. A key feature of Backupninja is that it has a built-in console-based wizard (called Ninjahelper) that allows you to easily create profiles for different backup scenarios.
If you have to say something, the disadvantage of Backupninja is that in order to fully use all of its features, it requires that you install some other "helper" programs. Although Backupninja has a release version of the RPM installation package based on Red Hat (Red Hat), Backupninja is optimized for the dependencies of Debian and its derived release versions. Therefore, it is not recommended to try Backupninja on a system based on Red Hat.
In this tutorial, we will describe how to install Backupninja on a Debian-based distribution.
Run the following command with the root account:
The code is as follows:
# Aptitude Install Backupninja
During the installation process, several files and directories will be created:
/usr/sbin/backupninja is the main script for a bash shell;
/etc/cron.d/backupninja, by default, the cron task is set up to run the main script every one hours;
/etc/logrotate.d/backupninja truncate the log generated by the Backupninja program;
/etc/backup.d/is the directory where the backup operation's configuration file resides;
/etc/backupninja.conf is the primary configuration file that contains general options. This file has a good annotation and explains the meaning of each option in detail;
/usr/share/backupninja is the directory where the scripts used by the Backupninja are. These script files are responsible for performing the actual work. In this directory, you can also find. helper files that can be used to configure and set ninjahelper menus;
/usr/share/doc/backupninja/examples contains templates for manipulating configuration files (that is, files produced by Ninjahelper).
First Run Ninjahelper
When we try to start ninjahelper, we can see that an internal dependency program may be required. If the system is prompted, enter "Yes" and knock down the ENTER key to install dialog (a tool to display a friendly dialog box from the shell script).
When you type Yes and then hit enter, Backupninja will install dialog, and once the installation is complete, the following screenshot will appear:
Case 1: Backing up hardware and system information
After Ninjahelper is started, we will create a new backup operation:
If the necessary helper program is not installed, the screenshot below will appear in front of us. If these packages are already installed on your system, skip this step.
The next step requires you to select the relevant entry as part of this backup task. The first four entries have been selected by default, but you can undo the selection by pressing the SPACEBAR on the entry.
Once you have completed the above steps, press the OK option to continue. You will then be able to choose whether you want to use the default profile (/etc/backup.d/10.sys) to complete this backup operation, or to create a new configuration file. For the latter, a file containing the same contents as the default profile will be created in the same directory, but it is named 11.sys, and subsequent backup operations will create similar files (note: Except for the named serial number). It should be explained that once the new profile is created, you can edit the file using your favorite text editor.
Case 2: Incremental Rsync Pull Backup of a remote directory
As you are most likely to know, rsync is widely used to synchronize files or folders over a network. In the next example, we'll discuss a method that uses hard links to make incremental pull backups for a remote directory, which is used to save historical data and restore these historical data to our local file servers. This approach will help us save space and enhance security at the server side.
Step 1: Write a custom script with the following, put it in/ETC/BACKUP.D, and set its permissions to 600. It should be explained that, in addition to the general configuration file, this directory may also contain some script files that you want to run when Backupninja executes, and they can take advantage of the variables located in the main configuration file.
The code is as follows:
# REMOTE USER
# REMOTE HOST
# REMOTE DIRECTORY
# local DIRECTORY
# local DIRECTORY WHERE PREVIOUS BACKUP is STORED
MV $localdir $localdirold
Rsync-av--delete--recursive--link-dest= $localdirold $user @ $host: $remotedir $localdir
In the above configuration, the '--link-dest ' option of rsync is to hard link to the target directory ($localdir) for files that are not changed in the $localdir-old directory (including all properties).
Step 2: Before the first run of Backupninja, the upper directory (the one in the case of/home/gacanepa) is empty. The first time we execute the following command:
The code is as follows:
The backup.0 directory is created, and in the next procedure, its name will be changed to BACKUP.1.
When we run Backupninja for the second time, the backup.0 will be recreated, and the BACKUP.1 remain fixed.
Step 3: Make sure the files inside the BACKUP.1 are hard to link to the files in the backup.0, we can do this by comparing the file's Inode (I node) number and the size of the directory.
Backupninja is not only a classic backup utility, it is also an easy to configure utility. You can run Backupninja by writing your own control script and using a different configuration file in the/ETC.BACKUP.D. You can even write helper programs for Ninjahelper and include them in the Ninjahelper main interface.
For example, if you create a control script named Xmodulo in the/usr/share/backupninja directory, it will automatically run each file that is in the/ETC/BACKUP.D directory with the. xmodulo suffix. If you decide to add your Xmodulo control script to Ninjahelper, you can write the appropriate helper program, that is, Xmodulo.helper. Also, if you want Backupninja to run other scripts, just add it to the/ETC/BACKUP.D directory.