Zip a directory based on its age


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zip a directory based on its age
# 1  
Old 10-21-2012
Zip a directory based on its age

I had allot of help with the below script, and its been a long time since i've done anything with shell scripts so I am having some trouble.

I am trying to zip the trace folder after it is copied and dated but i'm unsure of how to tell it to zip this new folder without knowing what it will be named.

The script works fine as it is now but when it goes to remove the oldest backup it takes forever due to all the files and directories within the trace folder.


Code:
c=$(ls -1 /backup/f1/ |grep -v 1f1 |wc -l)
if (("$c" >= 25))
then
f=$(ls -tr /backup/f1/ |grep -v 1f1 |head -n 1)
rm -r "/backup/f1/$f"
fi
DATE=$(date)
cp -r /lc/trace "/backup/f1/trace${DATE}"

# 2  
Old 10-21-2012
You can first tar the trace folder (choose your name for tar file):-

Code:
tar -cvf /tc/trace.tar /lc/trace

then you can gzip the tar file:-

Code:
gzip /lc/trace.tar

# 3  
Old 10-25-2012
Quote:
Originally Posted by bipinajith
You can first tar the trace folder (choose your name for tar file):-

Code:
tar -cvf /tc/trace.tar /lc/trace

then you can gzip the tar file:-

Code:
gzip /lc/trace.tar

Thanks for the reply. With a few additions including this everything is working smoothly. Appreciate the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and copy .zip file based on today's date

Hi Team, I'm new to unix and i have a requirement to copy or move files from one directory to another based on current date mentioned in the .zip file name. Note that i need to copy only the recent zip file. please help me with the code i tried the code as: #! /usr/bin/sh find... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

Zip a file without directory

Hi I was trying to zip some file in a directory using the below command. find /dir1/dir2/ -name "asdf*.txt" -print | zip -m /dir1/dir2/dir3/asd_Date.zip -@ Its getting zipped.But when I am trying to unzip, Its getting unzipped with full directory structure. Is there any command... (1 Reply)
Discussion started by: ginrkf
1 Replies

3. Shell Programming and Scripting

Command to zip a directory

Hi , How to compress the entire directory . Rajesh (1 Reply)
Discussion started by: guddu_12
1 Replies

4. UNIX for Dummies Questions & Answers

Zip all files in a directory and move to another directory

Hi, need to zip all files in a directory and move to another directory after the zip.. i am using this one but didnt help me... zip -r my_proj_`date +%Y%m%d%H%MS`.zip /path/my_proj mv in_proj_`date +%Y%m%d%H%M%S`.zip /path/source/ i am trying to zip all the files in my_proj... (0 Replies)
Discussion started by: dssyadav
0 Replies

5. UNIX for Dummies Questions & Answers

Zip files inside the directory, but not the directory itself

Hi, Im facing a problem that im stucked, I have the following structure: thales@pereirtc-vbox:/home/VfARM$ ls code config doc lib manifest.bak manifest.rel manifest.v3 ns pub if i try to execute zip -q -o arm.zip VfARM/* it will create a zip file with the folder VfARM.... (2 Replies)
Discussion started by: Thales.Claro
2 Replies

6. UNIX for Dummies Questions & Answers

how to zip the entire directory

my first question is how to zip the entire directory contents. second question is can we unzip the same file through windows environment. please help i need to complete it by EOD (3 Replies)
Discussion started by: bbc17484
3 Replies

7. Shell Programming and Scripting

Zip all files in a directory

I have two files in a directory: xxxx.txt xxxx.csv I need to zip both files up but the command I am doing below is only zipping xxx.txt file????: cd ../$CUSTOMER_DIRECTORY zip -q ${name}${FILE_OUT_NAME}.zip ls -lrt *.csv *.txt can anyone help?:confused: (3 Replies)
Discussion started by: Pablo_beezo
3 Replies

8. UNIX for Advanced & Expert Users

zip unix directory

what's the best command to zip up the whole unix directory, then ftp this to windows for viewing the directories/files. thank you (1 Reply)
Discussion started by: venhart
1 Replies

9. Shell Programming and Scripting

assign zip directory to variable

I'm running an sh shell that is unzipping some zip files that have a directory structure on them. Is there a way I can find the top level directory in the zip file and assign that to a variable? mike (5 Replies)
Discussion started by: skwyer
5 Replies

10. Shell Programming and Scripting

Script for tar and zip based on month & year

Hi Friends, I'm doing on script which finds all the files with time stamp and makes them tar and zip, based on their respective month&year. for instance "mar-2004.tar.zip" will contain all the files which was created/accessed/modified on mar-2004. like this the entire filesystem should be taken... (1 Reply)
Discussion started by: tuxfello
1 Replies
Login or Register to Ask a Question