一个 MySQL 数据库备份脚本,该脚本将只保留最近7天的备份记录:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #!/bin/bash
backup_dir="/data/backup/db_mysql" backup_file="db_backup_$(date +%Y%m%d).sql"
if [ ! -f "$backup_dir" ]; then mkdir -p $backup_dir fi
mysqldump -u your_username -p your_database > "$backup_dir/$backup_file"
find "$backup_dir" -name "db_backup_*" -type f -mtime +7 -delete
|