#!/bin/bashdbuser=rootdbpasswd=123456dbbak1=mysql_testbackupdir1=/data/backup_v2/mysql_testbacktime= ' Date +%y%m%d%h%m%s ' if [ ! -d $BACKUPDIR 1 ];then mkdir $BACKUPDIR 1fiecho "========== $BACKTIME Database $dbbak1 backup start ==========" > > $BACKUPDIR 1/mysql_test.logcd $BACKUPDIR 1mysqldump --opt -r --triggers -e --lock-all-tables --flush-logs --master-data=2 -u$dbuser -p$dbpasswd -- databases $DBBAK 1 > $DBBAK 1. $BACKTIME .sql 2>> $BACKUPDIR 1/mysql_test.logif [ $?==0 ];then tar zcf $DBBAK 1.$ backtime.tar.gz $DBBAK 1. $BACKTIME .sql > /dev/null rm -f $BACKUPDIR 1/$DBBAK 1. $BACKTIME. Sql echo -e "========= Database $dbbak1 Success!! =========\n " >> $BACKUPDIR 1/mysql_test.logelse echo -e "========= Database $dbbak1 backup failed!! =========\n " >> $BACKUPDIR 1/mysql_test.logfifind /data/backup_v2/mysql_test/ -mtime +10 -delete
This article is from the "burning Years of Passion" blog, please be sure to keep this source http://liuzhengwei521.blog.51cto.com/4855442/1909887
MySQL or mariadb backup script