linux下備份MySQL數據庫並刪除7天前的備份數據
#!/bin/bash
#備份數據庫hz jshuabo sdhuabo
name=$(date +%Y%m%d)
/alidata/server/mysql-5.1.73/bin/mysqldump -u root -p123456 hz > /root/sqlBackup/hz.$name.sql
/alidata/server/mysql-5.1.73/bin/mysqldump -u root -p123456 jshuabo > /root/sqlBackup/jshuabo.$name.sql
/alidata/server/mysql-5.1.73/bin/mysqldump -u root -p123456 sdhuabo > /root/sqlBackup/sdhuabo.$name.sql
#刪除一周之前的備份文件
file_path="/root/sqlBackup"
#方法a
#rm -rf `find $file_path '*.sql' -mitime 7 -print` > delete.log;
#方法b
find $file_path -mtime +7 -type f|xargs rm -f
#方法c
#rm -f `find $file_path -mtime +7 -type f`