Creating Backups with Backupninja
It’s hard to overstate the importance of having adequate backups. While organizing backups can be one of the less interesting administration tasks on a server, if something goes wrong the time invested is well worth it. To be classed as adequate the backups should cover everything required to recover the system to a working state. It is also important to ensure that the backups are automated, as a manual process can easily be forgotten, or not carried out due to a lack of time.
Automating and Managing Backups on Linux with Backupninja
Automation of these backups on Linux servers generally involves creating scripts that can be run to perform the tasks required to back up the server’s files. For users new to Linux, making these scripts can be confusing and difficult. This is where Backupninja comes in. Backupninja is an application that manages the backup process for you, automating the backups and removing the need to write your own custom scripts to get the job done. To make things even easier, you don’t even need to manually edit the configuration files for the backups, as Backupninja provides a handy tool with a graphical interface that you can use to organize your backups.
Installing Backupninja
Backupninja can handle making backups of PostgreSQL and MySQL databases, it can take backups of directories and can even make backups to remote systems. On Debian and Ubuntu systems Backupninja is in the standard repositories and can be installed with:
sudo apt-get update
sudo apt-get install backupninja
The configuration files for Backupninja will be stored in the /etc/backup.d directory, although with the configuration tool you shouldn’t need to go there to edit them. To invoke the configuration tool you need to use the ninjahelper command as follows:
sudo ninjahelper
This will then open a screen with two options: “Create a new backup action” and “Exit ninjahelper”. We’ll now run through an example of creating a backup of your MySQL database.
Start by selecting “create a new backup action”. This will take you through to another screen that offers the different types of backup available for Backupninja to perform. On this screen we’ll select “mysql database backup”. Next you’ll be prompted for the place that you’d like your backups to be stored; the default option is the “/var/backups/mysql/”.
Once you’ve provided the location for your backups you’ll be asked if you want to back up all the databases on the server or select individual ones. If you choose to only back up individual databases then you’ll be offered a screen where you can specify the names of the databases you wish to back up. For the purposes of our example, however, we’ll be choosing to back up all the databases. Once you’ve chosen what to back up you’ll be asked how Backupninja should authenticate against your database. This can be by running the backup as a specific Linux user, by providing the username and password for a MySQL account, or by using the default system login details. For this example we’ll choose username and password. This will present one screen to supply a username and another for the password to access the database for the backup to take place.
Next is a screen with options on how to run the backup. Here we will use sqldump to back up the databases and compress to compress the resulting backup to save space on the disk.
You’ll then be taken back to the original menu. An entry will have been created for the mysql backup, and you can then hit enter on that to get some options to edit or remove it. You can also do a test run or a run a backup now rather than waiting for Backupninja to do it for you.
A browse through the other options will show how simple it is to then create backups to make archives of directories, or use rdiff to run backups to remote systems. You can also use the sys option to make a backup of the configuration of the server’s hardware and installed packages which can make building a replacement server easier if ever need to restart from scratch.
As you can see, Backupninja greatly simplifies the process of making backups of your server.