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.

2

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.

  • While I agree in spirit, what works for you might not be the best for OP. He's stated he is not willing to build it and wants to be pointed to the solution. That solution is a proper OTS backup suite. He's going to have a much easier time setting up Bacula or Amanda than starting from scratch. – Aaron Copley May 31 '13 at 19:41
  • Yes, thank you. I really prefer simple thing. But simply keeps the last N - very simple. Looks like I just need good script for retention – Korjavin Ivan Jun 3 '13 at 3:37
2

A shell script can handle backups up to a certain point of complexity. You also have tools that leverage tar and rsync to accomplish even more convoluted tasks (rsnapshot, for example).

However, it looks like you need a very fine-grained backup and retention policy that a shell script might not be well suited to handle unless it is unnecessarily complicated and the other tools mentioned do not provide.

You should consider using a dedicated software for this task. There are many, but bacula and amanda come to mind.

  • Thank you alot. I take the point, but still like scripts more then dedicated software. – Korjavin Ivan Jun 3 '13 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.