The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Backup my files to DAT jefferson UNIX for Dummies Questions & Answers 1 09-30-2007 07:13 PM
Counting Files and send an email Notification if it exceeds a limit amitsayshii UNIX for Dummies Questions & Answers 10 07-07-2006 07:25 AM
backup files for a specific month problems Shell Programming and Scripting 3 04-28-2006 12:53 AM
limit to number of files in a given directory hedrict UNIX for Advanced & Expert Users 2 02-05-2004 01:14 PM
limit of files in the ufs filesystem witt UNIX for Dummies Questions & Answers 2 06-25-2002 07:02 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-30-2003
Registered User
 

Join Date: Sep 2003
Posts: 11
Limit backup files

Hello all,

I am building a shell script. Every morning my shell script will trigger an external system backup script and the backup file (File Name format: "20030929backup.bkp" (i.e)current date + "backup.bkp") will be stored in the backup directory. After successful back, I need to keep only 10 backup files in the backup folder at most. Say on 11th day, day 1 file should be deleted and the 11th day file should be created. What's the best way to do this?

I am using the below command to get the list of backup files from backup directory.
$ find /home/EBI -name "*.bkp" -exec ls {} \;

We need to calculate the calendar days.

I thought of using (-atime +10) but, the thing is this backup script will not run on Sundays. So we miss one day... I guess we may need to count the number of backup files, find the oldest one, delete it and add the current file. What's the simple way to do this?

Thanks.
Forum Sponsor
  #2  
Old 09-30-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Try this:

rm `ls -tr *.bkp | head -1`
  #3  
Old 09-30-2003
Registered User
 

Join Date: Sep 2003
Posts: 11
But, how do I count 10 backup files? and if it exceeds 10 then your command will work to delete the oldest file.

Thanks
  #4  
Old 09-30-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
I thought that you wanted to delete the oldest file. At this point I don't know what you want. But I'll take a stab at this anyway...

You can count backup files with:
ls *.bkp | wc -l

And this technique will indeed work if you happen to have 10 backup files.
  #5  
Old 10-01-2003
Registered User
 

Join Date: Sep 2003
Posts: 11
Thanks Perderabo. It worked.
  #6  
Old 10-01-2003
Registered User
 

Join Date: Sep 2003
Posts: 11
Also, I am trying to send an e-mail notification at the end of this script and I am using

$ /usr/lib/sendmail -v toname@name.com < /home/lognotes.txt

How do I specify the subject field?

Also, Is there a way I can type the message body instead of sending the log file from the command itself. Just simple one line command with "Subject", "To", "message body"

I want to send an e-mail like this:
*******************************************
From: from@name.com
To: toname@name.com
Subject: Notification
Message Body: Backup Success
*******************************************

Please help,

Thanks,
-Jai
  #7  
Old 10-01-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
You need to use a user agent rather than calling sendmail directly. Or you need to make your script smart enough to actually be a user agent.

You may have user agents named things like elm or mailx. I would use mailx and then the subject is specified with -s.
Google The UNIX and Linux Forums
Closed Thread

Tags
mailx, mailx attachment, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0