Skip to content

Instantly share code, notes, and snippets.

@joker-x
Last active December 20, 2017 11:50
Show Gist options
  • Save joker-x/8f1ca9964404476c1c25465a2ff315db to your computer and use it in GitHub Desktop.
Save joker-x/8f1ca9964404476c1c25465a2ff315db to your computer and use it in GitHub Desktop.
Genera un tar.gz con el contenedor lxc listo para archivar o migrar. Recibe el nombre del contenedor como primer parámetro.
#!/bin/bash
DIR_BACKUP="/var/backups"
[[ "$1" == "" ]] && echo "Error en el número de argumentos" && exit 1
[[ -z $(lxc-ls | grep -w $1) ]] && echo "No existe el contenedor $1" && exit 1
[[ -z $(whereis pigz | tr -d 'pigz:') ]] && echo "Error: pigz no instalado" && exit 1
#echo "Existe el contenedor $1"
CONTENEDOR=$1
echo "Parando contenedor $CONTENEDOR"
time lxc-stop -n $CONTENEDOR
echo "Generando ${DIR_BACKUP}/${CONTENEDOR}.tar.gz"
cd /var/lib/lxc/$CONTENEDOR
time ionice -c2 -n7 nice -n19 tar --numeric-owner -I pigz -cf "${DIR_BACKUP}/${CONTENEDOR}.tar.gz" ./*
chmod 600 "${DIR_BACKUP}/${CONTENEDOR}.tar.gz"
echo "Arrancando contenedor $CONTENEDOR"
time lxc-start -d -n $CONTENEDOR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment