This article shares the MySQL backup script for your reference. The specific contents are as follows #!/bin/bash #Full backup mode, usually executed on the slave machine, suitable for small and medium-sized MySQL databases #Delete backups older than 15 days #Author: fafu_li #Date: 2015.08.10 source /etc/profile #Load system environment variablessource ~/.bash_profile #Load user environment variablesset -o nounset #Exit when referencing uninitialized variables#set -o errexit #Exit when an error occurs when executing a shell commanduser="root" password="123456" host="localhost" port="3306" #Database to be backed up, array db=("test") #Lock mode during backup, #MyISAM is locked table --lock-all-tables, #InnoDB locks rows --single-transaction lock="--single-transaction" mysql_path="/usr/local/mysql" backup_path="${mysql_path}/backup" date=$(date +%Y-%m-%d_%H-%M-%S) day=15 backup_log="${mysql_path}/backup.log" #Create a backup directory if [ ! -e $backup_path ]; then mkdir -p $backup_path fi #Delete the previous backup find $backup_path -type f -mtime +$day -exec rm -rf {} \; > /dev/null 2>&1 echo "Start backing up database: ${db[*]}" #Backup and compress backup_sql(){ dbname=$1 backup_name="${dbname}_${date}.sql" #-R backup stored procedures, functions, triggers mysqldump -h $host -P $port -u $user -p$password $lock --default-character-set=utf8 --flush-logs -R $dbname > $backup_path/$backup_name if [[ $? == 0 ]];then cd $backup_path tar zcpvf $backup_name.tar.gz $backup_name size=$(du $backup_name.tar.gz -sh | awk '{print $1}') rm -rf $backup_name echo "$date backup $dbname($size) successful" else cd $backup_path rm -rf $backup_name echo "$date backup $dbname failed" fi } #Loop backup length=${#db[@]} for (( i = 0; i < $length; i++ )); do backup_sql ${db[$i]} >> $backup_log 2>&1 done echo "Backup completed, see the result in $backup_log" du $backup_path/*$date* -sh | awk '{print "file:" $2 ", size:" $1}' The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: vue-router hook function implements routing guard
>>: How to use docker+devpi to build local pypi source
Problem description: The following error message ...
MySQL installation instructions MySQL is a relati...
Preface: I reinstalled win10 and organized the fi...
According to the coefficient of pi and the radius...
1.Jenkins installation steps: https://www.jb51.ne...
Differences between Docker and Docker Machine Doc...
1. Multiple borders[1] Background: box-shadow, ou...
The /partition utilization of a server in IDC is ...
In the UI cutting process, the page is often comp...
How to add css in html? There are three ways to s...
The default MySQL version under the Alibaba Cloud...
Lottie is an open source animation library for iO...
1. Page requirements 1) Use standard headers and ...
Table of contents 1. Introduction 2. Usage 3. Dev...
This article example shares the specific code of ...