Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

5-minute VPS Migration
New on LowEndTalk? Please Register and read our Community Rules.

5-minute VPS Migration

huluwahuluwa Member
edited March 2012 in Tutorials

Migrating VPSes may be painful, but this method can make it more effective. No addtional software requred, just tar and ssh command. You can move all 5GB data in 5 minites*. (Depend on speed port of your VPSes both sides, also file types).

Source IP:
Destination IP: (Complte your configuration first, such as LNMP)

Log into source vps via ssh, then enter the dir your directory. Now I want to move mysql data on /var/lib/mysql to new vps with same path.

root@source:~# cd /var/lib/mysql

Then type this command:
tar czf - huluwadata | ssh [email protected] tar xzf - -C /var/lib/mysql
[This command means gzipped package is transferred to destination vps while ungzipping by ssh. So, your data is compressed when it's going to be transferred.]

Are you sure you want to continue connecting (yes/no)?

Type yes, press enter.

Warning: Permanently added '' (RSA) to the list of known hosts. [email protected]'s password:

Type your password, press enter.
Then it's transferd, the only thing you just do is wating.(When display the such as root@source, complete! )
Ok, let's move my web scripts on /var/www

root@source:/var/lib/mysql# cd /var/www

Type following command.
tar czf - huluwaweb | ssh [email protected] tar xzf - -C /var/www
Just do as aforementioned.

[You can move multi files with the command like this

tar czf - dir1 dir2 | ssh [email protected] tar xzf - -C /var/www


At last, you should copy your webserver's conf file and reslove your domain to the new IP.

Thanked by 1assassin


  • VPNshVPNsh Member, Host Rep

    Thanks, could come in handy (y)

  • raindog308raindog308 Administrator, Veteran

    Why not just scp -rCp ?

  • @raindog308 said: Why not just scp -rCp ?


    rsync FTW

  • tar-ing, rsync-ing, copying, etc. of /var/lib/mysql without shutting down mysql first is a bad idea.
    Better do a mysqldump, bzip2 the file and then transfer it.

  • prometeusprometeus Member, Host Rep

    @rds100 said: do a mysqldump, bzip2 the file and then transfer it.

    you can pipe the mysqldump compressing on fly and transferring i.e.:
    mysqldump mydatabase|gzip -9 | ssh user@destination "cat >/target_dir/mydatabase.sql.gz"

    (replace gzip with bzip2 if you like, but it's a bit slower than gzip)

  • @prometeus or use SSH's compression, and restore at the same time:
    mysqldump mydatabase| ssh -C user@destination "mysql mydatabase"

    Thanked by 1yomero
  • prometeusprometeus Member, Host Rep

    @dmmcintyre3 said: restore at the same time

    yup, I missed the original task :)

Sign In or Register to comment.