Restore mysql backup data on linux


#Database restore
echo $1 
echo $2 
echo $3

#!/bin/bash
# MYSQLDBUSERNAME is the username of the MySQL database, which can be customized
MYSQLDBUSERNAME=$1
# MYSQLDBPASSWORD is the password of the MySQL database, which can be customized
MYSQLDBPASSWORD=$2
# MYSQBASEDIR is the installation directory of the MySQL database, --prefix=$MYSQBASEDIR , customizable
MYSQBASEDIR=/usr/local/mysql
# MYSQL is the absolute path of the mysql command, customizable
MYSQL=$MYSQBASEDIR/bin/mysql
# MYSQLDUMP is the absolute path of the mysqldump command, customizable
MYSQLDUMP=$MYSQBASEDIR/bin /mysqldump


# BACKDIR is the storage address of the database backup, which can be customized and modified to the remote address
BACKDIR=/home/backup/mysql
# The directory for data recovery
 
TODAY=$3

echo $TODAY
RECOVERYDIR=$BACKDIR/$TODAY


# Get the backup files in the backup directory in MySQL
DBLIST_TMP=`ls -p $RECOVERYDIR`

#Get all file names in the directory and save them to a variable
DBLIST=($(echo $DBLIST_TMP))

#echo "The elements in the set are: ${DBLIST[@]}"
# Loop out the database name from the database list and perform the backup operation
for recoveryName in ${DBLIST[@]}

    do 
    
    echo $RECOVERYDIR/$recoveryName
    
 gunzip < $RECOVERYDIR/$recoveryName | mysql --user=${MYSQLDBUSERNAME}

--password=${MYSQLDBPASSWORD} 

    
    # Check the execution result, if the error code is 0, the output is successful, otherwise the output fails
    [ $? -eq 0 ] && echo "${recoveryName} has been recoveried successful"

                              || echo "${recoveryName} has been recovered failed"
    # Wait 3s, can be customized
    /bin/sleep 3
done

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326054982&siteId=291194637