Keeping oldest backup files?

I need a script to clean up the files on our backup system. I was hoping this would be simple for someone to put together for me.

I'm sure I could do it, but I'm a bash n00b so it would definitely not be efficiently or within a reasonable amount of time. :frowning:

Requirements:

  • Root of backups is at /var/backup
  • We are to process any directory whose name matches "vid*", "pic*", "usr*","bak", ".bak". Ignore any other directories.
  • Each directory is processed individually.
  • We don't recurse into lower directories.
  • We only want to process files whose name matches "config", "_bak", "*.cfg". Ignore any other files.
  • Delete any file matching "*.tmp" that is older than 30 days.

For each matching directory we will:

  • Identify the oldest file that matches the above file name requirements
  • Compare the content of that file to all other files that match the file name requirements and delete any matches.
  • Identify the next newest file that remains
  • Repeat the process until all duplicates are removed.
  • Finally delete any "*.tmp" files that are older than 30 days.

ALL HELP IS APPRECIATED!

In here, certainly nobody will "put together for you" a script. Search these forums (this topic has been covered umpteen times), put sth together yourself, and we'll be glad to help debug/improve.

try the best possible usage of find command. It will be the best possible help for u..

Thanks. I'll start scouring the man page now.

I don't expect anyone to write a complete script for me. I can get the logic down for what I need, and cobble something together. I'm just hoping to get some pointers on what commands would be best to accomplish this task.