Backing up is a must-do for server administrator, and especially when you are running Koha. Your server could crash and in an instant, you could lose your entire database. So this is how you can protect yourself, and your clients from data loss.

Backup your entire MySQL database

You can backup your entire MySQL database, including your Koha instance databases, using this command

$ mysqldump -u #username -p --all-databases > #any-name-for-your-backup.sql

#username is the username for your MySQL database. Unless you changed this, it is usually root.

#any-name-for-your-backup.sql is the name for your backup. You can choose any name for this, just make sure you add the .sql extension.

You will be prompted to enter your password.

Use the following command to verify your backup is there

$ ls

You should see #any-name-for-your-backup.sql in your folder

Use the following command to see the size of your backup

$ du -h #any-name-for-your-backup.sql

Backup a Single Koha Instance Database

First, you need to see what your Koha instance database is called. Log in to MySQL as follows

$ mysql -u #username -p

where #username is the username for your MySQL database. This is usually root.

mysql> show databases;

All the databases in MySQL will be listed. Make note of the one(s) which you want to backup. The Koha databases will have a “koha_” prefix. If your Koha instance is called “library” for example, you should see the entry “koha_library” in the output. Exit MySQL as follows

mysql> quit;

Now backup your desired Koha database

$ mysqldump -u #username -p koha_library > library.sql


#username is your MySQL admin/root username

koha_library is the name of your Koha database

library.sql is whatever name you choose to give to your backup. Make sure to include the “.sql” extension.

You will be prompted for your MySQL password.

Verify that the SQL file exists

$ ls

You can view its size using the following command

$ du -h #name-of-database.sql

You can proceed to download your backup or save it to a service like DropBox or GoogleDrive. If you have a large backup file, its usually a good idea to compress it, as we show here:

How to Compress Large Files Using 7zip.

Any comments or questions? Let us know down below!