-
Note: Le mot de passe est collé à l’option -p. Ceci permet faire le dump sans intéraction utilisateur
Backup : mysqldump -u root -pSuperMotDePasse --all-databases > backup.sql Restauration : mysql -u root -pSuperMotDePasse < backup.sql
-
-
#!/bin/bash
-
TAR_COMPRESS=“tar cjvf” # Commande de compression
-
BACKUP_EXTENSION=“tar.bz2” # Extension des fichiers compressés
-
DATE=`date ‘+%d-%m-%Y’`
-
BACKUP_ADDRESS=“[email protected]”
-
BACKUP_DIR=“/directory”
-
echo “Sauvegarde des fichiers”
-
echo “On sauvegarde et on envoie le home”
-
cd /home
-
for i in `ls`
-
do
-
$TAR_COMPRESS $i–$DATE.$BACKUP_EXTENSION /home/$i/*
-
echo “`date` debut scp $i” >> /var/log/backup.log
-
scp $i–$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
-
echo “`date` fin scp $i” >> /var/log/backup.log
-
rm -f $i–$DATE.$BACKUP_EXTENSION
-
done
-
echo “On sauvegarde et on envoie le home du root “
-
$TAR_COMPRESS root-$DATE.$BACKUP_EXTENSION /root/
-
echo “`date` debut scp /root” >> /var/log/backup.log
-
scp root-$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
-
echo “`date` fin scp /root” >> /var/log/backup.log
-
rm -f root-$DATE.$BACKUP_EXTENSION
-
echo “On sauvegarde et on envoie le etc”
-
$TAR_COMPRESS etc-$DATE.$BACKUP_EXTENSION /etc/
-
echo “`date` debut scp /etc” >> /var/log/backup.log
-
scp etc-$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
-
echo “`date` fin scp /etc” >> /var/log/backup.log
-
rm -f etc-$DATE.$BACKUP_EXTENSION
-
echo “On passe au dump MySQL”
-
MYSQL_USER=“root” # User mySQL Ã utiliser pour faire le dump
-
MYSQL_PASSWORD=“pass” # Mot de passe root de la base mySQL
-
MYSQL_HOST=“localhost” # Host de la base mySQL
-
SQL_LIST_DB=“SHOW DATABASES;” # Requete SQL listant toutes les bases
-
cd /home/backup/dumpsql
-
echo “Dump de toutes les bases MySQL”
-
mysqldump -p“$MYSQL_PASSWORD” –all-databases > all-databases.$DATE.sql
-
echo “Compression et envoie du dump”
-
$TAR_COMPRESS all-databases-$DATE.sql.$BACKUP_EXTENSION all-databases.$DATE.sql
-
echo “`date` debut scp all databases” >> /var/log/backup.log
-
scp all-databases-$DATE.sql.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
-
echo “`date` fin scp all databases” >> /var/log/backup.log
-
rm -f all-databases.$DATE.sql
-
rm -f all-databases-$DATE.sql.$BACKUP_EXTENSION
-
echo “Dump base par base”
-
for database in `echo $SQL_LIST_DB | mysql -u $MYSQL_USER -p“$MYSQL_PASSWORD” -h $MYSQL_HOST | sed 1d`
-
do
-
mysqldump -p“$MYSQL_PASSWORD” –databases $database > $database–$DATE.sql
-
$TAR_COMPRESS $database–$DATE.sql.$BACKUP_EXTENSION $database–$DATE.sql
-
rm -f $database–$DATE.sql
-
done
-
echo “On sauvegarde le dump des bases et on l’envoie”
-
$TAR_COMPRESS dump-$DATE.$BACKUP_EXTENSION *.*.sql.$BACKUP_EXTENSION
-
echo “`date` debut scp base par base” >> /var/log/backup.log
-
scp dump-$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
-
echo “`date` fin scp base par base” >> /var/log/backup.log
-
rm -f dump-$DATE.$BACKUP_EXTENSION
spirit’s tags
access apache apache2 apt arguments auditd auth awk backup backups bandwidth bash bridge cache cd charset cisco commands conversion cron css date debian debug default diff directories directory distance dns dom du eth ethernet excel exclude files find firefox flash forms function hacks headers history hosts htaccess html http https ie ifconfig images input ip javascript jobs kill latitude linux log logging longitude mac mail maps merge monitoring mysql network nginx openssl packages performance performances perl php red hat regex restore root route rpm script security server shell ssh ssl svn switch syslog tail trunk unix virtualhost vlan vmware windows yum
-