Backup all virtual machines on a SmartOS hypervisor with

This post will explain how to create a cronjob to backup of every virtual machine on a SmartOS hypervisor.

Create the following bash script in /opt/


# Backup all virtual machines on a SmartOS hypervisor
# Author:
# Website:

# Backup directory without trailing slash

# temp dir where we ZFS send and gzip before moving to backupdir  

svcadm enable autofs

for VM in `vmadm list -p -o alias,uuid`
    # create an array called VM_PARTS splitting on ':'
    IFS=':' VM_PARTS=($VM)

    # create some helper varibles for alias and uuid

    # echo "Backup started for $VM"
    vmadm send $uuid > $tmpdir/$alias

    # echo "Starting $VM"
    vmadm start $uuid

    gzip $tmpdir/$alias
    mv $tmpdir/$alias.gz $backupdir/$alias.gz


Create a cronjob entry to schedule the backups:

crontab -e
2 15 * * * /usr/bin/bash /opt/

If I expand on this script much more, I plan to stick it into revision control.

If you look closely, I have also added a hack to enable autofs (svcadm enable autofs) which lets me automount an NFS share on my remote FreeNAS by setting backupdir=/net/[ip-or-fqdn-of-freenas]/mnt/zfs-mirror/backup/vms.

We have scheduled a backup of each virtual machine on your SmartOS hypervisor!

If or when the time comes to restore a VM from a backup, use the following:

vmadm receive -f /path/to/backup-file
Just make sure the VM doesn’t currently exist on the hypervisor.

This strategy is great for complete backups of machines which could be used during a manual migration, or if corruption happened to the VM and we wanted to restore to a previous version.

4 thoughts on “Backup all virtual machines on a SmartOS hypervisor with

  1. Hey,
    Are you still using this script for backing up Smartos VM’s? Did you ever update it or add it to VCS?


  2. Hey, I built a script that does something similar.
    However, my script also has flags for either storing the vm locally, or storing it remotely via scp or ftp.

Leave a Reply

Your email address will not be published. Required fields are marked *