Linux – How to download a complete image of the DO VPS to an image for a VM over SSH

debianlinuxsshvps

There isn't a way to download a complete image from Digital Ocean VPS hosting through their web UI. How can I download an entire image of the VPS that I can use locally on a VM or upload to another VPS later on? Can this be done via SSH or SFTP? Im running Debian 6.

Best Answer

You can use rsync to essentially clone the whole system via SSH while running.

You create the local VM with the specs you need, install a minimal debian (same version) with the same partitioning schema as your VPS and then boot into a live CD (ubuntu-desktop has pretty much anything you will need).

Then from the live CD you mount the partition(s) to a temporary location (eg: /mnt) and then you run something like this to clone the whole VPS to your local VM keeping all permissions intact.

rsync -aAXv --progress --stats --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} root@YOUR_VPS_IP:/* /mnt/

Make sure to exclude paths that you don't need to clone. The above paths are standard paths that need to be excluded for a successful rsync.

Depending on the virtualization platform the current VPS runs on you might need to fix some paths or files (eg: Partitions' UUIDs on /etc/fstab and/or GRUB config).

You may also need to (re)install the boot loader.

And of course you will need to update the network information so that the newly cloned VM is accessible over the network.