Remove files from tar archive which are more than 1000 days old.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove files from tar archive which are more than 1000 days old.
# 1  
Remove files from tar archive which are more than 1000 days old.

I am not able to extract/remove files older than 1000 days from a tar archive in linux system.
Code:
       #!/usr/bin/perl   
            @file_list = `find /home/x/tmp/ -name *xxMsg* -ctime +7`;   
            $file_name = '/home/x/tmp/new_archive.tar';   
            for ($count=0;$count<@file_list;$count++)    {     
               if( -e $file_name)    {      `tar -rvf $file_name @file_list[$count] --remove -files 2> /dev/null`;      }
                 else {   
               `tar -cvf $file_name @file_list[$count] --remove -files 2> /dev/null`;     
               }  
           }

Above is my code to create a tar file. We run this script every end of day to archive the files in directory /home/x/tmp/ Also, I have another requirement to purge files from this tar which are 1000 days older. My doubt is, how to find out the files in the tar archive which are older than 1000 days.
Please advise the optimal solution to achieve this. Appreciate your solutions.
Thanks in advance

Last edited by DannyV; 05-27-2013 at 03:15 PM..
# 2  
The very first problem is that you do not create a relative tar archives:

You did this:
Code:
tar -cvf /path/to/my/file.tar /home/foo

Instead of this
Code:
cd /
tar -cvf /path/to/my/file.tar ./home/foo

Note the leading red dot.

To do what you ask, one way to do this extract a relative tar archive to some harmless disk somewhere, delete the file(s) you no longer want, then rebuild the archive. Note that most places do not do things this way, it is very cumbersome. Rather, there is a backup plan, and incremental backups made, say every day of the month. A full back up is made at month end. Then last month's incrementals are overwritten day by day.

You keep the month end backups and one month of incremental backups. We cycle on a 90-day basis, not 30.

If you had relative tar files (you don't) you could try something like this:
Code:
cd /someplace/harmless
tar xvf /path/to/file.tar
find . -type f -mtime +1000 -exec rm {} \;
tar cvf /path/to/file.tar ./
cd ..
rm -R ./harmless    # lose the files you restored
mkdir ./harmless

 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #271
Difficulty: Easy
While working at Bletchley Park, in the first week of June each year Alan Turing would get a bad attack of hay fever, and he would cycle to the office wearing a service gas mask to keep from breathing pollen. In the first week of June each year he would get a bad attack of hay fever, and he would cycle to the office wearing a service gas mask to keep from breathing the pollen.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with number of files in a tar archive

I cant seem to work out how to count the number of executable files in a particular tar archive? Only in a directory as a whole. I also cant work out how to count number of certain file types in a tar archive. Only the directory, pretty stuck :( (9 Replies)
Discussion started by: Razor147
9 Replies

2. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

3. Shell Programming and Scripting

Need script to tar files older than 30 days

Hi all. Here's my situation: I have performance reports that run every 30 minutes saved in the format: stats_report_11251000.txt stats_report_11251030.txt stats_report_11251100.txt stats_report_11251130.txt (Obviously run at Nov 25 10 AM, 10:30 AM, 11 AM and so on...) I would... (2 Replies)
Discussion started by: jamie_collins
2 Replies

4. UNIX for Dummies Questions & Answers

Count number of compressed files in a tar.gz archive

Hi Folks, I have a tar.gz compressed file with me, and I want to know the number of files in the archive without uncompressing it. Please let me know how I can achieve it. Regards RK Veluvali (5 Replies)
Discussion started by: vrk1219
5 Replies

5. Shell Programming and Scripting

How to tar, compress and remove files older than two days

Hi, I'm Eddy from Belgium and I've the following problem. I try to write a ksh script in AIX to tar, compress and remove the original *.wav files from the directory belgacom_sf_messages older than two days with the following commands. The problem is that I do not find a good combination... (4 Replies)
Discussion started by: edr
4 Replies

6. Solaris

Find files older than x days and create a consolidated single tar file.

Hello, I need help in finding files older than x days and creating a single consolidated tar file combining them. Can anyone please provide me a script? Thanks, Dawn (3 Replies)
Discussion started by: Dawn Bosch
3 Replies

7. UNIX for Dummies Questions & Answers

tar archive with including specific patern files

Hi, I need to create recursive tar archive, while I put there only files of type a*.txt. Without file filtering the command is: tar cfzf test.tar.gz test_tar/ How I include the switch for including only files with pattern a*.txt ? Thanks a lot! (1 Reply)
Discussion started by: john.gelburg
1 Replies

8. UNIX for Advanced & Expert Users

deleting files after the creation of a tar archive

Hi, I would modify to delete the files after creating the tar archive. How I can modify the following command: tar -cvvf logswitch.tar `find *.log* -mtime +5` It create a tar with files that are older than 5 days. (5 Replies)
Discussion started by: Minguccio75
5 Replies

9. UNIX for Dummies Questions & Answers

tar archive with .Z files

Hello, I have a tar archive full of compressed .Z (compressed with the compress command) files. I have restored the tar to a disk but am looking for a way to uncompress every file in every sub-directory. Under normal circumstances, I would just change directories and "uncompress *" but with 1600... (3 Replies)
Discussion started by: Kun2112
3 Replies

10. UNIX for Dummies Questions & Answers

tar files older than 30 days

Hi there, I am trying to tar a number of files held in a specific folder. I am only interested in archiving files older than 30 days. Having read through the man entries and all available documentation I thought I'd cracked the coomand with tar -c -z -v -N 15/04/2004 -f /wfch.tar * This... (6 Replies)
Discussion started by: wfch
6 Replies

Featured Tech Videos