If you are running Koha ILS you might find yourself in a situation where you need to upgrade or replace your servers or change your hosting provider. Instead of having to redo everything from scratch, you simply migrate your old Koha database to the new Koha installation.
In this tutorial, we will show you how to migrate your Koha database in a few simple steps. Server 1 refers to the old server on which you are currently running Koha, and Server 2 is the new server to which you are migrating. We assume that you are running your installation on Ubuntu Server. You will need root access to both servers.
On Server 1
Backup your old Koha database
- Login and open the terminal and enter the following command (if you want to compress the sql file)
mysqldump -u root -p koha_library | gzip -9 > koha_library.sql.gz
- Where -u specifies the user to login to MySQL as, in this case “root”.
- “koha_library” is the name of the database you are backing up.
- “koha_library.sql.gz” is the name (you can call it whatever you want) of the compressed database that will be saved.
- If you don’t want to compress the output database, use this command instead
mysqldump -u root -p koha_library > koha_library_old.sql
- You will be prompted to enter the password for your MySQL user.
- Save the database dump onto a USB stick or transfer it to your new server via FTP, rsync or a similar method
On Server 2
Create new Koha Instance
- Login and open the terminal
- Install your new Koha instance. If you have Koha already installed on your server, then simply create another instance using the following command
sudo koha-create --create-db library
- Where “library” is the name of the new Koha instance
- Otherwise, use these instructions for a fresh installation.
Drop the existing Koha database and create a new one
- First, you have to remove the database created in the new installation on Server 2
- Login to MySQL with the following command
mysql -u root -p
- Where “root” is the root/admin user for your MySQL installation. You will be prompted for a password. Enter it.
- Now you have to drop the current database, and recreate a new one with the following commands
drop database koha_library;
create database koha_library;
Restore the old database backed up from Server 1, to the new installation on Server 2.
- Copy the database backup from Server 1 to home folder of Server 2
- If you compressed it, first extract it using the following command
- To restore the old database into the new Koha instance, use the following command
mysql -u root -p koha_library < koha_library.sql
- Where “root” is the root/admin MySQL user
- “koha_library” is the name of the database of your new Koha instance in Server 2
- “koha_library_old.sql” is the database backup from your old Koha instance on Server 1
- You will be prompted for the MySQL root password. Enter it
Upgrade the Database Schema on Server 2
You should upgrade the Database schema so that it matches the new one using the following command
Rebuild your Zebra Index
The final step is to rebuild your Zebra index using the following command
sudo koha-rebuild-zebra -v -f library