backup all Zones on SmartOS
#!/bin/bash
# based on http://blog.beulink.org/smartos-migrate-backup-and-restore-kvm-vms/
ALIASES=($(vmadm list -o alias | awk '{if(NR>1)print}'))
UUIDS=($(vmadm list -o uuid | awk '{if(NR>1)print}'))
BACKUP_PATH=/zones/backup
for i in "${!UUIDS[@]}"
do
UUID=${UUIDS[$i]}
ALIAS=${ALIASES[$i]}
LABEL=${ALIAS}_${UUID}
echo "backup ${LABEL}"
vmadm get ${UUID} | json zfs_filesystem disks
mkdir -p $BACKUP_PATH/${LABEL}
vmadm get ${UUID} > $BACKUP_PATH/${LABEL}/${LABEL}.json
vmadm stop ${UUID}
zfs snapshot zones/${UUID}@sending
zfs send -p zones/${UUID}@sending > $BACKUP_PATH/${LABEL}/${LABEL}.zfs
zfs destroy zones/${UUID}@sending
tar -czf $BACKUP_PATH/${LABEL}/${LABEL}.zfs.tar.gz $BACKUP_PATH/${LABEL}/${LABEL}.zfs
openssl dgst -md5 $BACKUP_PATH/${LABEL}/${LABEL}.zfs > $BACKUP_PATH/${LABEL}/${LABEL}.zfs.md5
rm $BACKUP_PATH/${LABEL}/${LABEL}.zfs
done
Written by Philipp Haußleiter
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Smartos
Authors
sawanoboly
1.226K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#