L2 Cache

Behold the power of |!

User Tools

Site Tools


Sidebar

snipets:solaris:backup-ipkg-zone

Backup an IPKG zone

This is a very basic script I've written to backup the zone's configuration and a dump of the zfs filesystem.

zonebackup.sh

#!/bin/sh

ZONE=$1
ZONE_DS=main/vms/zones
BCK_PATH=/main/shares/documents/Backups/Gravity/zones

# check zone
if [ -e /etc/zones/${ZONE}.xml ]; then
        zlogin -S ${ZONE} 'shutdown -i5 -g0 -y' 2>1 > /dev/null
        COUNTER=120
        while [ ${COUNTER} -gt 0 ]; do
                let COUNTER=COUNTER-1
                sleep 1
                if [ "`zoneadm list | grep ${ZONE}`" != "${ZONE}" ]; then
                        break
                fi
        done
        if [ ${COUNTER} == 0 ]; then
                echo "Zone named ${ZONE} did not shutdown withing 120 seconds. Aborted!"
                exit 1
        else
                # backup zone
                SNP=`date +%Y%m%d_%H%M%S-zfsbck`                
                zfs snapshot -r ${ZONE_DS}/${ZONE}@${SNP}
                zfs send -R ${ZONE_DS}/${ZONE}@${SNP} | bzip2 > ${BCK_PATH}/${ZONE}_${SNP}.zfsimg
                cp /etc/zones/${ZONE}.xml ${BCK_PATH}/${ZONE}_${SNP}.xml
                zfs destroy -R ${ZONE_DS}/${ZONE}@${SNP}
                exit 0
        fi
fi

echo "No zone named ${ZONE}!"
exit 1
snipets/solaris/backup-ipkg-zone.txt · Last modified: 2014/10/09 22:02 (external edit)