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 {} \;