modif sql dump
This commit is contained in:
parent
5b7dccb6b0
commit
9603e3edbb
@ -1,17 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Inspiré d'un script trouvé sur phpnews.fr (plus en ligne)
|
||||
# Version 0.3 13/05/2013
|
||||
|
||||
# Script sous licence BEERWARE
|
||||
|
||||
set -eu
|
||||
|
||||
## Paramètres
|
||||
USER='dump'
|
||||
PASS='wg4KAKkbywiLs8pQ'
|
||||
# Répertoire de stockage des sauvegardes
|
||||
DATADIR="/diskstation/git/backup/mysql"
|
||||
DATADIR="/mnt/diskstation/git/backup/mysql/"
|
||||
# Répertoire de travail (création/compression)
|
||||
DATATMP=$DATADIR
|
||||
# Nom du dump
|
||||
@ -22,7 +18,7 @@ COMPRESSIONEXT=".tar.gz"
|
||||
# Rétention / rotation des sauvegardes
|
||||
RETENTION=30
|
||||
# Exclure des bases
|
||||
EXCLUSIONS='(information_schema|performance_schema)'
|
||||
EXCLUSIONS='(information_schema|performance_schema|mysql)'
|
||||
# Email pour les erreurs (0 pour désactiver
|
||||
EMAIL=0
|
||||
# Log d'erreur
|
||||
@ -41,7 +37,7 @@ function cleanup {
|
||||
trap cleanup EXIT
|
||||
|
||||
# On crée sur le disque un répertoire temporaire
|
||||
mkdir -p ${DATATMP}/${DATANAME}
|
||||
mkdir -p ${DATATMP}/last
|
||||
|
||||
# On place dans un tableau le nom de toutes les bases de données du serveur
|
||||
databases="$(mysql -u $USER -p$PASS -Bse 'show databases' | grep -v -E $EXCLUSIONS)"
|
||||
@ -50,12 +46,12 @@ databases="$(mysql -u $USER -p$PASS -Bse 'show databases' | grep -v -E $EXCLUSIO
|
||||
for database in ${databases[@]}
|
||||
do
|
||||
echo "dump : $database"
|
||||
mysqldump -u $USER -p$PASS --quick --add-locks --lock-tables --extended-insert $database > ${DATATMP}/${DATANAME}/${database}.sql
|
||||
mysqldump -u $USER -p$PASS --quick --add-locks --lock-tables --extended-insert $database > ${DATATMP}/last/${database}.sql
|
||||
done
|
||||
|
||||
# On tar tous
|
||||
cd ${DATATMP}
|
||||
${COMPRESSIONCMD} ${DATANAME}${COMPRESSIONEXT} ${DATANAME}/
|
||||
${COMPRESSIONCMD} ${DATANAME}${COMPRESSIONEXT} last/
|
||||
chmod 600 ${DATANAME}${COMPRESSIONEXT}
|
||||
|
||||
# On le déplace dans le répertoire
|
||||
@ -64,14 +60,14 @@ if [ "$DATATMP" != "$DATADIR" ] ; then
|
||||
fi
|
||||
|
||||
# Lien symbolique sur la dernier version
|
||||
cd ${DATADIR}
|
||||
set +eu
|
||||
unlink last${COMPRESSIONEXT}
|
||||
set -eu
|
||||
ln ${DATANAME}${COMPRESSIONEXT} last${COMPRESSIONEXT}
|
||||
#cd ${DATADIR}
|
||||
#set +eu
|
||||
#unlink last${COMPRESSIONEXT}
|
||||
#set -eu
|
||||
#ln ${DATANAME}${COMPRESSIONEXT} last${COMPRESSIONEXT}
|
||||
|
||||
# On supprime le répertoire temporaire
|
||||
rm -rf ${DATATMP}/${DATANAME}
|
||||
#rm -rf ${DATATMP}/${DATANAME}
|
||||
|
||||
echo "Suppression des vieux backup : "
|
||||
find ${DATADIR} -name "*${COMPRESSIONEXT}" -mtime +${RETENTION} -print -exec rm {} \;
|
||||
|
Loading…
Reference in New Issue
Block a user