1
0

[EVO] Gérer un nom d'hôte différent du nom de noeud

This commit is contained in:
pulsar89.5 2022-07-31 09:57:59 +02:00
parent 42b9842b8e
commit e2b29a5de8

View File

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