Re: Need some small help on shell script - delete old files



On Jun 4, 5:02 pm, "steven_nospam at Yahoo! Canada"
<steven_nos...@xxxxxxxx> wrote:
On Jun 4, 11:01 am, David <david4...@xxxxxxxxxxx> wrote:



1.) I do not have subdirectories past the /home/tom64/public_html/cgi-
bin/arp3/backup   directory.   Please revise and confirm the best
command so that it does not search subdirectories past this directory
if that is important.

2.) Please look at my original script from the first message to this
post.   For some reason, my script has not been gzipping these .sql
files.  Any idea how to fix that so that they do get gzipped?

Thank you so very much!-

Here is what I would do if using your setup. Keep in mind, I tend to
use piped commands because my workload would rarely suffer from
performance issues, but some people may have a better way.

# START OF SAMPLE #
###################
BKPPATH=/home/tom64/public_html/cgi-bin/arp3/backup/
BKPFILE=$(/bin/date +"%Y-%b-%d").sql
#
# Do the current mysqldump
/usr/bin/mysqldump --opt -utom64 -pPaSSwoRD tom64 > ${BKPPATH}$
{BKPFILE}
#
# gzip any files that start with a number and end with sql
# this is sufficiently unique in the BKPPATH
cd ${BKPPATH}
ls | grep "^[0-9].*sql$" | xargs gzip
#
# Remove oldest backups from specified path - do NOT go into
subdirectories
# Anything older than 7 days with .sql.gz extension will be removed
# For testing purposes - you may replace "rm" command with "ls"
find ${BKPPATH} -name "*.sql.gz" -mtime +7 -print |
   grep -v "${BKPPATH}.*/" |
   xargs /bin/rm
#################
# END OF SAMPLE #

The find command shows all files in the directory and subdirectories.
We then use grep -v to limit our view to files in the designated
directory by saying ignore any files that have the BKPPATH name along
with one or more characters (.*) and another slash (/). The results of
the grep are then sent to xargs to issue the rm command. The extra
gzip of $FILENAME at the end is not necessary as far as I can tell
because the ls will see that new file and gzip it in the ls | xargs
section.

CAVEAT: This was tested briefly on an IBM AIX 5.3 system in Korn Shell
and worked for me. It should naturally be tested on a test system
before being released to any production server. You may also want to
add additional checks, such as making sure your BKPPATH is set,
directory is not empty, etc. as I have not tried all possible
scenarios. Use at your own risk.

Regards,

SteveN


SteveN,

I am using your script.

1.) Is there any way that the script can be modified so that even the
last dump that it does gets gzipped? I am noticing that the most
recent dump is always left un-compressed with no .gz extension. The
following day, it will gzip any prior files and then create a new non-
gzipped dump.

2.) I am still getting a second dump at around 2-3pm each day
strangly. I have no other cron job running which would do this. What
is an "AT job" as quoted in your post on 06/15/2009 at 3:46pm?

Thank you!

David
.



Relevant Pages

  • Re: Need some small help on shell script - delete old files
    ... command so that it does not search subdirectories past this directory ... The find command shows all files in the directory and subdirectories. ... gzip of $FILENAME at the end is not necessary as far as I can tell ... I am running the script and have noticed that the file names have been ...
    (comp.unix.shell)
  • Re: Need some small help on shell script - delete old files
    ... command so that it does not search subdirectories past this directory ... Please look at my original script from the first message to this ... # this is sufficiently unique in the BKPPATH ... The find command shows all files in the directory and subdirectories. ...
    (comp.unix.shell)
  • Re: Command to dump/restore user info OSR5
    ... Write a script that does a dump and then compares the current dump against the previous such dump. ... You don't have a diff unless you install the devsys or gnutools. ... The order of the filenames on the diff command line, and the way the script renumbers filenames, means that the first instance is the old password and the next instance is the new password. ...
    (comp.unix.sco.misc)
  • Copying and insuring directory and subdirectory contents have been synchronized.
    ... TEST subdirectories. ... room to hold two copies of the file while the copy command completes. ... the individual files after the global copy or better yet, have a better, ... I was also thinking of building a script with rm commands in it for some ...
    (AIX-L)
  • Re: Need some small help on shell script - delete old files
    ... I am using your script. ... recent dump is always left un-compressed with no .gz extension. ... or use the "wait" command to see if it must delay the start of the ... The second dump has to be coming from an alternate CRON job or an AT ...
    (comp.unix.shell)