mysqldump 備份指令碼

snale1989發表於2016-11-30
#!/bin/bash

DUMP=/usr/bin/mysqldump
OUT_DIR=/home/mysql

LINUX_USER=root

DB_NAME=snale

DB_USER=root 

DB_PASS=password
DB_HOST=127.0.0.1

DAYS=7

cd $OUT_DIR 

DATE=`date +%Y_%m_%d` 

OUT_SQL="$DATE.sql" 

TAR_SQL="mysqldata_bak_$DATE.tar.gz" 

$DUMP -u$DB_USER -h $DB_HOST -p$DB_PASS $DB_NAME --default-character-set=utf8 --opt -Q -R --skip-lock-tables> $OUT_SQL 

tar -czf $TAR_SQL ./$OUT_SQL 

rm $OUT_SQL 

chown $LINUX_USER:$LINUX_USER $OUT_DIR/$TAR_SQL

find $OUT_DIR -name "mysqldata_bak*" -type f -mtime +$DAYS -exec rm {} \; 

 

相關文章