Migrate Database to Another Host

IMPORTANT: This tutorial is only for old ejabberd 2.0.5. If you are using ejabberd 2.1.0 or newer, you can use the tutorial included in the ejabberd Guide called "Change Computer Hostname".

Depending in your ejabberd configuration, when you migrate ejabberd from one host to another you may need to also convert ejabberd's Mnesia database from one nodename to other. You can attempt the optimistic migration: copy the Mnesia files to new machine and start ejabberd. If that fails with the error message aborted,{no_exists,config}, then you probably need to convert the database nodename.

Because ejabberd uses Mnesia as its internal database, and because this system stores the Erlang node name into the backup files, when you want to migrate from one host to another you have to 'convert' the backups from the old node name to the new one.

We will assume that the old node name is jab@oldhost and the new one is eja@newhost.

  1. Backup Database on the old Host

    Go to your old host, where you are still running ejabberd. You must do a binary backup of the Mnesia database. There are two methods:

    • Using
      ejabberd_ctl jab@oldhost backup /tmp/ejabberd.backup
    • On the admin web, store binary backup to /tmp/ejabberd.backup
  2. Download convert.erl

    Download convert.erl and save it as /tmp/convert.erl

  3. Start Erlang

    Start Erlang, you will see something like this on your console:

    $ erl
    Erlang (BEAM) emulator version 5.4.10 [source] [hipe]
    
    Eshell V5.4.10  (abort with ^G)
    1>
  4. Compile and Load convert.erl

    On the Erlang shell you have just opened, compile and load the module 'convert':

    1> c("/tmp/convert.erl").
    {ok,convert}
    2>
  5. Convert the Backup

    Now you are ready to convert the backup file. On the Erlang shell:

    2> convert:change_node_name('jab@oldhost', 'eja@newhost', "/tmp/ejabberd.backup", "/tmp/ejabberd2.backup").
    ...
     * Checking table: 'privacy'
       + Checking key: 'ram_copies'
       + Checking key: 'disc_copies'
         - Replacing node: 'jab@oldhost' with node: 'eja@newhost'
       + Checking key: 'disc_only_copies'
    ...
    {ok,switched}
    3>

    If everything went ok, you will have a new file /tmp/ejabberd2.backup ready to be imported on the new host.

  6. Stop the Erlang Shell

    3> q().
    ok
    4> 
    $
  7. Copy the Converted Backup to the new Host

    Copy your newly converted /tmp/ejabberd2.backup from the old host to the new host, for example copy it to /tmp/ejabberd2.backup

  8. Restore the new Backup on the new Host

    Go to your new host, where you plan to run ejabberd from now on. Start ejabberd. It will have no users yet, of course. There are two methods to restore the database from a binary backup file:

    • Using
      ejabberd_ctl eja@newhost restore /tmp/ejabberd2.backup
    • On the admin web, restore from /tmp/ejabberd2.backup

Thanks to Pietrzak for providing usage explanation.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This doesnt work at all.

This doesnt work at all. Doesnt change users, and doesnt modify the back end references in all places.

Garbage.

Guide for latest version

Dear folks

ejabberd ist great!

However, I cannot manage to migrate from the original hostname (derived from localhost) to a new one (mydomain.com).

Even if I follow the steps above, I still need to have the original hostname ("localhost") in the hosts attribute in the .cfg config file.

As soon, as I modify or add a host in the hosts attribute in .cfg, I receive the error message:

Failed RPC connection to the node ejabberd@xxx: nodedown

Is there a precise step-by-step description what to do to start a fresh ejabberd installation with a new @domainname?

Many thanks in advance!

ejabberd.cfg and ejabberdctl.cfg are different

Maybe you are confusing the configuration in ejabberd.cfg of the list of virtual hosts that you want ejabberd to serve
http://www.process-one.net/docs/ejabberd/guide_en.html#hostnames

and the configuration of the node name in ejabberdctl.cfg of the host name of the machine where ejabberd is running
http://www.process-one.net/docs/ejabberd/guide_en.html#nodename
http://www.process-one.net/docs/ejabberd/guide_en.html#changeerlangnodename

Not working...

Hi,

i've tried to migrate my user database to another server. i used the convert.erl script to convert the hostnames, but when trying to restore the database on the new server i get this error:

RPC failed on the node ejabberd@arwen: {'EXIT',
{{case_clause,{aborted,eacces}},
[{ejabberd_ctl,process,1},
{rpc,'-handle_call/3-fun-0-',5}]}}

anyone who could give me a hint, what the problem is?

thanks.

eaccess means something like

eaccess means something like "error accessing a directory or file". Probably ejabberd does not have privilege to read/write the spool files.

Error in process <0.31.0>

I USE the following command as above to backup ejabberd of the old server.
ejabberd_ctl admin@oldhost backup /tmp/ejabberd.backup"

Then use convert.erl to convert it, but i get the error as below, anyone could help me, what is wrong about it?

---------------
convert.erl as above to
Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0] [kernel-poll:false]
Eshell v5.5.5 (abort with ^G)
1> c ("convert.erl").
{ok,convert}
2> convert:change_node_name("admin@localhost","admin@ubuntutest","ejabberd.bak","ejabberd2.bak").

=ERROR REPORT==== 28-Oct-2008::17:20:17===
Error in process <0.31.0> with exit value: {undef,[{mnesia,traverse_backup,["ejabberd.bak","ejabberd2.bak",#Fun,switched]},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {undef,[{mnesia,traverse_backup,
["ejabberd.bak",
"ejabberd2.bak",
#Fun,
switched]},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **

mnesia not available

The error message means that it couldn't find the library 'mnesia', included in Erlang/OTP and also in ejabberd installer.

By the way, I tried today to copy the spool directory, without backup/convert/import:

  1. Stop ejabberd
  2. Copy the files in /var/lib/ejabberd/acl.DCD acl.DCD ... to the same directory in the new machine
  3. In the new machine, start ejabberd
  4. It started and loaded the database, with all its content!

You can try this, if you are lucky it will work, if not you can still try to run convert.

What about restoring to a new server, without a live old server?

Well...

Case:
=====
Restoring ejabberd mnesia database files to a new machine, because the
old machine is no longer available. Yes, this can happen.

Since ejabberd/erlang/mnesia uses the hostname to check if the database
is valid, we have to change the hostname of the new machine a couple
of time.

Here's how.

Machine names:
============
Old machine: milliways.verwijs.org
New machine: shrek.verwijs.org

Files:
======
database files: /var/lib/ejabberd
config files: /etc/ejabberd

Install Ejabberd:
=================
Install ejabberd;
apt-get install ejabberd

Procedure:
==========

01. stop all ejabberd instances on shrek:
shrek# /etc/init.d/ejabberd stop

02. Move all files to a backup location
mv /etc/ejabberd /etc/ejabberd_shrek
mv /var/lib/ejabberd /var/lib/ejabberd_shrek

03. Get the old files into the new location. I had the backupfiles of the
old server placed on the disk of the new server:
cp -a /data/backups/milliways.verwijs.org/etc/ejabberd /etc/ejabberd
cp -a /data/backups/milliways.verwijs.org/var/lib/ejabberd \
/var/lib/ejabberd

04. Important bit: rename shrek to milliways.
echo "milliways" >> /proc/sys/kernel/hostname
echo "milliways" >> /etc/hostname

05. Now the old hostname has been set, ejabberd-milliways will start
(yay!)
/etc/init.d/ejabberd start

06. Make a backup.
ejabberdctl ejabberd@milliways backup /tmp/backupfile

07. Stop ejabberd
/etc/init.d/ejabberd stop

08. Put the hostname back:
echo "shrek" >> /proc/sys/kernel/hostname
echo "shrek" >> /etc/hostname

09. Put the config-files and database files of shrek back:
rm -rf /etc/ejabberd
mv /etc/ejabberd_shrek /etc/ejabberd
rm -rf /var/lib/ejabberd
mv /var/lib/ejabberd_shrek /var/lib/ejabberd

10. Restart ejabberd
/etc/init.d/ejabberd

11. Use the restore procedure as described here to convert and import you backupfile:
--> http://www.ejabberd.im/migrate-host

12. ??????

13. Profit!

For what it's worth...

I've never gotten the convert script to work properly however using a TXT dump of the DB works fine for migrating between hosts. I'm not sure of the pros/cons of it vs a restore from a binary backup but I haven't noticed any problems or oddities.

How to clear down the database?

I'm trying to rename my machine, and have gone through these instructions. Everything seems to work fine, until point 8 where I get this error:

darcachon:/var/lib/ejabberd# ejabberdctl restore ejabberd2.backup
RPC failed on the node ejabberd@darcachon: {'EXIT',
                                               {badarg,
                                                   [{ets,
                                                        lookup,
                                                        [config,hosts]},
                                                    {ejabberd_config,
                                                        get_global_option,
                                                        1},
                                                    {ejabberd_admin,
                                                        keep_modules_tables,
                                                        0},
                                                    {ejabberd_admin,
                                                        keep_tables,
                                                        0},
                                                    {ejabberd_admin,restore,1},
                                                    {ejabberd_ctl,process,1},
                                                    {rpc,
                                                        '-handle_call/3-fun-0-',
                                                        5}]}}

I assume this is because the ejabberd cannot start up with the old database; if so, how do I clear down the DB so that it thinks it's starting on a fresh installation?

Cheers,

Giles

Got it working

OK, it's working now. For anyone else who arrives here having renamed their server, only afterwards discovering that ejabberd didn't like it, here's what I did. It worked just fine for me, but I'm no ejabberd expert so YMMV, follow these instructions at your own risk...

  1. Temporarily renamed the host back to its old name by editing /etc/hostname and restarting.
  2. Backed up the database - as above, but nowadays you use a slightly different command:
    ejabberdctl backup /tmp/ejabberd.backup
    
  3. Uninstalled ejabberd using
    apt-get remove ejabberd
  4. Switched back to the new name - edit /etc/hostname and restart.
  5. Reinstalled ejabberd using
    apt-get install ejabberd
  6. Downloaded and run the convert script, just as above.
  7. Put the file /tmp/ejabberd2.backup into /var/lib/ejabberd
  8. Restored the database using the command
    ejabberdctl restore ejabberd2.backup

    .

This seemed to fix things - at least, now I can connect using Pidgin and everything looks OK.

Cheers,

Giles

ejabberd 1.1.2 ?

In ejabberd 1.1.2 it does not work to me

What does not

What does not work?

--
sander

Migrate Database to Another Host

Gracias sander

Erlang (BEAM) emulator version 5.5 [source] [async-threads:0] [hipe]

Eshell V5.5 (abort with ^G)
1> c("convert.erl").
{ok,convert}
2> convert:change_node_name(default@jabber-hispano.org, ejabberd@mundo-chat, "ejabberd.backup", "ejabberd2.backup").

=ERROR REPORT==== 28-Dec-2006::15:03:46 ===
Error in process <0.32.0> with exit value: {badarith,[{erl_eval,eval_op,3},{erl_eval,expr_list,6},{erl_eval,expr,5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {badarith,[{erl_eval,eval_op,3},
{erl_eval,expr_list,6},
{erl_eval,expr,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **
3>

Instructions

Script converts backup files - it replaces every occurence of old node name with new node name. To use it, you have to call it from erl.

First, start erl:

erl -name mynode

Name should be unique, there should be no other node named mynode.

Erl shell should start and display prompt.

Inside erl prompt you can load the file you just saved. This file should reside in current directory. Type:

c(convert).

Erl should print status message "ok".

Now call funtion:

convert:change_node_name(ejabberd@oldhost, 'ejabberd@newhost', "/path/to/old/backup-file", "new-backup-file").

If everything works well you'll get "new-backup-file" in current dir ready to be loaded (with ejabberd restore or ejabberd install-fallback) into new node. Of course you'll have to replace "ejabberd@oldhost" and "ejabberd@newhost" with old and new node names. Quotations used above are correct (in sense that they worked - I don't know Erlang and I completely don't understand quotation issues in this language).

Good luck!

Exporting Mnesia from another host

I had to plug the harddrive containing the Mnesia database to another pc to create a backup, I accomplished it by using a chroot and changing the hostname , if anyone has a similar setup they might be interested in the howto I wrote: http://geekosphere.org/603/mountat-up-again-aka-how-to-export-ejabberd-u....

Syndicate content