| 1 | #!/bin/sh
|
|---|
| 2 | #######################################################################################################################
|
|---|
| 3 | #
|
|---|
| 4 | # DESCRIPTION : LNX - Script de sauvegarde Mondorescue automatique
|
|---|
| 5 | #
|
|---|
| 6 | # OPTIONS DE LANCEMENT
|
|---|
| 7 | # arguments :
|
|---|
| 8 | # -dir /my/dir;/other/dir -- le dossier que l'on veut purger (obligatoire)
|
|---|
| 9 | # -recursive y -- recherche dans les sous-répertoire (par défaut: n)
|
|---|
| 10 | # -filetype all -- le(s) type(s) de fichier à purger, séparé par des ":" (par défaut: all)
|
|---|
| 11 | # -retention 180 -- au delà de combien de jours on liste (par défaut: 365)
|
|---|
| 12 | # -remove y -- lancer un rm sur la liste de fichiers (par défaut: n)
|
|---|
| 13 | # -log /tmp/testing -- log des opérations (par défaut: /root/admin/log)
|
|---|
| 14 | #
|
|---|
| 15 | # EXEMPLE : $0 -dir /my/dir:/other/dir -recursive y -filetype .tmp:.dmp.gz:.dmp -retention 180 -rm y -log /tmp/mylog.log
|
|---|
| 16 | #
|
|---|
| 17 | # LOG : /tmp/lnx_historique_purge.log (par défaut)
|
|---|
| 18 | #
|
|---|
| 19 | # MODIFICATIONS :
|
|---|
| 20 | # 2009/12 : v1 : Creation - Camille Bouly
|
|---|
| 21 | # 2010/04/07 : v1.1 : Modifications - BLE
|
|---|
| 22 | # Renommage du script
|
|---|
| 23 | # Correction des erreurs
|
|---|
| 24 | # Ajout usage
|
|---|
| 25 | #
|
|---|
| 26 | #######################################################################################################################
|
|---|
| 27 |
|
|---|
| 28 | #***************************************************************************
|
|---|
| 29 | # Variables FOR VTOM
|
|---|
| 30 | #***************************************************************************
|
|---|
| 31 |
|
|---|
| 32 | . ~/.bash_profile
|
|---|
| 33 |
|
|---|
| 34 | VERSION="1.1"
|
|---|
| 35 | ECHO_VERSION="## LNX - Script de sauvegarde Mondorescue automatique -- Version $VERSION"
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | SYNTAX="
|
|---|
| 39 | $ECHO_VERSION
|
|---|
| 40 |
|
|---|
| 41 | USAGE : $0 [ options ]
|
|---|
| 42 |
|
|---|
| 43 | -serv : Nom du serveur ou reside le partage NFS
|
|---|
| 44 |
|
|---|
| 45 | -e : Filesystem ou directory que l'on veut exclure de la sauvegarde
|
|---|
| 46 |
|
|---|
| 47 | -m [i][n] : Choix du Mode - soit i pour le mode ISO soit n pour le mode NFS
|
|---|
| 48 |
|
|---|
| 49 | Exemple :
|
|---|
| 50 | $0 -m i -serv pmk0vct10 -e /dev/mapper/VolGroup00-LogVol02 pmk1ora2:/oracle/NodhosImages /PMK1JBOSS10 /srv /tftpboot >> /var/log/lnx_mondo_bkp_system.log
|
|---|
| 51 |
|
|---|
| 52 | "
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | #***************************************************************************
|
|---|
| 58 | # Functions
|
|---|
| 59 | #***************************************************************************
|
|---|
| 60 |
|
|---|
| 61 | error_syntax() {
|
|---|
| 62 | echo ""
|
|---|
| 63 | echo "$SYNTAX" >&2
|
|---|
| 64 | exit 1
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | #***************************************************************************
|
|---|
| 68 | # Variables
|
|---|
| 69 | #***************************************************************************
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | servername=`hostname`
|
|---|
| 73 | resmondo=1
|
|---|
| 74 | mesmondo=""
|
|---|
| 75 | NFS_DIRECTORY=mondo_bck
|
|---|
| 76 | MAIL_TO_SENDER=bruno.legrand@partenaire.pimkie.com
|
|---|
| 77 |
|
|---|
| 78 | #***************************************************************************
|
|---|
| 79 | # MAIN
|
|---|
| 80 | #
|
|---|
| 81 | #***************************************************************************
|
|---|
| 82 | #Verification du nombre d'arguments
|
|---|
| 83 | if [[ $# -lt 1 ]]
|
|---|
| 84 | then
|
|---|
| 85 | error_syntax
|
|---|
| 86 | fi
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | while [ "$1" != "" ]
|
|---|
| 90 | do
|
|---|
| 91 | case $1 in
|
|---|
| 92 | -e) exclude=$2
|
|---|
| 93 | shift
|
|---|
| 94 | while [ "$2" != "-m" ] && [ "$2" != "" ]
|
|---|
| 95 | do
|
|---|
| 96 | exclude="$exclude $2"
|
|---|
| 97 | shift
|
|---|
| 98 | done
|
|---|
| 99 | exclude='"'"$exclude"'"'
|
|---|
| 100 | shift ;;
|
|---|
| 101 |
|
|---|
| 102 | -m) mode=$2
|
|---|
| 103 | shift ;;
|
|---|
| 104 |
|
|---|
| 105 | -serv) servnfs=$2
|
|---|
| 106 | shift ;;
|
|---|
| 107 |
|
|---|
| 108 | -version) echo "$ECHO_VERSION"; exit 49;;
|
|---|
| 109 |
|
|---|
| 110 | -help) echo "$SYNTAX"; exit 50;;
|
|---|
| 111 |
|
|---|
| 112 | esac
|
|---|
| 113 | shift
|
|---|
| 114 | done
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | #Mise en place du montage nfs
|
|---|
| 118 |
|
|---|
| 119 | service nfs restart
|
|---|
| 120 |
|
|---|
| 121 | if [ ! -d /mnt/mondo ] ; then
|
|---|
| 122 | mkdir -v /mnt/mondo
|
|---|
| 123 | fi
|
|---|
| 124 |
|
|---|
| 125 | umount /mnt/mondo
|
|---|
| 126 |
|
|---|
| 127 | mount -t nfs $servnfs:/$NFS_DIRECTORY /mnt/mondo
|
|---|
| 128 |
|
|---|
| 129 | #Ajouter controle erreur
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 | #Creation du dossier de reception au nom du serveur s'il n'existe pas
|
|---|
| 134 |
|
|---|
| 135 | if [ ! -d /mnt/mondo/$servername ] ; then
|
|---|
| 136 | mkdir -v /mnt/mondo/$servername
|
|---|
| 137 | fi
|
|---|
| 138 |
|
|---|
| 139 | #Archivage des Infos du serveur
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | echo "Fiche d'identité de $servername" > /mnt/mondo/$servername//ID.txt
|
|---|
| 143 | echo -e "\n############## Uname -a #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 144 | uname -a >> /mnt/mondo/$servername/ID.txt
|
|---|
| 145 | echo -e "\n############## df -h #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 146 | df -h >> /mnt/mondo/$servername/ID.txt
|
|---|
| 147 | echo -e "\n############## fstab #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 148 | cat /etc/fstab >> /mnt/mondo/$servername/ID.txt
|
|---|
| 149 | echo -e "\n############## ifconfig -a #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 150 | ifconfig eth0 >> /mnt/mondo/$servername/ID.txt
|
|---|
| 151 | echo -e "\n############## OS Version #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 152 | cat /etc/redhat-release >> /mnt/mondo/$servername/ID.txt
|
|---|
| 153 | echo -e "\n############## modprobe.conf #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 154 | cat /etc/modprobe.conf >> /mnt/mondo/$servername/ID.txt
|
|---|
| 155 | echo -e "\n############## Fdisk -l #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 156 | fdisk -l >> /mnt/mondo/$servername/ID.txt
|
|---|
| 157 | echo -e "\n############## LVM #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 158 | pvdisplay >> /mnt/mondo/$servername/ID.txt
|
|---|
| 159 | vgdisplay >> /mnt/mondo/$servername/ID.txt
|
|---|
| 160 | lvdisplay >> /mnt/mondo/$servername/ID.txt
|
|---|
| 161 | echo -e "\n############## Exclus lors de la sauvegarde #########################\n" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 162 | echo "$exclude" >> /mnt/mondo/$servername/ID.txt
|
|---|
| 163 |
|
|---|
| 164 | #On archive l'anciennne sauvegarde (si elle existe)
|
|---|
| 165 |
|
|---|
| 166 | if [ -e /mnt/mondo/$servername/mondorescue-1.iso ] ; then
|
|---|
| 167 | mv /mnt/mondo/$servername/mondorescue-1.iso /mnt/mondo/$servername/mondorescue-1.old
|
|---|
| 168 | fi
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 | #C'est parti!
|
|---|
| 172 |
|
|---|
| 173 | if [ $mode = 'n' ]
|
|---|
| 174 | then
|
|---|
| 175 | echo "mode nfs"
|
|---|
| 176 | mondoarchive -On $servnfs:/$NFS_DIRECTORY -d "$servername" -N -E "$exclude" -s 40g | tee /tmp/mesmondo.txt
|
|---|
| 177 | fi
|
|---|
| 178 |
|
|---|
| 179 | if [ $mode = 'i' ]
|
|---|
| 180 | then
|
|---|
| 181 | echo "mode iso"
|
|---|
| 182 | mondoarchive -Oi -d /mnt/mondo/"$servername" -N -E "$exclude" -s 40g | tee /tmp/mesmondo.txt
|
|---|
| 183 | fi
|
|---|
| 184 |
|
|---|
| 185 | resmondo=`tail /tmp/mesmondo.txt | grep result | awk -F= '{print $2}'`
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 | #On verifie et on envoie un mail sur le statut de la sauvegarde
|
|---|
| 189 |
|
|---|
| 190 | if [ $resmondo != 0 ]
|
|---|
| 191 | then
|
|---|
| 192 | mail -s "Probleme sur l'archivage Mondorescue du serveur $servername ; voir /var/log/mondoarchive.log" $MAIL_TO_SENDER </tmp/mesmondo.txt
|
|---|
| 193 | exit 1;
|
|---|
| 194 | else
|
|---|
| 195 | mail -s "OK pour l'archivage Mondorescue du serveur $servername" $MAIL_TO_SENDER </tmp/mesmondo.txt
|
|---|
| 196 | if [ -e /mnt/mondo/$servername/mondorescue-1.old ] ; then
|
|---|
| 197 | rm -f /mnt/mondo/$servername/mondorescue-1.old
|
|---|
| 198 | fi
|
|---|
| 199 | exit 0;
|
|---|
| 200 | fi
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|