5-minute VPS Migration
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: 1.2.3.4
Destination IP:5.6.7.8 (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.]
Dialog
Are you sure you want to continue connecting (yes/no)?
Type yes, press enter.
Warning: Permanently added '5.6.7.8' (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.
Comments
Thanks, could come in handy (y)
Why not just scp -rCp ?
Neeeeeeeh
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.
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"
yup, I missed the original task