Solved

I need guidance in tweaking my Nightly Cron Backup script to properly remove old files.

Posted on 2009-05-14
3
363 Views
Last Modified: 2013-12-16
I have two IP security cameras that each take a snapshot every 3 seconds and FTP it to my linux server. This generates approximately 85,000 images per day. I've written a very rough backup script to perform the following functions at the end of each day:

1) Delete the old DAY.TAR.GZ (i.e. Monday would delete last week's Monday.tar.gz)
2) Tar all of the current day's image files into DAY.TAR.GZ
3) Delete all of the current day's image files.

This repeats every day, so I always have 7 days worth of surveillance stills to go back and review if needed. Monday.tar.gz, Tuesday.tar.gz, Wednesday.tar.gz, etc etc.

The script works great except for the deleting of the current day's photos. Originally I was running an rm -f /var/www/photosvcs/*.jpg that was supposed to delete all of the JPG image files from the directory, but the argument list was too long so it would fail. Eventually I ran out of disk space as nothing was being deleted but everything was being backed up each night. Not a good situation.

I found a workaround to get past the 'Too Many Arguments' error for rm, which was to do a find and print the results to delete everything individually. I'm posting a snippet of my cron to show what I am doing currently. It's still not working, though, which is why I'm here. I'm actually not getting any errors from this, the files just aren't being deleted.

I know this script is bulky but I'm by no means a script coding kind of guy. Did what I thought logically should work, so now I'm asking for help. Any thoughts or suggestions would be greatly appreciated!

Have a great day.
# Remove previous week's backup (MONDAY 11:50pm)

50 23 * * 1 /bin/rm -f /var/www/monday.tar.gz
 

# Backup current day's photos (MONDAY 11:55pm)

55 23 * * 1 /bin/tar -zcpf /var/www/monday.tar.gz /var/www/photos
 

# Delete current day's photo files (MONDAY 11:59pm)

59 23 * * 1 cd /var/www/photos | find . -name '*jpg' | xargs rm -f

Open in new window

0
Comment
Question by:goodie069
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Deepak Kosaraju earned 500 total points
ID: 24384909
Since u are using | some crons dosen't support | so either u can copy the entire command to a file and name it as deletecurrent.sh and call it from cron (or)
replace the above delete command with the following
find /var/www/photos/* -name '*.jpg' - exec rm -rf {} \;
0
 
LVL 14

Expert Comment

by:Deepak Kosaraju
ID: 24384918
let me show the command more clear
find /var/www/photos/* -name '*.jpg' -exec rm -rf {} \;

Open in new window

0
 

Author Closing Comment

by:goodie069
ID: 31581436
Perfect! Worked like a charm. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now