Migrate Hosted VPS server to my own server
Is it possible to direct copy an entire VPS host to my own server?
My current VPS is in the US and the response times from/to Denmark are bugging me a lot. I have previously had my own server, running FreeBSD, before I switched to the VPS. For the sake of a quick'n'easy move, I wondered if I could just make a diskimage of the VPS and then extract it to my server which I have placed at my workplace here in Denmark.
Solution 1:
Presuming some kind of linux/bsd, it's actually possible to copy a 'running' system over to another one. The target is strongly recommended to be booted in something other than the systemdisk (rescue system, or swap partition with mini system installed).
The advantage of this approach is all kinds of settings are identical (permissions, user crontabs, web server library versions, ...). Of course you also copy over all the cruft that has built up as well.
First turn of everything holding important data or not strictly required (database, http server, all kinds of daemons etc).
You can then tar / and copy it over, install the bootloader on the target system.
Then reboot.
Any running daemons may think the system crashed, but it should be no worse than pidfile overrides.
Tips:
- start the whole operation from a screen or use nohup.
- Pipe the tarball over ssh:
root@source:~# tar czvf - / | ssh root@target "tar -xzv -C targetpartition/ -f -"
. - Preferably umount any data partitions and give them a seperate treatment. Keep in mind the mountpoint (underlying the mounted fs) may have had files.
- Carefully check hardware configuration, bootloader config, fstab and ethernet config (nothing worse than a successful conversion that's unreachable from the internet because eth0 and eth1 are switched arround)
- Make sure tar takes over uid/gid/permissions and extended attributes (if any). Requires root on unpacking, hence the ssh root login in my example.
- It is a lot easier if you have a remote reset and rescue system on the target. If things don't work out at first, you can check the syslog for errors etc.
- Don't do this under time pressure or substance influence ;-)
Solution 2:
I've had a VPS with Linode for many years and have, on a couple of occasions, needed to back up my entire disk image. Linode has some documentation on how to copy your disk image to your local machine via ssh. These instructions are written specifically with linode's infrastructure in mind, but it shouldn't be too difficult to adapt to another provider's setup.