LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Automatically Purge Backup Files Off Thumb Drive (https://www.linuxquestions.org/questions/linux-software-2/automatically-purge-backup-files-off-thumb-drive-547712/)

JustinK101 04-20-2007 06:11 PM

Automatically Purge Backup Files Off Thumb Drive
 
Hello, we have a thumb drive attached to a CentOS box and mysql backups are automatically saved to the thumb drive. Is there a way to automatically purge backup files if they are older than say 15 days? I suppose I would need to write a script for this.

The format of the mysql dump files are:

Backup_20070420_0015.sql

Thanks for the help.

fukawi2 04-21-2007 03:58 AM

Code:

find /mnt/thumb -mtime +15 -iname Backup\*.sql -exec rm -rf {} \;

JustinK101 04-23-2007 11:18 AM

Ok, so do I just put that in a file, which is rwxr-x-r-x and then add to the cronmanager?

JustinK101 04-23-2007 11:39 AM

Also, do I need to define what shell I want to use?

fukawi2 04-23-2007 05:46 PM

You could make it in to a cron script if you like.

Something as simple as this would work:
Code:

#!/bin/bash

find /mnt/thumb -mtime +15 -iname Backup\*.sql -exec rm -rf {} \;

You might like to add a check to see if the USB Key is actually mounted:
Code:

#!/bin/bash

SCRUBDIR='/mnt/thumb'

# Check if it's mounted first
MOUNTED=`cat /etc/mtab | grep $SCRUBDIR`
if [ ! -z "$MOUNTED" ] ; then
        find $SCRUBDIR -mtime +15 -iname Backup\*.sql -exec rm -rf {} \;
fi



All times are GMT -5. The time now is 12:11 PM.