From e2b29a5de8e96f642bb5d5a2d2662e452721d21b Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Sun, 31 Jul 2022 09:57:59 +0200 Subject: [PATCH] =?UTF-8?q?[EVO]=20G=C3=A9rer=20un=20nom=20d'h=C3=B4te=20d?= =?UTF-8?q?iff=C3=A9rent=20du=20nom=20de=20noeud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup/run.bash | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/backup/run.bash b/backup/run.bash index ec7c6ca..4e98b0d 100755 --- a/backup/run.bash +++ b/backup/run.bash @@ -2,7 +2,7 @@ #################################################################################### ## VARIABLES # Activer ou non le mode debug (message) -DEBUG=0 +DEBUG=1 # Extraire le chemin où est stocké le script basePath=$(dirname $0) @@ -39,8 +39,20 @@ host=( "/etc/wireguard/wg0.conf" ) -# Liste des conteneurs à savegarder -[[ -x "/snap/bin/lxd" ]] && containers=$(/snap/bin/lxc list --columns "nsL" --format csv | grep "$(hostname)" | awk -F ',' '{print $1}') +# SI la commande est lxd est disponible +if [[ -x "/snap/bin/lxd" ]]; then + # Liste des conteneurs à savegarder + containers=$(/snap/bin/lxc list --columns "nsL" --format csv | grep "$(hostname)" | awk -F ',' '{print $1}') + + # SI la liste est vide, tenter avec le nodename + if [[ -z "${containers}" ]]; then + # Récupérer le nom du noeud lxc + nodename=$(/snap/bin/lxc info | grep "server_name" | awk -F':' '{print $NF}' | sed 's# ##g') + + # Récupérer la liste des conteneurs + containers=$(/snap/bin/lxc list --columns "nsL" --format csv | grep "${nodename}" | awk -F ',' '{print $1}') + fi +fi # Récupérer la liste des conteneurs à ne pas sauvegarder exclude=""; [[ -f $excludesPath ]] && [[ -z "$(cat $excludesPath)" ]] && readarray exclude < "${excludesPath}" @@ -133,7 +145,7 @@ if [[ "$(/bin/ls ${containersPath})" ]]; then done # Créer le fichier de lock - hostname | tee "${containersPath}/${scriptName}.lock" + hostname | tee "${containersPath}/${scriptName}.lock" > /dev/null # Appliquer la rétention [[ "$(/bin/ls ${containersPath})" ]] && find ${containersPath}/* ! -path "*kept*" -mtime "+${retentionPolicy}" -exec rm {} \;