Automatically back up MySQL scripts:
The following script for MySQL automatic backup script, for reference only, can be modified according to the actual situation. #!/bin/sh #auto backup mysql #20170329 # define PATH definition variable bakdir=/data/backup/mysql/' date +%y-%m-%d ' mysqldb=webapp mysqlpw=backup mysqlusr=backup #must Use root user run scripts must be run with root, $ UID is System variable if [$UID-ne 0];then echo This script must use the root user!!! &nbs P sleep 2 exit 0 fi #Define dir and mkdir dir to determine if the directory exists, does not exist the new if [!-D $ Bakdir];then mkdir-p $BAKDIR else echo This is $BAKDIR exists.... fi& nbsp; #Use mysqldump backup MySQL uses mysqldump to back up the database/usr/bin/mysqldump-u$mysqlusr-p$mysqlpw-d $MYSQLDB > $BAKDIR/ WEBAPP_DB.SQL CD $BAKDIR; Tar-czf webapp_mysql_db.tar.gz *.sql #查找备份目录下以. SQL End file and delete the Find . -type f-name "*.sql" |xargs rm-rf #如何数据库备份成功, print successfully, and delete the backup directory 30 days before the directory [$?-eq 0]&&echo "This ' date +%y-%m-%d ' MySQL BACKUP is SUCCESS " cd/data/backup/mysql/; find. -type d -mtime +30 |xargs rm-rf echo "The MySQL backup successfully"
MySQL database backup script