#!/bin/sh # Makes a compressed image of a vps guest system installed on this host. # Gustavo Maluf. July, 2007. Distribute under GPL license terms. # # CONFDIR=/etc/vservers VDIR=/var/lib/vservers # The path begins with /, don't change this behavior! APTARCHIVES=/var/cache/apt/archives if [ $# -lt 1 ] || [ "$1" == "--help" ]; then echo \ "Makes a compressed image of a vps guest system installed on this host. Usage: $0 [destination_path] Available vps are: " # this feature may be implemented with another script lsdirs for i in `ls -l ${CONFDIR} | awk '($1 ~ /^d/) {print $8}'`; do echo " $i"; done echo exit 0 fi NAME="$1" if [ $# -eq 1 ]; then DEST=${PWD}; else DEST=${2}; fi CONFNAME=${NAME}_conf.tar.gz IMGNAME=${NAME}_img.tar.gz # Binaries VSERVER=/usr/sbin/vserver AWK=/usr/bin/awk TAR=/bin/tar FIND=/usr/bin/find if [ ! -d ${CONFDIR}/$NAME ]; then echo "Configuration files for vps $NAME not found" exit 1 fi # Past all verifications, let's change the names set -e echo "Making compressed image of vps $NAME in $DEST, please wait..." $TAR cPzf ${DEST}/$CONFNAME ${CONFDIR}/$NAME $FIND ${VDIR}/${NAME}${APTARCHIVES} -name "*.deb" > /tmp/excludelist $TAR cPzf ${DEST}/$IMGNAME -X /tmp/excludelist ${VDIR}/$NAME/ echo "Two files generated: $CONFNAME, $IMGNAME "