This shows you the differences between two versions of the page.
computing:storage:xen_backup.sh [2011/11/27 11:37] gcooper created |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== xen_backup.sh ====== | ||
- | |||
- | < | ||
- | #!/bin/bash | ||
- | # xen_backup.sh by Gene Cooper (gcooper@sonoracomm.com) | ||
- | # | ||
- | # This script provides a fairly quick and clean method for backing up an OSS | ||
- | # Xen server. | ||
- | # | ||
- | # I searched for a tool to do this, but I couldn' | ||
- | # | ||
- | # I use this script as a pre-exec script for my regular backup system. | ||
- | # there is downtime during the backup and amount of it will depend on the speed of your | ||
- | # hardware. | ||
- | # into LVM snapshots. | ||
- | # | ||
- | # The logic of this script is simple and it is designed to minimize downtime. | ||
- | # It will determine the running Xen domains and then, one at a time, it will suspend each | ||
- | # domain, save (checkpoint) the running state, create a compressed copy of the disk image | ||
- | # file then resume the domain. | ||
- | # | ||
- | # IMPORTANT NOTE: This version of the script depends on sufficient free disk space to save | ||
- | # the gzip'd disk image files and the checkpoint (memory state) files! | ||
- | |||
- | # The checkpoint files appear to be memory snapshots of the running domains and are the | ||
- | # size of the allocated memory. | ||
- | # | ||
- | # Your main backup should probably back up the /etc/xen directory, the compressed Xen disk | ||
- | # image files as well as the checkpoint files ($dest as set below). | ||
- | # | ||
- | # Restoring a domain from backup would mainly involve restoring the xen config files | ||
- | # from /etc/xen, restoring/ | ||
- | # original locations then running a command like: | ||
- | # | ||
- | # xm restore / | ||
- | # | ||
- | |||
- | # Log file | ||
- | log=/ | ||
- | |||
- | # Temp directory for checkpoint files | ||
- | dest=/ | ||
- | |||
- | # Xen configuration files location | ||
- | xenconfig=/ | ||
- | |||
- | # Xen domains (VMs) to be backed up | ||
- | # | ||
- | alldomains=( ISPConfig appserv mgmt ) | ||
- | |||
- | # Delete old backups - Assume they were backed up to tape or disk and are no longer needed | ||
- | # This may help keep your backups smaller by avoiding duplicate backups. | ||
- | delold=yes | ||
- | |||
- | ############## | ||
- | |||
- | # Create temp dir if not exist | ||
- | if [ ! -d ${dest} ] | ||
- | then | ||
- | echo "Temp directory for checkpoint files doesn' | ||
- | echo "" | ||
- | / | ||
- | fi | ||
- | |||
- | # Subroutine Definitions | ||
- | |||
- | delete-old() | ||
- | # Here we delete all old backups, if that is desirable. | ||
- | # This may help keep our tape backups smaller. | ||
- | { if [ " | ||
- | rm -f $dest/* | ||
- | fi | ||
- | } | ||
- | |||
- | pre-backup() | ||
- | { | ||
- | echo "" | ||
- | / | ||
- | echo " | ||
- | if [ -f $dest/ | ||
- | echo " | ||
- | rm -f $dest/ | ||
- | fi | ||
- | echo " | ||
- | / | ||
- | / | ||
- | } | ||
- | |||
- | compress-image() | ||
- | { | ||
- | echo "" | ||
- | / | ||
- | # Now we create a compressed copy of the VM (.img file) ready to be backed up | ||
- | # by the primary backup system. | ||
- | # to extract the .img filename from the xen config file, but it works on my domains. | ||
- | imgfile=`cat $xenconfig/ | ||
- | echo " | ||
- | gzip -c $imgfile > $dest/ | ||
- | / | ||
- | } | ||
- | |||
- | post-backup() | ||
- | { | ||
- | echo "" | ||
- | / | ||
- | echo " | ||
- | / | ||
- | / | ||
- | } | ||
- | |||
- | # Processing begins | ||
- | delete-old | ||
- | |||
- | # Here we checkpoint only the currently running domains. | ||
- | for runningdomain in `xm list|grep -v Name|grep -v Domain-0|cut -f1 -d" "`; do | ||
- | | ||
- | | ||
- | done | ||
- | |||
- | # Here we back up all specified domains, not just running VMs. | ||
- | for domain in ${alldomains[@]}; | ||
- | | ||
- | done | ||
- | |||
- | # Just closing out the log... | ||
- | echo "" | ||
- | echo " | ||
- | /bin/date >> $log | ||
- | |||
- | exit | ||
- | </ | ||