A script is used to export all MySQL databases and save them to a specified location.
The contents are as follows:
The code is as follows |
Copy Code |
#!/bin/bash ############################################ # # This is a MySQL database backup script # One at a time to export all the database and GZ compressed save # ccshaowei#gmail.com # 2013/05/08 # http://www.111cn.net# ############################################ # Backup Directory Backdir=/home/shaowei/dbbak # Database Login User Name Dbuser= ' Dbusername ' # Database Login Password dbpass= ' dbpasswd ' # database location is usually/var/lib/mysql dblist=$ (ls-p/var/lib/mysql | grep/| tr-d/) ################ Configuration End ################# today=$ (Date +%y%m%d) mkdir $backdir mkdir $backdir/$today For dbname in $dblist ######################################## #如果不需要显示压缩比, remove the-v parameter after gzip Do Mysqldump-u$dbuser-p$dbpass $dbname | Gzip-v > $backdir/$today/$dbname-$today sql.gz echo $dbname ' OK ' #如果需要他默默的运行, comment out this line Done |
The run result is to save all the databases to the backup directory/today's date/xxx.sql.gz