backup files for a specific month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting backup files for a specific month
# 1  
Old 04-25-2006
backup files for a specific month

i am having a problem with writing a shell script to back up files for a specific month. the month and year are specified as paramters. so a backup of all the files modified during the specified month have to be made. for example if specify 200406 as my parameter, it should back up files that have been modified during the month of june in year 2004

i know u can use the find -atime -n. but it aonly finds files that were accesed within n days. but i would like to find files for a specific month and back it up. need help please

thanks
# 2  
Old 04-26-2006
I think u will need to find the diff of current that with the start and end date of the month u want backup.
and u may use the find . -mtime -60 -mtime +30
-mtime -60,...less than 60 days ago
-mtime +30...more than 30 days ago..
this way u will have to look for yours month duration...
but there should be better ways...may be someone else in group can help
# 3  
Old 04-27-2006
An alternative is to try to match the Month and year in a directory listing - tho the change from "dd Mmm hh:mm" format to "dd Mmm yyyy" when a file gets to six months old complicates this.
I would be a good idea to log the details of files deleted too!

Code:
Code
# note proper parameter validation (e.g. mon between 1 and 12 inclusive)
# script also assumes that you have read/write access to all subdirectories

scriptname=$(basename $0)
if [ $# -ne 3 ]; then
  print "usage: $scriptname MonthNumber YearNumber directory, e.g. '$scriptname 4 2006 /tmp'"
  exit 0
fi

set -A monnames Zero Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
typeset -i mon=$1
typeset -i yr=$2
typeset -i thisyr=$(date +%Y)
typeset -i lastyr=$(($thisyr -1))
typeset -i thismon=$(date +%m)
typeset -i fmon

print "Print Deleting files from ${monnames[$mon]} $yr in directory $3"

find $3 -type f -ls | sed -e's/ *//' | tr -s ' ' | cut -d' ' -f8- | while read fmonname fday fyrtime ffilename
do

# Get month number from month name in file list
  fmon=1
  while :
  do
    if [ $fmonname = ${monnames[$fmon]} ]; then
      break
    fi
    fmon=$(($fmon + 1))
  done

# if the last part of the timestamp is a time rather than a yr then
# we need to find the yr it belongs to

  if [[ $fyrtime = *:* ]]; then

#   if month number is not greater than current month number then it is in this yr ...
    if [ $fmon -le $thismon ]; then
      fyrtime=$thisyr
    else

#     ... otherwise it's last yr
      fyrtime=$lastyr
    fi
  fi

  if [ $fmon = $mon ]&&[ $fyrtime = $yr ]; then
    print "deleting $fname dated $fday $fmon $fyrtime $ffilename"
    -- backup $ffilename somehow --
  fi
done
~

any help?

cheers

Last edited by thestevew; 04-28-2006 at 07:26 AM..
# 4  
Old 04-28-2006
thanks but i wanted to copy the files for a specilfy month. is it possible to search through the directory list for the specific month specified
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Get last month files

Hi All, How to get last month files. Ex : 1st Jan i have to get Dec 31 days files and on Feb 1st i have to get Jan 31 days files and on Mar 1st i have to get Feb 28 days files. Below are the example files with date and timestamp. aaa.txt.timestamp aaa.txt.timestamp aaa.txt.timestamp Please... (7 Replies)
Discussion started by: kiranparsha
7 Replies

2. Shell Programming and Scripting

Three month old specific files deletion

Hi, I need to delete 3 month old files in my logpath. This path contains several logs and other important files The file names are be like this sl_details.env tomcatfiles_03062014.log application_zur_03.062014.log I need to delete only tomcatfiles logs. I wrote this command. can... (7 Replies)
Discussion started by: nag_sathi
7 Replies

3. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

4. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

5. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

6. Filesystems, Disks and Memory

backup of files for a specific date

In Linux Advance server I want to write one script for backing up files for a specific date like 24/07/2008. (3 Replies)
Discussion started by: akm9999
3 Replies

7. Shell Programming and Scripting

backup of files for a specific date

I want to write script for backing up archive logs files for specific date. please give me idea for that. (2 Replies)
Discussion started by: akm9999
2 Replies

8. UNIX for Advanced & Expert Users

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

9. Solaris

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

10. HP-UX

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies
Login or Register to Ask a Question