数据库shell备份与超时自动删除

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash 
id="user"
pwd="password"
$db="db"
backuppath="/app/"$user"/var/dbbackup"
day=15
[ ! -d $backuppath ] && mkdir -p $backuppath
cd $backuppath

dbname=$db'_'
backupname=$dbname`date +%Y%m%d%H%M%S`
mysqldump -h127.0.0.1 -u$id -p$pwd $db --single-transaction --triggers --skip-tz-utc --ignore-table-data=$db.quote_id_mask | gzip -> $backupname.sql.gz
find $backuppath -name $dbname"*.sql.gz" -type f -mtime +$day -exec rm -rf {} \;