Blog

Parallels Server for Mac – Roll your own snapshots with prlctl

By Iain Morris posted on January 26th, 2009

The 8-core Xserve platform has often seemed overpriced and overkill for many IT server applications that require less performance, but must have server isolation for industry compliance, security, and high availability.  Parallels has made a welcome step forward in virtualization on the Xserve platform, with Parallels Server for Mac.  For an initial release, it has proven quite dependable despite a few issues with recent X Server updates.  No doubt this product will continue to improve in the near future, and it’s exciting to see the Xserve hardware used more efficiently.

One feature missing from the initial Server release is the ability to perform VM snapshots of both disk and memory within the admin application. There’s no easy way to schedule jobs out for automation in a backup strategy.  Parallels Desktop 4 has this functionality, but it has yet to show up in the Server product. One solution is to roll your own snapshot system using the command line tool /usr/bin/prlctl and a bit of scripting.  A few people out there have started making their own backup systems using prlctl, and here is only one example of what you can do with this tool.

I’ve attached a basic perl script that calls the prlctl tool to get a list of all active VMs, suspend each VM (which dumps a copy of memory to the disk to resume), copy the full VM to a new location of your choosing and optionally compress, date-stamp, and archive, and finally resume the VM after copy.

I’ve added a flag in the script to compress the image into a date-stamped archive if I choose to, though this adds some time to the copy and subsequent restoration of the archive.  I have found it saves a considerable amount of disk space, which could make a difference for your backup times to a network volume or tape.  The entire process leaves the VM suspended for under 10 minutes on my storage systems.  You will need to decide for yourself what is considered acceptable downtime to get the snapshot. The archives are obviously quite large, so it may be best to do the wholesale VM copy in your weeklies, while getting client VM system-level copies daily. These are big files! However, if you forgo compression, you can be up and running on new hardware literally within seconds, with an identical point-in-time of your virtual host.

This particular script uses ditto to archive as a .cpz and make the transfer, but rsync or a gzipped tar setup would work just as well.

I’m sure there are some tricks to be made with your company’s backup solution to get incrementals of the full copy over time, but that can be left as an (easy) exercise for the reader, as every environment has its own circumstances. Time Machine increments come to mind as a cool option.

Once you have your script dialed in, throw it into your crontab, or better yet, build a launch daemon plist file for it and load it in with launchctl (interestingly, cron is considered depreciated in Mac OS X these days). All backups should be automated, even if they only run once a week or month.

Here’s an example of com.yourcompany.vmsnapshot.plist, which should execute your backup at 9pm nightly (the script will need to be executable):

bash-3.2# cat com.yourcompany.vmbackup.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Disabled</key>
        <false/>
        <key>Label</key>
        <string>com.yourcompany.vmbackup</string>
        <key>ProgramArguments</key>
        <array>
                <string>/private/var/root/bin/vm_backup.pl</string>
        </array>
        <key>KeepAlive</key>
        <false/>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Hour</key>
                <integer>21</integer>
                <key>Minute</key>
                <integer>0</integer>
        </dict>
</dict>
</plist>

Copy this file to your /Library/LaunchDaemons directory, and launchctl load com.yourcompany.vmbackup.plist.  Do a quick confirmation with launchctl list | grep vmbackup, and you should be good to go.

Feel free to adapt and expand as you need, but please remember this is just a suggestion, not a released backup product!  The utility prlctl provides error codes, so some basic error checking would be a good addition here.  We would love to see this expanded and improved, so post back with any additions or changes!  Happy virtualizing.

vm_backup.pl

Posted in Mac OS X Server, Scripts, System Administration, Tips and Tricks

Comments are closed.