Every once in a while, we have to build a server. You’ve spent the time installing and configuring everything and you want a snapshot for Posterity’s sake. Here’s how to do it quickly. This little command will simply take a snapshot of everything of importance and for the most part allow you to restore your server from a fresh install (binaries, libs, and all) in a few minutes.
I do this for every one of my servers. Especially my EC2 Instance Backed servers.
I keep an EBS volume around that I mount as /mnt for hot attaching to any server and doing the restore. So basically, Just hot attach the EBS volume and just untar it. Restart all the services and you’re done. Keep in mind that if you’re running services, they should be shut down prior to issuing this command.
The beauty of this is it allows you to keep things separate. (Applications, Binaries, and Data)
I exclude any data as that is backed up to S3 on a regular schedule, but the configs, binaries, libraries are all preserved using this method.
The magic tool? Tar.
I issue the following command:
tar czvf /mnt/total/restore.tgz --exclude "/proc" --exclude "/sys" --exclude "/net" --exclude "/root/Archives.tar" --exclude "/usr/src/backup" --exclude "/media" --exclude "/home/backup" --exclude "/mnt" --exclude "/dev" --exclude "/home/vmail" /
It’s pretty self explanatory. I’m pretty much tarring up everything except for anything that would cause problems like /proc /sys /net and certain data directories.
Simple tip, but great solution to a really quick restore of an Amazon Instance Backed linux box or even any linux box.