#!/bin/bash set -e usage="lxc-pack CONTAINER" if [ -z "$1" ]; then echo $usage exit 8 fi container=$1 stopped=0 cd /var/lib/lxc if [ ! -e $container ]; then echo "container $container not existing" exit 16 fi # check if container is running if [[ $(lxc-info -s $container) =~ "RUNNING" ]]; then echo "Container $container still running. Stop it (Y/n)" read answ if [ "$ans" == "n" ]; then echo "..aborted" exit 24 fi echo "..stopping $container" lxc-stop $container stopped=1 fi # pack it into /tmp echo "..packing $container" tar czf /tmp/$container.tgz $container echo "..packed into /tmp/$container.tgz" # restart container? if [ $stopped -eq 1 ]; then lxc-start $container echo "..$container started again" fi