• 🏠 Accueil
  • 🧰 Générateurs
  • 📰 Blog
  • 🔎 Rechercher
  • 📧 Contact
  • 📘 Livre d'or
  • 🗞️ News
  • 💰 Soutien
  • Description

    This script will backup the database specified on the command line. Credentials, and backup directory are defined on the configuration file of the script.

    You have to create mysql_backup.cfg file, in cfg directory with those contents: (you will also need to generate a base64 encoded password, to avoid a clear password in the configuration file, using: echo "YourPassword" | base64 command).

    ############################################################ 
    # File: mysql_backup.cfg                                   # 
    # Author: Jerome DESMOULINS - djeshellstepsATdesmoulins.fr # 
    # Description:                                             # 
    #   MySQL Database backup script configuration file        # 
    ############################################################ 
    
    MyUser=root 
    MyPwd=[[Put your base64 encoded password here]] 
    MyHost=localhost 

    mysql_backup.sh

    The script contains two steps. One, for Backup of MySQL databases, and the other one, to compress the backup file

    #!/bin/bash 
    ############################################################ 
    # File: mysql_backup.sh                                    # 
    # Author: Jerome DESMOULINS - djeshellstepsATdesmoulins.fr # 
    # Description:                                             # 
    #   MySQL Database backup script                           # 
    ############################################################ 
    
    ### Calling DjeShellSteps ### 
    ShellName=mysql_backup_$1 
    . `dirname $0`/djeshellsteps.sh 
    BeginSteps 
    
    DumpName=${DataDir}/mysql_backup_$1_`date +%Y%m%d_%H%M%S`.sql 
    ReadConfigFile 
    
    if [ -z "$1" ] 
    then 
            echo "Database name missing" 
            exit 1 
    else 
            MyDB=$1 
            MyPwd=`echo $MyPwd | base64 -d` 
    fi 
    
    ########################################################### 
    Step 10 "Backuping $1 mysql database" 
    ########################################################### 
    if [ $RunThisStep -eq 1 ]; then 
            mysqldump -u ${MyUser} -p${MyPwd} -h ${MyHost} --opt ${MyDB} -r ${DumpName} 
    fi 
    
    ########################################################### 
    Step 20 "Compressing export file" 
    ########################################################### 
    if [ $RunThisStep -eq 1 ]; then 
            echo "GZipping ${DumpName}..." 
            gzip ${DumpName} 
            echo "Compression done" 
    fi 
    
    ### End of Shell Script ### 
    EndSteps 

    Retour



    (c) 2005-2025 Jérôme DESMOULINS
    Mentions légales