Automatic Database Backup in Koha

The most important role a system administrator has to perform is to take daily backups of the database on every production server. But since we, IT guys, are Pro in procrastination, we always prefer to defer it till something terrible happens. Yet we still try to find simple forms for automating stuff because of our mentality “I’ll do it later.” We always ask computers that certain vital tasks be performed, and since our romanticism with computers is no contrast, backup is such a task. The koha database can be provided with the cron job feature in Linux with a scheduled backup. Cron is a system daemon used to execute desired tasks (in the background) at designated times.

MySQL Dumps and a cronjob combination will be the best way to automate the work. A lot of information is available here, but in order to complete: build a file of containing MySQL dumping we must plan in a command (replace user, password and path for your environment): You will find loads of information on this subject on this and other Internet sites:

In this process, we put a MySQL command to take a backup of the Koha database every 60 minutes.
Create a folder in the home folder called “backup”, where the backup file will be stored.

Open Applications > Accessories > Terminal

issue the following command with escalated privileges,

crontab -e

To open and edit the file it will ask to pick a text editor. You can choose either the text editor Nano / Vim or Gedit according to your preference and availability.
You can see the contents of the crontab file. Using the down arrow button to move to the bottom of the paper. Copy the command following.

*/60 * * * * mysqldump -usingh -pkoha123 koha_library | xz > /home/koha/backup/koha_library.sql.xz

For every 60 minutes the above listed command will take backup of the koha library database. Bear in mind that I used-usingh as my username and-pkoha123 as my koha library data base password, and xz is a compression format in my case. You need to use your account credentials.

in order to run a backup command in a specific time of your convenience, you can alter the timing values as shown in the following command.

15 30 * * * mysqldump -usingh -pkoha123 koha_library | xz > /home/koha/backup/koha_library.sql.xz

Above mentioned command take a backup at 3:30 PM every day.
Press Ctrl + o button to save the file.
Then Ctrl + x to close the cron file and leave the terminal screen.
This will export the SQL database and a compressed file will be placed in /home/koha/backup folder after the cron job ran successfully.