Friday, February 28, 2014

VM snapshots and why you should use them.




I've been playing with snapshots inside VMware Fusion (the Mac version of VMware Workstation) and I gotta say, this is one of the greatest tool to have. You can read up on countless articles and blog post of how cool it is. There are many reasons why you should use it. As many of the best practices suggest, it is not a substitute for backups or restore point.

Having said that, I use them for testing and quickly provisioning. This morning, I was playing with building a quick and dirty LEMP (PHP NGINX MySQL) stack from a bare clean Cent OS 6.5 build.

My default VM is about 900 MB and I can easily back that up pretty quick. Screw up? Easy, pull out the clean virgin image and start over. However, with snapshots, you can do side-by-side comparisons that is pretty invaluable. I've used snapshots before but not on a regular basis because export and migrating VMs with snapshots tend to be a hassle. Now, I run multiple snapshots and once my automation scripts all work fine and dandy, I dump the snapshot VM and finalize my build off a clean slate back-up.




After starting with a clean, virgin build, I built my list of what I needed to install into a BASH script. The script sets repositories, launches services, set IPtables, copy configuration files, and modifies /etc/ files. For example, with NGNIX, you have to make sure you change user/groups from apache to nginx, define the worker process, etc. So I did this all manually to see if I had any typos as I normally did.  My script also does things like set CRON jobs, copies SSH keys, and modifies SSH daemon logins for keys only. The point was to make it completely automated with only a few clicks and password entries. This would something analogous to installing a pre-built VM appliance but defined for my use case.

Then I reverted back to my clean slate snapshot. Launched the VM and ran my installation script. It ran flawlessly. I had a whole LEMP build running in 2 minutes with all my settings I needed.






So in short, snapshots are pretty awesome. Again, this is good for quick provisioning testing and comparing if a service update breaks anything. I can see it for those uses.

No comments:

Post a Comment