spirit posteets tagged backup

 

  • 8 years ago and saved by 1 other
    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
  • 8 years ago and saved by 2 others
    1. #!/bin/bash
    2. TAR_COMPRESS=“tar cjvf” # Commande de compression
    3. BACKUP_EXTENSION=“tar.bz2” # Extension des fichiers compressés
    4. DATE=`date ‘+%d-%m-%Y’`
    5. BACKUP_ADDRESS=“sav@server.org”
    6. BACKUP_DIR=“/directory”
    7. echo “Sauvegarde des fichiers”
    8. echo “On sauvegarde et on envoie le home”
    9. cd /home
    10. for i in `ls`
    11. do
    12.                 $TAR_COMPRESS $i$DATE.$BACKUP_EXTENSION /home/$i/*
    13.                 echo “`date` debut scp $i” >> /var/log/backup.log
    14.                 scp $i$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
    15.                 echo “`date` fin scp $i” >> /var/log/backup.log
    16.                 rm -f $i$DATE.$BACKUP_EXTENSION
    17. done
    18. echo “On sauvegarde et on envoie le home du root “
    19. $TAR_COMPRESS root-$DATE.$BACKUP_EXTENSION /root/
    20. echo “`date` debut scp /root” >> /var/log/backup.log
    21. scp root-$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
    22. echo “`date` fin scp /root” >> /var/log/backup.log
    23. rm -f root-$DATE.$BACKUP_EXTENSION
    24. echo “On sauvegarde et on envoie le etc”
    25. $TAR_COMPRESS etc-$DATE.$BACKUP_EXTENSION /etc/
    26. echo “`date` debut scp /etc” >> /var/log/backup.log
    27. scp etc-$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
    28. echo “`date` fin scp /etc” >> /var/log/backup.log
    29. rm -f etc-$DATE.$BACKUP_EXTENSION
    30. echo “On passe au dump MySQL”
    31. MYSQL_USER=“root” # User mySQL à utiliser pour faire le dump
    32. MYSQL_PASSWORD=“pass” # Mot de passe root de la base mySQL
    33. MYSQL_HOST=“localhost” # Host de la base mySQL
    34. SQL_LIST_DB=“SHOW DATABASES;” # Requete SQL listant toutes les bases
    35. cd /home/backup/dumpsql
    36. echo “Dump de toutes les bases MySQL”
    37. mysqldump -p“$MYSQL_PASSWORD” –all-databases > all-databases.$DATE.sql
    38. echo “Compression et envoie du dump”
    39. $TAR_COMPRESS  all-databases-$DATE.sql.$BACKUP_EXTENSION all-databases.$DATE.sql
    40. echo “`date` debut scp all databases” >> /var/log/backup.log
    41. scp all-databases-$DATE.sql.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
    42. echo “`date` fin scp all databases” >> /var/log/backup.log
    43. rm -f all-databases.$DATE.sql
    44. rm -f all-databases-$DATE.sql.$BACKUP_EXTENSION
    45. echo “Dump base par base”
    46. for database in `echo $SQL_LIST_DB | mysql -u $MYSQL_USER -p“$MYSQL_PASSWORD” -h $MYSQL_HOST | sed 1d`
    47. do
    48.         mysqldump -p“$MYSQL_PASSWORD” –databases $database > $database$DATE.sql
    49.         $TAR_COMPRESS $database$DATE.sql.$BACKUP_EXTENSION $database$DATE.sql
    50.         rm -f $database$DATE.sql
    51. done
    52. echo “On sauvegarde le dump des bases et on l’envoie”
    53. $TAR_COMPRESS dump-$DATE.$BACKUP_EXTENSION *.*.sql.$BACKUP_EXTENSION
    54. echo “`date` debut scp base par base” >> /var/log/backup.log
    55. scp dump-$DATE.$BACKUP_EXTENSION $BACKUP_ADDRESS:$BACKUP_DIR
    56. echo “`date` fin scp base par base” >> /var/log/backup.log
    57. rm -f dump-$DATE.$BACKUP_EXTENSION