[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/bin/bash 2 3 # $Id: sauve.sh 7744 2013-03-31 23:47:51Z keyser $ # 4 5 ##### Lance la sauvegarde sur bande ##### 6 7 # Détection de la distrib 8 9 if [ -e /etc/redhat-release ]; then 10 DISTRIB="RH" 11 WWWPATH="/var/www/html" 12 fi 13 if [ -e /etc/mandrake-release ]; then 14 DISTRIB="MDK" 15 WWWPATH="/var/www/html" 16 fi 17 if [ -e /etc/debian_version ]; then 18 DISTRIB="DEB" 19 WWWPATH="/var/www" 20 fi 21 22 SE3LOG="/var/log/se3/backup.log" 23 XFSLOG="/var/log/se3/xfsdump.log" 24 MEDIA="tape_" 25 XFSDUMP="/usr/sbin/xfsdump" 26 ERASE="-E" 27 28 # Récupération des paramètres mysql 29 30 if [ -e $WWWPATH/se3/includes/config.inc.php ]; then 31 dbhost=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2` 32 dbname=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2` 33 dbuser=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2` 34 dbpass=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2` 35 else 36 echo "Fichier de conf inaccessible" >> $SE3LOG 37 echo "sauve.sh: Status FAILED" >> $SE3LOG 38 exit 1 39 fi 40 41 # Test si la sauvegarde sur bande est active, sinon quitte 42 SAVBANDACTIV=`echo "SELECT value FROM params WHERE name='savbandactiv'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 43 if [ "$SAVBANDACTIV" = "0" ] 44 then 45 echo "Sauvegarde désactivée" 46 exit 0 47 fi 48 49 MELSAVADMIN=`echo "SELECT value FROM params WHERE name='melsavadmin'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 50 SAVLEVEL=`echo "SELECT value FROM params WHERE name='savlevel'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 51 SAVBANDNBR=`echo "SELECT value FROM params WHERE name='savbandnbr'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 52 SAVDEVICE=`echo "SELECT value FROM params WHERE name='savdevice'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 53 SAVHOME=`echo "SELECT value FROM params WHERE name='savhome'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 54 SAVSE3=`echo "SELECT value FROM params WHERE name='savse3'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 55 SAVSUSPEND=`echo "SELECT value FROM params WHERE name='savsuspend'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N` 56 57 # Vérification de l'intégrité des paramètres 58 59 echo "-----------------------------" >> $SE3LOG 60 date >> $SE3LOG 61 echo "-----------------------------" >> $SE3LOG 62 63 if [ -z "SAVDEVICE" ]; then 64 echo "Le périphérique de sauvegarde n'est pas renseigné ou l'accès à la base des paramètres est impossible. La sauvegarde a échouée." >> $SE3LOG 65 echo "sauve.sh: Status FAILED" >> $SE3LOG 66 exit 1 67 fi 68 69 if [ "$SAVSUSPEND" = "1" ]; then 70 echo "La sauvegarde est suspendue..." >> $SE3LOG 71 echo "sauve.sh: Status SUSPEND" >> $SE3LOG 72 exit 0 73 fi 74 75 if [ ! "$SAVHOME" = "0" ]; then 76 FLAGR="" 77 if [ "$SAVHOME" = "2" ]; then 78 FLAGR="-R" 79 else 80 # Commencement d'un nouveau cycle de sauvegarde, j'efface XFSLOG 81 echo "" > $XFSLOG 82 fi 83 echo "---------------------------------------------------------" >>$XFSLOG 84 SESSION="home_" 85 echo "$XFSDUMP -F -l $SAVLEVEL -L $SESSION$SAVLEVEL $ERASE -M $MEDIA$SAVLEVEL$SAVBANDNBR $FLAGR -f $SAVDEVICE /home" >>$XFSLOG 86 $XFSDUMP -F -l $SAVLEVEL -L $SESSION$SAVLEVEL $ERASE -M $MEDIA$SAVLEVEL$SAVBANDNBR $FLAGR -f $SAVDEVICE /home >> $XFSLOG 87 STATUS=`tail -n 1 $XFSLOG | cut -d : -f 3 | sed -e "s/ //g"` 88 echo "Sauvegarde de /home: $STATUS" >>$SE3LOG 89 if [ "$STATUS" = "SUCCESS" ]; then 90 echo "UPDATE params SET value=\"0\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 91 ERASE="" 92 if [ "$SAVSE3" = "0" ]; then 93 # La sauvegarde est achevée avec succes 94 if [ "$SAVBANDNBR" != "0" ]; then 95 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 96 fi 97 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 98 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 99 echo -e "Succès de la sauvegarde.\n Pensez à faire une rotation de la bande en cas de besoin." | mail -s "Sauvegarde SE3" $MELSAVADMIN 100 echo "sauve.sh: La sauvegarde s'est terminée avec succès" >> $SE3LOG 101 fi 102 fi 103 if [ "$STATUS" = "INTERRUPT" ]; then 104 echo "UPDATE params SET value=\"2\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 105 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 106 # Incrémentation du compeur de bande 107 let SAVBANDNBR+=1 108 echo "UPDATE params SET value=\"$SAVBANDNBR\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 109 echo -e "Sauvegarde de /home inachevée.\n Lorsque vous aurez inséré une nouvelle bande, éditez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 110 exit 0 111 fi 112 # Il y a des erreurs non récupérables 113 # Il faut recommencer le processus de savegarde entier /home et /var/se3 :-( 114 # La sauvegarde est placée en état suspendu 115 if [ "$STATUS" = "QUIT" ]; then 116 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 117 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 118 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 119 echo "Erreur lors de la sauvegarde de /home: Le média n'est plus utilisable, changez de bande puis éditez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 120 exit 1 121 fi 122 if [ "$STATUS" = "INCOMPLETE" ]; then 123 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 124 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 125 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 126 echo "Erreur lors de la sauvegarde de /home: La sauvegarde est incomplete. Editez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 127 exit 1 128 fi 129 if [ "$STATUS" = "FAULT" ]; then 130 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 131 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 132 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 133 echo "Erreur lors de la sauvegarde de /home: Erreur logicielle. Editez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 134 exit 1 135 fi 136 if [ "$STATUS" = "ERROR" ]; then 137 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 138 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 139 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 140 echo "Erreur lors de la sauvegarde de /home: Erreur ressource. Editez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 141 exit 1 142 fi 143 fi 144 145 if [ ! "$SAVSE3" = "0" ]; then 146 FLAGR="" 147 if [ "$SAVSE3" = "2" ]; then 148 FLAGR="-R" 149 fi 150 echo "---------------------------------------------------------" >>$XFSLOG 151 SESSION="se3_" 152 echo "$XFSDUMP -F -l $SAVLEVEL -L $SESSION$SAVLEVEL $ERASE -M $MEDIA$SAVLEVEL$SAVBANDNBR $FLAGR -f $SAVDEVICE /var/se3" >>$XFSLOG 153 $XFSDUMP -F -l $SAVLEVEL -L $SESSION$SAVLEVEL $ERASE -M $MEDIA$SAVLEVEL$SAVBANDNBR $FLAGR -f $SAVDEVICE /var/se3 >> $XFSLOG 154 STATUS=`tail -n 1 $XFSLOG | cut -d : -f 3 | sed -e "s/ //g"` 155 echo "sauvegarde de /var/se3: $STATUS" >>$SE3LOG 156 if [ "$STATUS" = "SUCCESS" ]; then 157 if [ "$SAVBANDNBR" != "0" ]; then 158 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 159 fi 160 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 161 echo "UPDATE params SET value=\"1\" WHERE name=\"savse3\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 162 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 163 echo -e "Succès de la sauvegarde.\n Pensez à faire une rotation de la bande en cas de besoin." | mail -s "Sauvegarde SE3" $MELSAVADMIN 164 echo "sauve.sh: La sauvegarde s'est terminée avec succès" >> $SE3LOG 165 fi 166 if [ "$STATUS" = "INTERRUPT" ]; then 167 echo "UPDATE params SET value=\"2\" WHERE name=\"savse3\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 168 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 169 # Incrémentation du compeur de bande 170 let SAVBANDNBR+=1 171 echo "UPDATE params SET value=\"$SAVBANDNBR\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 172 echo -e "Sauvegarde de /var/se3 inachevée.\n Lorsque vous aurez inséré une nouvelle bande, éditez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 173 exit 0 174 fi 175 # Il y a des erreurs non récupérables 176 # Il faut recommencer le processus de savegarde entier /home et /var/se3 :-( 177 # La sauvegarde est placée en état suspendu 178 if [ "$STATUS" = "QUIT" ]; then 179 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 180 echo "UPDATE params SET value=\"1\" WHERE name=\"savse3\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 181 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 182 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 183 echo "Erreur lors de la sauvegarde de /var/se3: Le média n'est plus utilisable, changez de bande puis éditez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 184 exit 1 185 fi 186 if [ "$STATUS" = "INCOMPLETE" ]; then 187 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 188 echo "UPDATE params SET value=\"1\" WHERE name=\"savse3\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 189 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 190 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 191 echo "Erreur lors de la sauvegarde de /var/se3: La sauvegarde a été interrompue. Editez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 192 exit 1 193 fi 194 if [ "$STATUS" = "FAULT" ]; then 195 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 196 echo "UPDATE params SET value=\"1\" WHERE name=\"savse3\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 197 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 198 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 199 echo "Erreur lors de la sauvegarde de /var/se3: Erreur logicielle. Editez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 200 exit 1 201 fi 202 if [ "$STATUS" = "ERROR" ]; then 203 echo "UPDATE params SET value=\"1\" WHERE name=\"savhome\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 204 echo "UPDATE params SET value=\"1\" WHERE name=\"savse3\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 205 echo "UPDATE params SET value=\"1\" WHERE name=\"savsuspend\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 206 echo "UPDATE params SET value=\"0\" WHERE name=\"savbandnbr\""| mysql -h $dbhost $dbname -u $dbuser -p$dbpass 207 echo "Erreur lors de la sauvegarde de /var/se3: Erreur ressource. Editez les parametres de sauvegarde et mettez la variable savsuspend à 0." | mail -s "Sauvegarde SE3" $MELSAVADMIN 208 exit 1 209 fi 210 fi
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |