Home >Database >Mysql Tutorial >linux下备份MySQL数据库并删除7天前的备份数据_MySQL

linux下备份MySQL数据库并删除7天前的备份数据_MySQL

WBOY
WBOYOriginal
2016-06-01 13:04:091014browse

#!/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`


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn