Mac OSX Terminal – Parallels VM Backup / Restore

| | | | |

If you use Parallels like I do sometimes you need to test things and recover from that test rather quickly.

My process is to first build the base/template VM the way I want it and then back it up before testing things. In intervals if I’m going to continue to use the VM I will create additional backups.

#!/bin/sh

#  Parallels-VMManagement.sh
#
#
#  Created by David Kittell on 6/28/19.
#

# Variables - Start
txtBold=`tput bold`
txtRed=`tput setaf 1` # Errors
txtGreen=`tput setaf 2` # Info
txtBlue=`tput setaf 4` # Question
txtU1=`tput smul`
txtU2=`tput rmul`
txtReset=`tput sgr0`
# tput examples: https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
cwd=$(pwd)
# Variables - Stop

echo "${txtBold}${txtBlue}Do you want to backup or restore a VM?, type b or r followed by [ENTER]?${txtReset}"
read br
case $br in
  [bB])
    ls ~/Parallels | grep -v Archive
    # mkdir -p ~/Parallels/Archive
    echo "${txtBold}${txtBlue}What VM do you want to backup?, type or copy/paste the VM name followed by [ENTER]?${txtReset}"
    read backup_VM
    cd ~/Parallels/
    tar -cvzf "Archive/$(echo $backup_VM)_`date +%Y_%m_%d_%H.%M.%S`.tar.gz" $backup_VM && say "VM Archived"
    cd $cwd
    ;;
  [rR])
    ls ~/Parallels/Archive | grep '.tar.gz'
    # mkdir -p ~/Parallels/Archive
    echo "${txtBold}${txtBlue}What VM do you want to backup?, type or copy/paste the VM name followed by [ENTER]?${txtReset}"
    read restore_VM
    cd ~/Parallels/
    tar -xvzf "Archive/$(echo $restore_VM)" -C ~/Parallels/ && say "VM Restored"
    cd $cwd
    # tar -zxf
    ;;
esac
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.