Skip to content

Server Migration

Observium stores its data in two places, historical data in in RRD format files in the rrd directory and state data and events in the MySQL database. This makes migration easy as you only need to transfer these along with the relevant config.php entries to the new system.

We strongly recommend keeping your config.php small to simplify migrations.

Prepare new server

Firstly install Observium on the new server. You can follow the install guides for this. Ensure that you can log in to the server, and that polling and the web interface function correctly. We recommend using the install script.

Make a note of the database settings for the new server. You'll need these later. You can paste them into a notepad or another text editor.

root@obs-old:/opt/observium# grep db config.php

$config['db_host']      = 'localhost';
$config['db_user']      = 'observium';
$config['db_pass']      = 'new-password';
$config['db_name']      = 'observium';

Now go back to the old server to dump and copy the MySQL database, rrd files and config.

Database dump

To dump the database you need to use the mysqldump command. We recommend using --add-drop-table and --extended-insert. Additional option is --no-tablespaces for prevent error 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation'. You can get the username and password required by grepping them from the configuration file.

root@obs-old:/opt/observium# grep db config.php

$config['db_host']      = 'localhost';
$config['db_user']      = 'observium';
$config['db_pass']      = 'password';
$config['db_name']      = 'observium';

Here we would use "observium" as the username and "password" as the password.

mysqldump -u observium -p --databases observium --no-tablespaces --add-drop-table --extended-insert > observium-dump.sql

This will promp you for your observium database password and dump the database to a file called observium-dump.sql

root@obs-old:/opt/observium# mysqldump -u observium -p --databases observium --no-tablespaces --add-drop-table --extended-insert > observium-dump.sql
Enter password:
root@obs-old:/opt/observium# ls -l observium-dump.sql
-rw-r--r-- 1 root root 170984 Dec  4 06:21 observium-dump.sql

RRD files

The RRD files can be tarred and copied or rsynced to the new server. We'll use tar here. rsync is potentially faster, but more complicated.

tar zcvf observium-rrd.tar.gz rrd

This command will compress all of the RRDs into a single file you can copy to the new server.

root@obs-old:/opt/observium# tar zcvf observium-rrd.tar.gz rrd
rrd/
rrd/localhost/
...
rrd/poller-wrapper_count.rrd

Copy files

You now need to copy the two files you generated along with the config.php to the new installation.

From the new server you can use scp to copy them.

scp <username>@<old_server>:/opt/observium/<filename> /opt/observium

root@obs-new:~# scp adama@192.168.1.189:/opt/observium/observium-rrd.tar.gz /opt/observium/
adama@192.168.1.189's password:
observium-rrd.tar.gz                                                    100%  119KB  65.5MB/s   00:00
root@obs-new:~# scp adama@192.168.1.189:/opt/observium/observium-dump.sql /opt/observium/
adama@192.168.1.189's password:
observium-dump.sql                                                      100%  167KB  77.9MB/s   00:00
root@obs-new:~# scp adama@192.168.1.189:/opt/observium/config.php /opt/observium/
adama@192.168.1.189's password:
config.php                                                              100% 1406     3.3MB/s   00:00

You should now have the three files in the /opt/observium directory on the new server

root@obs-old:~# ls -l /opt/observium/observium-rrd.tar.gz /opt/observium/observium-dump.sql /opt/observium/config.php
-rw-r--r-- 1 root root   1406 Dec  4 06:33 /opt/observium/config.php
-rw-r--r-- 1 root root 170984 Dec  4 06:33 /opt/observium/observium-dump.sql
-rw-r--r-- 1 root root 121711 Dec  4 06:33 /opt/observium/observium-rrd.tar.gz

Modify configuration

Modify the config.php file to replace the database entries from the old server with the ones you copied at the start of this guide. The new server has a different MySQL password, so the old server's config.php won't work without copying at least the username and password generated during installation of the new install.

Note that from this point on we always use the new database username and password.

Replace database

Before we insert the database information it's a good idea to delete all of the tables, just in case there's a mismatch in version between the old and new servers.

Generate a list of tables on the new server and use it to delete them. We will use the MySQL root password for this. We also need to disable and re-enable foreign key checks whilst doing this.

echo "SET FOREIGN_KEY_CHECKS = 0;" > ./drop_all_tables.sql
( mysqldump --add-drop-table --no-data -u root -p observium | grep 'DROP TABLE' ) >> ./drop_all_tables.sql
echo "SET FOREIGN_KEY_CHECKS = 1;" >> ./drop_all_tables.sql
mysql -u root -p observium < ./drop_all_tables.sql

Your observium database should now be compeltely empty. You can insert the dump you generated earlier

mysql -u observium -p observium < observium-dump.sql

root@obs-new:/opt/observium# mysql -u observium -p observium < observium-dump.sql
Enter password:
root@obs-new:/opt/observium#

Replace RRD files

Finally we can restore the RRD files from the tar file. It's probably a good idea to delete the existing RRD directory first.

rm -rf rrd
tar zxvf observium-rrd.tar.gz

The tar file should give a long list of RRDs it's restoring as it's run

root@obs-new:/opt/observium# rm -rf rrd/
root@obs-new:/opt/observium# tar zxvf observium-rrd.tar.gz
rrd/
rrd/localhost/
...
rrd/poller-wrapper_count.rrd
root@obs-new:/opt/observium#

You should also make sure the permissions are correct on the RRD files

chown -R observium.www-data rrd

Finished!

You should now be able to log in to the web interface. Ensure that devices are being correctly polled.

You may need to do additional configuration for mail or other services from the old server.

This process can also be used for backup/restoration by periodically dumping the database, tarring the RRDs and copying them to a backup location. Restoration is as simple as using the backup files in this guide.