大网数据广告活动
服务器运维问答

Script for remove old backups

· 52CE 我爱测

I have a lot of backups, like: backup-20130528_054504_mysql.tar.gz, bill_db_201305290130.BAK.bz2, etc_20130412.tbz This is full backups which done each day. Before today, I have a cron task with a command line like this: /usr/bin…

问题原文

原帖链接 · Korjavin Ivan · CC BY-SA 3.0

I have a lot of backups, like:

backup-20130528_054504_mysql.tar.gz, 
bill_db_201305290130.BAK.bz2,
etc_20130412.tbz

This is full backups which done each day.

Before today, I have a cron task with a command line like this:

/usr/bin/find /media/backups -ctime +7 -delete

But it was the bad idea.

One server stopped do new backups (filesystem was full) more than 7 days ago, and all old backups was deleted by cron.

Probably I need a new script as replacement for this "find -ctime", which will hold some old backups anyway.

All my backup files have names {unique_prefix}YYYYMMDD...

I want something like :

  • one backup for each year before last year
  • one backup for each month of last year
  • 4 backup for each week of previous month
  • and 7 backups for last 7 days.

for each {unique_prefix}.

All this files are downloaded to my server by cron via rsync, ssh , etc..

I dislike reinvent the wheel, and pretty sure that is a typical task.

Please, point me to the solution.

已采纳解答

原帖链接 · Dennis Kaarsemaker · CC BY-SA 3.0

I disagree with dawud and think simple backups are the best.

What you really need is not a smarter way of deleting things (though that wouldn't be a bad idea, I wrote something similar which simply keeps the last N backups), but proper monitoring of your filesystem so you'll notice it filling up well before it does and you can take action. That way you won't lose your data.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-05-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。