Passa ai contenuti principali

[HOW-TO] Migrate linux has never been so easy

Recently i had to migrate my servers from a Virtualbox instances to KVM and LXC containers. ( this guide is also valid for Desktop PC)

Before that i simply move the .vdi file from a machine to another, but .vdi are not compatible with KVM/LXC formats. Moreover converting .vdi to .raw (compatible format for kvm/lxc) is not a good practice since your system will be probably broken.

But, i'm an extremely lazy person...so how can i migrate a server without a long manual process of reinstalling , reconfiguring and moving file?

After some researches i've found this wonderful guide: https://lowendbox.com/blog/how-to-migrate-a-hosted-server-in-5-easy-steps-with-rsync/


I want to summarize and improve it for you (the process will take 5-10 human minutes + the variable upload time):


NOTE: you must be logged as root user before execute following commands.

Step1:

First of all, you need to have both machines powered up.
Assure that you have same linux os version on both machines, if not do the upgrade.

Step2:

Run:

apt-get update; apt-get upgrade; apt-get dist-upgrade
 on both machines

Step 3:

Rsync is able to syncronize the entire system even if it's in running. You just have to exclude some folder that are machine related.

Run
rsync -auHxv --numeric-ids --exclude=/etc/fstab --exclude=/etc/network/* --exclude=/proc/* --exclude=/tmp/* --exclude=/sys/* --exclude=/dev/* --exclude=/mnt/* --exclude=/boot/* --exclude=/root/* root@SRC-IP:/* /
on destination machine (replace SRC-IP with the ip of the source machine)

Step 4:
This step is needed since rsync is not able to overwrite following files.

 Run
rsync -auHxv --numeric-ids root@SRC-IP:/etc/passwd /tmp/ 
rsync -auHxv --numeric-ids root@SRC-IP:/etc/shadow /tmp/ 
rsync -auHxv --numeric-ids root@SRC-IP:/etc/gshadow /tmp/
        rsync -auHxv --numeric-ids root@SRC-IP:/etc/group /tmp/

        mv /tmp/passwd /etc/
        mv /tmp/shadow /etc/
        
mv /tmp/gshadow /etc/
        
mv /tmp/group /etc/

After that, reboot your destination machine and change your IP/Domain destination.
Reconfigure the /etc/network/interface if you are moving a failover IP.


I hope it can help someone!
At least for me, it has been as faster as move a .vdi and reconfiguring the virtualbox instance! 

Please leave a comment about your experience

Commenti

Post popolari in questo blog

JS Class, a full featured javascript class for ES5 and newer.

Have you ever wanted to write classes in Javascript just like in Java,C++ and PHP ?

Now you can with a tiny stand-alone library written in native Javascript and compatible with any environment that supports ES5 specifications! (So even IE9+!)

The entire documentation is available here: https://hw-core.github.io/js-lib-class/

Here you are an example of how the syntax looks, it's very familiar, isn't it?: