Linode.com provides a great service but it was time to retire an old node. After archiving all the data using rsync, I decided that I wanted to make a copy of the disk over ssh so I could mount it locally or re-upload it if I ever needed to restore. This process was really overkill for my application but I wanted an extra back up after last months event.
Step 1. I resized the disk image to make it smaller and get rid of the unneeded free space.
Step 2. I rebooted the Linode in ‘restore’ mode which basically loads a small instance of Finnix (Debian based – really tiny distro). You can use apt-get to install packages to Finnix but your space is limited. On Linode, ssh is not running and root does not have a password, so you will have to use the following commands through the console to get you up and running.
passwd #sets the root password /etc/init.d/ssh start
Step 3. Now you should be able to go over to your local machine and start the command to copy.
ssh -C [email protected] "dd if=/dev/xvda " | dd of=/home/whereyourwantit/linode.img
What this does is it creates a ssh connection with compression enabled to start sending your hard drive over to the local computer. Depending on the size of the drive, this could talk a little while.
One important note – in your .know_host file you might already have a key associated with the the ip/domain combination. You will need to delete that out of ~/.ssh/.known_hosts before being able to proceed.
Step 4. Wow you have your image and you are probably on a mac. Fantastic – since the filesystems are different. But no stress, load up your virtual box, mount your shared folder (if you can get guest additions to not be a pain) and then mount your image as the link linode suggests.
mkdir linode # creating the mount point mount -o loop linode.img linode ### Once it is mounted you should be able to traverse it like a normal file system. ls linode/ #exposes it all
Tomorrow I will try to upload the img back to Linode. Help me compile linux tips.
Update: Uploading the image back to Linode was a success
This process would be different if you were using a non-Linode image or you were trying to make the image work in a different virtual environment.
I started by creating a fresh Linode instance and then I created 2 disks (one for image and one for swap) after picking the datacenter.
Next, I created a new configuration profile. I set xvda to my primary disc and xvdb to my swap.
Now I start the Linode in recovery mode and basically repeat the steps above including setting the password and starting ssh in Finnix.
To copy the image to Linode:
dd if=/directoryto/linode.img | ssh -C [email protected] "dd of=/dev/xvda"
Then I reboot and I have a cloned version of the Linode I deleted yesterday up and running.
***Again disclaimer – this is probably not the best/most efficient way to back up your server.
Comments
I suppose while downloading the image to your local computer, piping the dd to gzip could save on bandwidth and time?
You bring up a good point. I would be interested to see the difference in transfer size with ssh compression, gzip/bzip2 compression, and the combination of both ssh and gzip or bzip2 encryption.
Hey, can you help us restore our img to linode. We have been at it for few days but no dice. It somehow just fails.
I am glad I was able to help get the vdi transferred and working but I am sorry Linode turned out to not be a good solution for your custom kernel. In a few days, I will type up what I did to get it running.
There are lots of classic tricks to speed this up.
ssh [email protected] “dd if=/dev/xvda | bzip2 | dd bs=1M” | dd of=/home/whereyourwantit/linode.img.bz2
Let the remote idle server do better-than-ssh compression. You could even opt to use xz instead of bzip2. The extra dd creates a buffer between the stream and the network pipe. I also like to use ‘pv’ in there to get some throughput stats, but that is just bling.
This processes could take a long time if you don’t have good bandwidth – in that case don’t trust your laptop not to got to sleep on you.