Find file using date appended to file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find file using date appended to file name
# 1  
Old 07-13-2009
Question Find file using date appended to file name

The script below is a backup script I wrote.
It Tars and gzips files and move them to backup folder.
It appends the current date of action to the name of the .tar.gz file

echo “Taking Domain Backup...”
hostname
echo “Tarring internetprod”
sleep 2
cd /usr/web/bea/projects/domains
tar -cvf internetprod_`date “+%d%b%Y”`.tar internetprod
echo “Zipping internetprod”
sleep 2
gzip internetprod_`date “+%d%b%Y”`.tar
echo “Moving internetprod_date.tar.gz to Backup folder”
sleep 2
mv internetprod_`date “+%d%b%Y”`.tar.gz /usr/weblogic/Backup

what I want to do now is to reverse the process in case there is a disaster.
i want to be able to loop through the files in the backup filder and identfy the most current file by the appended date, move it to /usr/web/bea/projects/domains gunzip and untar it to over write the current internetprod file.

The other option i am considering is to have interractive script, that will request for the date in “+%d%b%Y” format compare it to the dates appended to the file name and gunzip and untar the file to over write internetprod file in the /usr/web/bea/projects/domains folder
can you help?
# 2  
Old 07-13-2009
try:

Code:
file=`ls -trl /usr/weblogic/Backup | tail -1 | awk '{ print $NF}' `
mv  $file /usr/web/bea/projects/domains/ &&  gzip $file && tar -xvf ${file%%.gz}

# 3  
Old 07-13-2009
hi dennis.jacob
thanks for the prompt help you offererd
can you please explain comment your script for me.
it will help a lot.
I have an idea about what it should do, but I want to be sure
# 4  
Old 07-13-2009
Quote:
Originally Posted by dennis.jacob
try:

Code:
file=`ls -trl /usr/weblogic/Backup | tail -1 | awk '{ print $NF}' `
mv  $file /usr/web/bea/projects/domains/ &&  gzip $file && tar -xvf ${file%%.gz}


ls -trl /usr/weblogic/Backup | tail -1 will sort the files on mtime and pick the most recent one

| awk '{ print $NF}' ` will give the filename on a long list

mv $file /usr/web/bea/projects/domains/ moving the file.tar.gz

&& gzip $file && tar -xvf ${file%%.gz} if the above one is successful, unzip the tar ball and if that is successful, extract the tar
# 5  
Old 07-13-2009
thanx,
the files currently in the backup folder saved in this format
internetprod_08Jul2009.tar.gz
internetprod_09Jul2009.tar.gz
internetprod_10Jul2009.tar.gz
internetprod_11Jul2009.tar.gz
internetprod_12Jul2009.tar.gz
and what I want to do is select the most current using the most current date appended to internetprod_. in this case the most current is internetprod_12Jul2009.tar.gz
looks like your script is using mtime the file was last modified.
I want to avoid this because, if anyone should temper with any of the files, the script may consider it as most current.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy or cut specific rows from appended file with some conditions

Hi I have one file which is containing about 5000 rows and 20 columns I will just explain about my requirement here briefly with sample file, I have attached also, please help....me.. 1 28.25 36.42 5 28.26 36.42 10 28.23 36.43 15 28.22 36.43 20 28.2 36.42 25... (6 Replies)
Discussion started by: nex_asp
6 Replies

2. Shell Programming and Scripting

awk print re-direction to a file with timestamp appended

Hello I need to split big xml file into multiple files based on xml declaration. for that i have written one awk 1 liner as below awk '/<?xml\ version/{i++}{print > "outfile."i}' test123.xml this is producing the desired out put. but i want the the currenttimestamp with milliseconds in the... (3 Replies)
Discussion started by: dsdev_123
3 Replies

3. UNIX for Dummies Questions & Answers

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
Discussion started by: johannd
7 Replies

4. Shell Programming and Scripting

Move txt file to with current date appended to filename

I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>" So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Discussion started by: johannd
1 Replies

5. Shell Programming and Scripting

Adding Header and Trailer records to a appended file

How can we a shell script and pass date parameters .I have 3 files comming from Datastage with |" delimited I need append 3 files as above: File1: P0000|"47416954|"AU|"000|"INS|"0000|"|"20060601|"99991231|"|"|"|"|"01 File 2:... (2 Replies)
Discussion started by: e1994264
2 Replies

6. Shell Programming and Scripting

find date in name of file

hlow i have file like this format: 23312100.2011091617522800CF5253.DAT so i want get date (yyyymmdd) for rename again this file like this 20110916.DAT how can i do that any idea about using awk with regex thx before (1 Reply)
Discussion started by: zvtral
1 Replies

7. UNIX for Dummies Questions & Answers

shell scripts - create a filename with the date appended

I am looking to do something where if I created a file named backup,or whatever it would print a name like “backup_Apr_11_2011”. Thanks citizencro (1 Reply)
Discussion started by: citizencro
1 Replies

8. UNIX for Dummies Questions & Answers

Delete lines from a file where data is continously appended

Hello , Is there a way to delete lines from a file where data is continously appended to the file. I can use normal vi command ndd to remove n number of lines from the file, as the data is continously appended the line numbers doesnt work. (1 Reply)
Discussion started by: sophos
1 Replies

9. Solaris

Find a file and xarg mv to append date to file

Hello All, What I would like to do is search for a file and then run a mv command to rename the file to have todays date appended to it. The find when I run it finds eight or so files and I would like to append a date stamp to each file. If possible using one line command would be great. Can... (6 Replies)
Discussion started by: jacktravine
6 Replies

10. UNIX for Dummies Questions & Answers

How to copy set of files with date appended to their name

Hi gurus, I have set of files in a directory ex : test_file1.csv test_file2.csv test_file3.csv my requirement is to copy these files into another directory but with date appended to the name : like after copying the files should look like : test_file1_07072008.csv ... (7 Replies)
Discussion started by: sish78
7 Replies
Login or Register to Ask a Question