Skip to content

Instantly share code, notes, and snippets.

@StephenFriend
Created August 25, 2014 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenFriend/69477732bbb1423942f4 to your computer and use it in GitHub Desktop.
Save StephenFriend/69477732bbb1423942f4 to your computer and use it in GitHub Desktop.
Shell script to clone a Parallels VM
#! /bin/bash
# This script is used to back up/clone a Parallels VM on a laptop running
# OSX. Cloned VMs are named by the format <identifier>YYYYMMDD e.g
# w8_20140701 might be Windows 8 clone.
# Check that power is attached. If there's only one line, then power isn't on.
adapter_details_line_count=$(pmset -g adapter | wc -l)
if [ $adapter_details_line_count -eq 1 ] ; then
exit 0
fi
vm_to_be_cloned="Windows 8.1"
backup_path="/Volumes/path/to/your/location"
clonePrefix="w8_"
# use the date to create the name of the cloned item
date_portion=$(date "+%Y%m%d")
new_vm_name=$clonePrevix$date_portion
# check that the VM isn't running
vm_status=$(prlctl list name "$vm_to_be_cloned" --no-header --output status)
if [[ $vm_status == *stopped* ]]; then
# see if the drive is attached
if [ -d $backup_path ]; then
# make sure that a clone hasn't been done for the day
if [ ! -d "$backup_path/$new_vm_name.pvm" ]; then
prlctl clone "$vm_to_be_cloned" --name $new_vm_name --dst $backup_path
# unregister the new vm from Parallels (because you aren't going to be using it, and it mostly won't be available)
prlctl unregister $new_vm_name
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment