Par Franck OZANO,
mercredi 20 juin 2018.
Lien permanent
Pour réaliser le backup d'une machine LXD, je propose la méthode suivante :
- Arrêt du conteneur foo
- Déplacement dans le dossier /var/lib/lxd/containers/foo
- Archivage avec TAR. Les compressions gzip, bzip2 et xz fonctionnent
- Démarrage du conteneur foo
- Voici un script qui utilise cette méthode de compression.
- N'oubliez pas d'installer le paquet "pxz".
#!/bin/bash
if [ ! -z "$1" ]
then
DIR=`pwd`
RUN=`lxc info $1|grep Running`
EXCLUDE="--exclude='rootfs/dev/*' --exclude='rootfs/proc/*' --exclude='rootfs/sys/*' --exclude='rootfs/tmp/*'"
PXZ=`dpkg-query --status pxz|grep Status|grep ok`
if [ -z "$PXZ" ]
then
echo "Le paquet pxz n'est pas installé"
exit 1
fi
if [ ! -d "/var/lib/lxd/containers/$1" ]
then
echo "Le dossier $1 n'existe pas"
exit 1
fi
if [ ! -z "$RUN" ]
then
echo "Arrêt de la machine $1"
lxc stop $1 --force
sleep 10
fi
cd /var/lib/lxd/containers/$1
tar $EXCLUDE -I 'pxz -3' -cvf $1.txz *
mv *.txz $DIR
cd $DIR
if [ ! -z "$RUN" ]
then
echo "Lancement de la machine $1"
lxc start $1
fi
exit 0
else
echo "Usage : $0 nomMachine"
exit 1
fi