Need command/script to archive files older than


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need command/script to archive files older than
# 1  
Old 12-14-2017
Need command/script to archive files older than

I need to find a way to archive all files older than a given date but there are some conditions that are making it difficult for me to find the correct command:

Linux based system (RH5)
  • there are multiple layers of directory depth I need to search
  • each file should be tar'd in it's original location in the directory
  • original file removed of course (this is a space issue)
  • tar files should achieve max compression
  • Cannot simply delete any files, records have to be maintained

Now personally I would prefer to pull all files from say July 2015 into a singe tar, max compress, and simply write a script that the web app can call to search the tar files and extract if needed.

---------- Post updated at 12:55 PM ---------- Previous update was at 11:53 AM ----------

I should have said I would prefer to do one big tar file but I'm being told I can't by management and customer.
# 2  
Old 12-14-2017
If you do not compress the tar file it makes no sense to tar at all. A tar archive can be slightly larger than the original file. One single file per tar is pointless as well. Just compress the file. It becomes unreadable.

What you want to do, minus some details:
Code:
# find files in select directories:
# you need a file with directory names, call it dirnames, create one
while read dir
do
      # -mtime  180  finds files older than 180 days, change it to what you want in days 
      # the name excludes already zipped files.
      find "$dir" -type f  -mtime +180 ! -name '*.gz' -exec gzip {} \;    
done

If you absolutely have to have a single file in tar format archive change the above -exec command to get whatever.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shellscript command to remove files starting with a certain string, and older than 3 days

Hi All, Need help in identifying a shellscript command to remove all files on a server directory, starting with a certain prefix and also older than 3 days. That means files created with that prefix, today or yesterday, shouldn't be removed. Thanks, Dev (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

Command to find files older than 1 hour

Hi, Out of a list of files in a directory, I want to find the files which were created/modified more than 1 hour ago. I am using HP -UNIX and it does not support the argument -mmin. Please advise. I am using # !/bin/sh (4 Replies)
Discussion started by: jhilmil
4 Replies

3. Shell Programming and Scripting

How archive the older than 30 day files to another unix server

I need to archive the older than 30 day file to another uinx server.I have wrote the below uinx script. for LOOK_DIR in /TempFiles do for FILE in `find ${LOOK_DIR} -mtime -30 -exec ls {} \;` do echo ${FILE} >> file_list ## This file will have the list of files copied and... (12 Replies)
Discussion started by: murari83.ds
12 Replies

4. Shell Programming and Scripting

find command to filter specific type of files older than certain date.

Hi I need to find the list of files in a directory and to do some specific operations based on the type of files. suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months. i used the below query but the... (2 Replies)
Discussion started by: msathees
2 Replies

5. Shell Programming and Scripting

Finding older files using find command

Hi All, I want to find files which are older than 15 days. I have written a command as below, find -mtime +15 -print I understand (System date - last modified time of a file) should be greater than or equal to 15 days. This command returns files which are 15 days old.. i.e... (1 Reply)
Discussion started by: nshan
1 Replies

6. Shell Programming and Scripting

Command to Count the files which is Older than 3 months?

Hi Gurus the count of files in a particular Directory... ls -lrth | grep -c ^- can any one share the command to Count the files which is Older than 3 months So please help me out in this Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

7. UNIX for Advanced & Expert Users

how to archive logs older than 5 days & then delete them?

My code is tar -cvf logs.tar `find /usr/openv/logs/512*.log -mtime +2` && find *.log* -mtime +2 -exec rm {} \; this gives me output as: tar: Missing filenames:confused: (1 Reply)
Discussion started by: timus1980
1 Replies

8. Shell Programming and Scripting

unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input. (6 Replies)
Discussion started by: Presanna
6 Replies

9. Shell Programming and Scripting

Archive script old files

Hi All, Im trying to write a script to archive files based on the date the files were created. For example, if a group of files were created on 23rd August,I would have 230806.tar. I have a problem,I want the script to read a separately created file(readarchive.txt) to look for the path to... (1 Reply)
Discussion started by: kayarsenal
1 Replies

10. Shell Programming and Scripting

Archive files older than 30days

I have files with the names BARE01_DLY_MKT_20060724 in the source directory /biddf/ab6498/dev/ctl. I need to archive folders older than 30days. Like if i have a file named BARE01_DLY_MKT_20060622 I need to move this to /biddf/ab6498/dev/ctl/archive. How can I do this. One more thing is that I... (8 Replies)
Discussion started by: dsravan
8 Replies
Login or Register to Ask a Question