Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding utilities scripts and mysql backup script
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
# Script de sauvegarde mysql | ||
|
||
MYSQL_LOGIN= | ||
MYSQL_PASSWORD= | ||
BACKUP_LOG_ROOT=/log/backup | ||
BACKUP_DUMP_ROOT=/backup/mysql | ||
|
||
# Setup Global Environnement | ||
. $(pwd)/$(dirname $0)/../../setup.sh | ||
#. ../../setup.sh | ||
|
||
log_info "Sauvegarde des Bases MySql" | ||
log_info "LOG="${BACKUP_LOG_ROOT} | ||
log_info "DUMP="${BACKUP_DUMP_ROOT} | ||
|
||
timestamp=$(date +%Y%m%d-%H%M%S) | ||
prefix=${HOSTNAME_SHORT} | ||
|
||
exit 0 | ||
|
||
# Sauvegarde de chaque Base dans un fichier | ||
for database in `echo "show databases" | mysql -u ${MYSQL_LOGIN} -p${MYSQL_PASSWORD} --disable-pager -N` | ||
do | ||
if [ "$database" != "lost+found" ] | ||
then | ||
BACKUP_FILE=${BACKUP_DUMP_ROOT}"/${prefix}-mysql-backup-"${timestamp}"-"${database}".sql" | ||
LOG_FILE=${BACKUP_LOG_ROOT}"/${prefix}-mysql-backup-"${timestamp}"-"${database}".log" | ||
#echo "#"$(date +%Y%m%d-%H%M%S)"# DEBUT Sauvegarde de ["${database}"] in ["${BACKUP_FILE}"]" | tee -a ${LOG_FILE} | ||
echo "#"$(date +%Y%m%d-%H%M%S)"# DEBUT Sauvegarde de ["${database}"] in ["${BACKUP_FILE}"]" | ||
# liste des options de sauvegarde | ||
# -q recuperation 1 ligne a la foi pour la sauvegarde | ||
# -c | --complete-insert : insertion complete avec les noms de colonnes | ||
# --allow-keywords prefixe les noms de colonne avec la table | ||
# -i ajout de commentaires : version ... | ||
# --add-locks : ajoute une instruction LOCK TABLSS avant et UNLOCK TABLES apres pour accelerer les insertions dans mysql | ||
# --create-options : ajoute toutes options specifiques MySql dans le script de creation de table | ||
# --default-character-set=XXXXX : le charset par defaut (si non specifie alors utf8) | ||
# -e | --extended-insert : utilise la nouvelle syntaxe INSERT multi-ligne (plus courtes et plus efficaces) | ||
# -q | --quick : ne garde pas en buffer les requetes mais ecrit immediatement sur la sortie | ||
# -Q | --quote-names : protege les noms de table et colonnes avec le caractere '`' | ||
# | ||
# --opt est equivalent a --quick --add-drop-table --add-locks --extended-insert --lock-tables | ||
# | ||
# mysqldump --add-drop-table --allow-keywords --default-character-set=latin1 -q -c -u${MYSQL_LOGIN} -p${MYSQL_PASSWORD} ${database} > ${BACKUP_FILE} | ||
# mysqldump --quick --add-locks --extended-insert --lock-tables --allow-keywords --default-character-set=latin1 -c -u${MYSQL_LOGIN} -p${MYSQL_PASSWORD} ${database} > ${BACKUP_FILE} | ||
# mysqldump --quick --add-locks --extended-insert --lock-tables --allow-keywords --default-character-set=latin1 -c -u${MYSQL_LOGIN} -p${MYSQL_PASSWORD} ${database} | gzip > ${BACKUP_FILE}.gz | ||
mysqldump --quick --add-locks --extended-insert --lock-tables --allow-keywords --default-character-set=latin1 -c -u${MYSQL_LOGIN} -p${MYSQL_PASSWORD} ${database} | bzip2 -9 > ${BACKUP_FILE}.bz | ||
retour=$? | ||
if [ "$retour" -eq "0" ] | ||
then | ||
#echo "#"$(date +%Y%m%d-%H%M%S)"# La sauvegarde s'est correctement deroulee" | tee -a ${LOG_FILE} | ||
echo "#"$(date +%Y%m%d-%H%M%S)"# La sauvegarde s'est correctement deroulee" | ||
else | ||
#echo "#"$(date +%Y%m%d-%H%M%S)"# La sauvegarde s'est terminee en ERREUR" | tee -a ${LOG_FILE} | ||
echo "#"$(date +%Y%m%d-%H%M%S)"# La sauvegarde s'est terminee en ERREUR" | ||
fi | ||
#echo "#"$(date +%Y%m%d-%H%M%S)"# FIN Sauvegarde de ["${database}"] in ["${BACKUP_FILE}"]" | tee -a ${LOG_FILE} | ||
echo "#"$(date +%Y%m%d-%H%M%S)"# FIN Sauvegarde de ["${database}"] in ["${BACKUP_FILE}"]" | ||
fi | ||
done | ||
|
||
|
||
exit $retour | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
# | ||
|
||
# Define te environnement | ||
#LOG_LEVEL=TRACE | ||
|
||
## Import of the utilities env | ||
. utils/sys_env.sh | ||
|
||
HOSTNAME=UNKNOWN | ||
HOSTNAME_SHORT=UNKNOWN | ||
if ${CYGWIN} ; then | ||
HOSTNAME=$(hostname) | ||
HOSTNAME_SHORT=$(hostname) | ||
else | ||
HOSTNAME=$(hostname -f) | ||
HOSTNAME_SHORT=$(hostname -s) | ||
fi | ||
|
||
|
||
## Import of the utilities scripts | ||
. utils/log_functions.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
# script de tests de "log_functions.sh" | ||
|
||
echo "Chargement de $(pwd)/$(dirname $0)/log_functions.sh" | ||
. $(pwd)/$(dirname $0)/log_functions.sh | ||
|
||
log_trace "Ma log de Trace" | ||
log_info "Ma log d'Info" | ||
log_error "Ma log d'Erreur" | ||
|
||
declare -F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
### Utilities functions for Logging ### | ||
# | ||
### FUNCTIONS LIST | ||
#> log_trace (<Str to log>) | ||
#> log_info (<Str to log>) | ||
#> log_error (<Str to log>) | ||
### LOG OUTPUT FORMAT | ||
#> # <YYYYMMDD-HHMMSS> # <[TRACE|INFO|ERROR]> # <the log message> | ||
|
||
## main function for logging | ||
#> $1 : level of the log | ||
#> $2 : the string to log | ||
function _internal_log { echo "# "$(date +%Y%m%d-%H%M%S)" # "$1" # "$2; } | ||
## TRACE LOGGING | ||
#> $1 : the string to log | ||
function log_trace { _internal_log "TRACE" "$1"; } | ||
## INFO LOGGING | ||
#> $1 : the string to log | ||
function log_info { _internal_log "INFO " "$1"; } | ||
## ERROR LOGGING | ||
#> $1 : the string to log | ||
function log_error { _internal_log "ERROR" "$1"; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
### Utilities functions for System ### | ||
# | ||
### FUNCTIONS LIST | ||
#> log_trace (<Str to log>) | ||
#> log_info (<Str to log>) | ||
#> log_error (<Str to log>) | ||
### LOG OUTPUT FORMAT | ||
#> # <YYYYMMDD-HHMMSS> # <[TRACE|INFO|ERROR]> # <the log message> | ||
|
||
# OS specific support. $var _must_ be set to either true or false. | ||
cygwin=false | ||
os400=false | ||
darwin=false | ||
case "`uname`" in | ||
CYGWIN*) cygwin=true;; | ||
OS400*) os400=true;; | ||
Darwin*) darwin=true;; | ||
esac |