I reserve the right to change the howto and I’ll not be held responsible if ANY
damage is caused by this how-to. If you don’t agree please do not use it! Thanks

The idea of this how-to is to help you deal with this situation:

Imagine you have server with let’s say 10 users. Your server is getting too old
and you want to upgrade it. A good system administrator will not just shut down
the old server work on the new one for few days and then bring it up. A better
solution would be to leave the old server runnin, build the new one, configure
the new one, copy user files from old one to new one and for few seconds just
switch the IPs of both servers.

Now the problem comes when users change their files after you have transfered
them to the new server but before you have switched the IPs.

In this howto I’ll give you set of commands to run and set a cron job that will
update your /home for example every hour without causing high trafic on the
network. Only the first time!

What you need is:
ssh(d) on both servers
rsync on both servers
OpenSSL on both servers

Let’s give some names to our servers:
New server = thunder(192.168.0.101)
Old server = light(102.168.0.100)

we have a bunch of directories in /home/ on “light” that we want to transfer to
/home/ on “thunder”

here is what we do:

SSH no password part:
login to thunder as root
execute:
thunder#mkdir -p /root/.ssh
thunder#chmod 0700 /root/.ssh
thunder#ssh-keygen -t dsa -f /root/.ssh/id_dsa -P ” (two single quotes)

now you will have two new files:
/root/.ssh/id_dsa(your private key)
/root/.ssh/id_dsa.pub(your public key)

login to light as root
execute:
light#scp 192.168.0.101:.ssh/id_dsa.pub .
light#cat id_dsa.pub >> /root/.ssh/authorized_keys2
light#chmod 0600 /root/.ssh/authorized_keys2
NOTE: you might have to do the same for /root/.ssh/authorized_keys

now try to login from thunder to light with the key:
from thunder execute:
thunder#ssh -i /root/.ssh/id_dsa 192.168.0.100
you should login to light without entering password

!WARNING!WARNING!WARNING!WARNING!WARNING!WARNING!WARNING!
if someone gains root access on thunder he will be able to ssh to light without
entering any password if he figures out that you have a key!
!WARNING!WARNING!WARNING!WARNING!WARNING!WARNING!WARNING!

if everything is OK let’s test it trough rsync:

create a directory on light and touch some files:
light#mkdir /home/testdir
light#cd /home/testdir
light#touch a
light#touch b

from thunder execute:
thunder#rsync -azx –delete –numeric-ids -e “ssh -i /root/.ssh/id_dsa” \
192.168.0.100:/home/testdir/ /home/testdir/

you should now see /home/testdir on thunder with a and b in it

now move a to c on light:
light#mv /home/testdir/a /home/testdir/c

execute the same rsync command on thunder:
thunder#rsync -azx –delete –numeric-ids -e “ssh -i /root/.ssh/id_dsa” \
192.168.0.100:/home/testdir/ /home/testdir/

now on thunder you should have /home/testdir/b and /home/testdir/c

the ownership will be preserved while the uid and gid on both thunder and light
match(and they should, but that other how-to 🙂

now go to /etc/cron.hourly on thunder and add the rsync line:
thunder# cd /etc/cron.hourly
thunder# echo “rsync -azx –delete –numeric-ids -e “ssh -i /root/.ssh/id_dsa” \
192.168.0.100:/home/ /home/” > rsync_home_update

And that’s it! Every hour thunder will sync its /home/ with /home/ on light
remember that both directories will be identical, that means if you have new
users on thunder that are not on light, their home directoreis will be deleted!
to avoid that, create /home/oldusers/ and sync /home/ on light to /home/oldusers/
on thunder. Don’t forget to move it later when you switch the servers or change
/etc/passwd on thunder to point to the correct home directories!

Good Luck