Last active
December 20, 2017 11:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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