mysqldump full script

For databases with a relatively small amount of data, you can use mysqldump to perform logical backups.

It is recommended that the database size be under 5G, and the backup speed may be similar to that of physical backup. It is best to back up on the slave database or proprietary backup database. If it is a single database, it is recommended to be at 5:00 a.m. and stagger this time period for long-term database operations. .

cat mysqldump.sh

#!/bin/bash
# mysql_config_editor set --login-path=root --user=root  --host=127.0.0.1 --port=3306 --socket=/data/mysql/mysql.sock --password

export MYSQL_TEST_LOGIN_FILE=/root/.mylogin.cnf

Date=`date -d 'today' +%Y%m%d`
Date14=`date -d '14 days ago' +%Y%m%d`
backdir='/data/mysqldump'
mkdir -p $backdir

Dbname=`/usr/bin/mysql --login-path=root -e "show databases" | grep -Ev "test|information_schema|performance_schema|Database"`

for i in $Dbname
  do
   /usr/bin/mysqldump --login-path=root --single-transaction --master-data=2 --routines --flush-privileges --databases  $i |gzip > $backdir/"$i"."$Date".sql.gz
done

find $backdir -name "*$Date14.sql.gz" -exec rm -f {} \;
#Linux解压缩保留源文件的方法:
#gunzip –c filename.gz > filename

Description of several common parameters, the default is FALSE

# single-transaction applies to innodb, the purpose is to maintain consistency
# master-data=2 comment change master to 
# routines backup stored procedures (functions), according to your needs, you can also -E backup events
# flush-logs dump logs ( binlog)

Guess you like

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