Of course we cannot always share details about our work with customers, but nevertheless it is nice to show our technical achievements and share some solutions.
I recently had to migrate an OTRS installation to another server. It's basically not that difficult as the files don't change and all data is stored in the database. However some migration steps should not be forgotten. This guide should serve as a reminder, in case I'll have to do another migration in the future.
The previous server will be called OLDSERVER, the destination server NEWSERVER in the following guide.
OTRS has its database on a MySQL server running on localhost.
1. Stopping OTRS on OLDSERVER
To not risk that during the transfer new tickets arrive or that an agent works on a ticket, OTRS should be stopped on OLDSERVER.
You can do this by stopping the cron service and Apache (or by simply disable the virtual host used for OTRS):
/etc/init.d/cron stop; /etc/init.d/apache2 stop
2. Create backup + transfer data on OLDSERVER
You should now have a consistent state of your OTRS installation on OLDSERVER so you can do a proper backup.
First the OTRS database needs to be dumped, then transferred to NEWSERVER:
mysqldump otrs > /tmp/otrs.sql; scp /tmp/otrs.sql root@NEWSERVER:/tmp/
Note that some OTRS databases can be huge, so it might make sense to zip/gzip/bzip the dump before the transfer.
Then the complete folder /opt/otrs (or wherever you have your OTRS installation installed) can be transferred to the new server.
I chose to pack the whole /opt/otrs into a tar.gz file to keep the file permissions and ownerships and then copy this file with scp:
tar -czf /tmp/otrs.tar.gz /opt/otrs; scp /tmp/otrs.tar.gz root@NEWSERVER:/tmp/
3. Prepare stuff on NEWSERVER
OTRS needs to run under its own system user, so this one needs to be created on NEWSERVER:
useradd -r -d /opt/otrs -c 'OTRS user' -u 1001 otrs
Make sure you use the same UID as used on OLDSERVER, if possible.
The new database (and database user) also needs to be created on NEWSERVER:
mysql> create database otrs;
mysql> grant all on otrs.* to 'otrs'@'localhost' identified by 'somePass';
In case you don't remember the password, you can look it up on OLDSERVER in /opt/otrs/Kernel/Config.pm.
Furthermore I'd stop the cron service on NEWSERVER as well:
4. Import data on NEWSERVER
Let's start with the files. We can now unpack the tar.gz file into /opt:
tar -xzf /tmp/otrs.tar.gz -C /opt/
Verify the file ownerships. If they don't seem OK (e.g. a "ls -l /opt/otrs" doesn't show the user otrs), you should run /opt/otrs/bin/otrs.SetPermissions.pl.
Then import the database:
mysql otrs < /tmp/otrs.sql
5. Don't forget the cronjobs!
This is most likely the step which could be forgotten the easiest. There are of course still the cron jobs on OLDSERVER, which need to run on NEWSERVER.
On OLDSERVER show the crontab of user otrs:
crontab -l -u otrs
Copy the whole output and on NEWSERVER insert it into the crontab:
crontab -e -u otrs
6. Complete the migration
Change DNS records to point to the new IP address, or inform your colleagues about the new domain/URL for OTRS.
It is recommended to do a quick testing on a secondary domain if OTRS works as it should. Only if the tests were successful, the "real" domain should then be changed or pointed to the migrated OTRS installation.
Once the tests were completed, you can start the cron service on NEWSERVER. This will start fetching the mails and create tickets again: