Créer un groupe (Networker)
Aller à la navigation
Aller à la recherche
| Fiche express | |
|---|---|
| Domaine | Procédure d'exploitation |
| Objectif | Automatiser la création (ou suppression) des groupes et du client NetWorker associés à une nouvelle machine |
| Voir aussi | Groupe de sauvegarde (Networker) · Nsradmin · Savegrp |
Ce script shell automatise la création (fonction create) ou la suppression (fonction delete) des groupes de sauvegarde Daily/Weekly/Monthly et de la ressource client NetWorker associée, pour un nouveau serveur à intégrer à la sauvegarde. Il gère deux sites (deux emplacements de nœuds de stockage) et deux cas particuliers : rétentions courtes (« SR ») et sauvegarde de projet (« MEP »).
Script
#!/bin/bash
###################################################################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Created : 01/dec/2012
# version 0.3
###################################################################
RETURN=0
APPNAME=$(basename $0)
debug() {
set -x
}
usage () {
cat<<EOU
---------------------------------------------------------------------
Usage of $APPNAME
---------------------------------------------------------------------
Options non obligatoires :
-h | --help : Affiche cet ecran d'aide
-d | --debug Mode debug
Fonction:
-f | --fonction : Nom de la fonction a utiliser
-c | --client : Nom du client en nom court (pas de fqdn, le nom est genere automatiquement)
-e | --emplacement Emplacement du serveur (site1 - site2)
Options :
-o | --option Les options disponibles sont
-F | --force Permets de forcer l'installation client lors de l'existance de plusieurs entrees DNS sur la meme IP
SR Short retentions
MEP Sauvegarde pour projet
Liste des fonctions :
create Permets la creation d'un client networker
delete Permets la suppression d'un client networker
Examples:
./$APPNAME -f create -c machine_name -e site1
./$APPNAME -f create -c machine_name -e site2
./$APPNAME -f create -c machine_name -e site2 -o SR
./$APPNAME -f create -c machine_name -e site2 -o MEP
./$APPNAME -f delete -c machine_name
./$APPNAME -f delete -c machine_name -o SR
./$APPNAME -f delete -c machine_name -o MEP
---------------------------------------------------------------------
EOU
exit 3
}
if [ $# == 0 ]; then usage ;fi
ARGS=`getopt -o "dhc:e:f:o:f:" -l "debug,help,client:,emplacement:,fonction:,option:,force:" \
-n "getopt.sh" -- "$@"`
if [ $? -ne 0 ]; then exit 1 ;fi
eval set -- "$ARGS"
while true;
do
case "$1" in
-h|--help )
usage
shift ;;
-d|--debug )
debug
shift ;;
-c|--client )
CLIENT_NAME=$2
shift 2 ;;
-e|--emplacement )
LOCALE=$2
shift 2 ;;
-o|--option )
CAS_SPECIAUX=$2
shift 2 ;;
-f|--fonction )
FUNCTION=$2
shift 2 ;;
-F|--force )
FORCE=$2
shift 2 ;;
--)
shift
break;;
esac
done
#################################
## TEST ENTREES DNS
#################################
if [[ -z $FORCE ]]; then
IP=$(host $CLIENT_NAME | awk {'print $4'})
DNS=$(host -a $IP | grep corp | wc -l)
echo $DNS
if [[ $DNS -gt 1 ]];then
echo "Il existe plusieurs entrees DNS sur cette IP: $IP. Veuillez supprimer l'ancienne IP avant la creation ou utiliser l'option --force"
exit 1
fi
fi
##################################
## LISTES DES FONCTIONS
##################################
function get_create() {
MEP=0
if [[ $CAS_SPECIAUX = SR ]];then
SR="SR_"
elif [[ $CAS_SPECIAUX = MEP ]];then
MEP=1
else
echo "pas de MEP, pas de SR"
fi
GROUP=$(echo $CLIENT_NAME | sed 's/^./\U&/')
CLIENT=$(nslookup $CLIENT_NAME | grep Name | awk '{print $2}')
RANDOM_HOURLY=$(echo `< /dev/urandom tr -dc 0-7 | head -c1`)
Start_time=$(echo "${RANDOM_HOURLY}\:00")
export LANG=fr_FR.UTF8
JOUR=$(date +"%A" | tr '[:lower:]' '[:upper:]')
DATE=`date +%d/%m/%Y\ %H:%M:%S`
if [[ $LOCALE = site1 ]] ;then
Storage_nodes=node1,node2
elif [[ $LOCALE = site2 ]] ;then
Storage_nodes=node1,node2
else
echo "le lieu doit etre mentionne (site1 ou site2)."
fi
echo -e "\ncreation des groupes en cours ... $GROUP\n"
if [[ $MEP -eq 1 ]] ; then
(echo "create type: NSR group;name: MEP${GROUP}" ; echo "y";) | nsradmin | grep failed
else
(echo "create type: NSR group;name: ${GROUP}Daily;Autostart:Enabled;Start time:$Start_time;Schedule:AUTOSTART_${SR}DAILY_${JOUR}_FULL"; echo "y";) | /usr/sbin/nsradmin | grep failed
(echo "create type: NSR group;name: ${GROUP}Weekly;Autostart:Enabled;Start time:$Start_time;Schedule:AUTOSTART_${SR}WEEKLY_${JOUR}_FULL"; echo "y";) | nsradmin | grep failed
(echo "create type: NSR group;name: ${GROUP}Monthly;Autostart:Enabled;Start time:$Start_time;Schedule:AUTOSTART_${SR}MONTHLY_${JOUR}_FULL"; echo "y";) | nsradmin | grep failed
fi
echo -e "\ncreation des clients en cours ...$CLIENT\n"
if [[ $MEP -eq 1 ]] ; then
(echo "create type: NSR client;Storage nodes:$Storage_nodes;name: ${CLIENT};Browse policy:POLBROWSEMEP;Retention policy:POLRETMEP;Schedule:SCHEDMEP;Group:${GROUP};Save set:/tmp;Comment:Groupe uniquement MEP"; echo "y") | nsradmin | grep failed
else
(echo "create type: NSR client;Storage nodes:$Storage_nodes;name: $CLIENT;Browse policy:POLBROWSEDAILY;Retention policy:POLRETDAILY;Schedule:SCHEDDAILY;Directive:Unix with compression directives;Group:${GROUP}Daily,Indexdaily"; echo "y";) | nsradmin | grep failed
(echo "create type: NSR client;Storage nodes:$Storage_nodes;name: $CLIENT;Browse policy:POLBROWSEWEEKLY;Retention policy:POLRETWEEKLY;Schedule:SCHEDWEEKLY;Directive:Unix with compression directives;Group:${GROUP}Weekly"; echo "y";) | nsradmin | grep failed
(echo "create type: NSR client;Storage nodes:$Storage_nodes;name: $CLIENT;Browse policy:POLBROWSEMONTHLY;Retention policy:POLRETMONTHLY;Schedule:SCHEDMONTHLY;Directive:Unix with compression directives;Group:${GROUP}Monthly"; echo "y";) | nsradmin | grep failed
fi
echo -e "\nInitialisation du reporting\n"
REP=/home1/logs2/log_group_recap
FIC_DAILY=${REP}/Daily/${GROUP}Daily.txt
FIC_WEEKLY=${REP}/Weekly/${GROUP}Weekly.txt
FIC_MONTHLY=$REP/Monthly/${GROUP}Monthly.txt
FIC_ALL_DAILY=${REP}/All/${GROUP}Daily.txt
FIC_ALL_WEEKLY=${REP}/All/${GROUP}Weekly.txt
FIC_ALL_MONTHLY=${REP}/All/${GROUP}Monthly.txt
for LOGFILE in $FIC_DAILY $FIC_WEEKLY $FIC_MONTHLY $FIC_ALL_DAILY $FIC_ALL_WEEKLY $FIC_ALL_MONTHLY
do
if [[ -f $LOGFILE ]];then
echo -e "\tle fichier $LOGFILE existe"
else
echo "le fichier $LOGFILE a ete cree" > $LOGFILE
fi
done
echo "$DATE Linux $GROUP $CLIENT " >> /home1/lmscripts/create/histo_create.txt
echo "termine avec succes"
echo "Voulez vous lancer la sauvegarde weekly pour initier la premiere full ? (Y / N)"
read LANCE_BACKUP
if [[ $LANCE_BACKUP = "Y" ]] ; then
savegrp -l full -G ${GROUP}Weekly -v &
else
echo "La sauvegarde n'a pas ete lancee ..."
fi
exit 0
}
get_delete() {
MEP=0
if [[ $CAS_SPECIAUX = SR ]];then
SR="SR_"
elif [[ $CAS_SPECIAUX = MEP ]];then
MEP=1
else
echo "pas de MEP, pas de SR"
fi
GROUP=$(echo $CLIENT_NAME | sed 's/^./\U&/')
for GROUP_NAME in ${GROUP}Daily
do
if [[ $GROUP_NAME == ${GROUP}Daily ]] ; then POOL_NAME=POOLDAILY4 ;
elif [[ $GROUP_NAME == ${GROUP}Weekly ]] ; then POOL_NAME=POOLWEEKLY4 ;
elif [[ $GROUP_NAME == ${GROUP}Monthly ]] ; then POOL_NAME=POOLMONTHLY4 ;
else echo "Probleme dans le nom du groupe"; exit; fi
VAR=$( (echo "print type :nsr POOL; name :${POOL_NAME}") | nsradmin | grep ly | sed 's/groups://' )
echo $VAR
GROUP_LIST=$(echo $VAR | sed -n 's/'", $GROUP_NAME"'//p')
echo $GROUP_LIST
nsradmin -i - <<EOF
. type NSR POOL , name :$POOL_NAME
update groups: $GROUP_LIST
EOF
done
}
##########################################################
# lancement de la fonction via le parametre -f
##########################################################
case $FUNCTION in
create ) get_create ;;
delete ) get_delete ;;
esac
Notes
- Les noms de sites d'origine (deux emplacements géographiques réels) ont été remplacés par les placeholders génériques
site1/site2. - Un commentaire du script mentionnait le prénom d'une personne réelle en tant que responsable du reporting ; il a été remplacé par une formulation générique.
- La coquille
-e|--emplcementde la version source (qui empêchait l'option longue--emplacementde fonctionner correctement) a été corrigée en-e|--emplacement. - La fonction
get_deletede la version source contenait plusieursexitde mise au point intermédiaires qui interrompaient le script avant la mise à jour effective du pool ; ils ont été retirés pour ne conserver que la logique fonctionnelle, mais cette portion reste à valider avant réutilisation en production.
Voir aussi
- Groupe de sauvegarde (Networker) — concept de groupe et ses attributs
- Nsradmin — syntaxe des commandes
create type: NSR group/NSR client - Savegrp — lancement de la première sauvegarde du groupe créé