Sponsored Content
Top Forums Shell Programming and Scripting Need help to tar and gzip files per date Post 302581279 by Corona688 on Monday 12th of December 2011 03:12:45 PM
Old 12-12-2011
You still haven't told me what your system is, which rules out many solutions I've thought of.

How about this:

Code:
find / -type f -mtime +90 -name "*.log*" |
        awk -F/ '{ split($NF, A, "_"); F[A[1]]=F[A[1]]"|"$0 }
        END     {       for(X in F)     print X F[X];   }' |
while read LINE
do
        # Split in the shell so $1 is the date, $2 ... $N are filenames.
        set  -- $LINE # LINE must NOT be quoted!
        DATE="$1"
        shift # Get rid of $1, so $1...$N-1 are all filenames.  This lets us feed them into tar with "$@"
        echo tar -zcf "$DATE.tar.gz" "$@"
done

Running it on local files here gives me:
Code:
tar -zcf 2011-12-08.tar.gz ./2011-12-08_001334.log ./2011-12-08_001334.logaccount_ptr ./2011-12-08_001334.loginitial_ptr ./2011-12-08_001334.logptr ./2011-12-08_235901.log ./2011-12-08_235901.logaccount_ptr ./2011-12-08_235901.loginitial_ptr ./2011-12-08_235901.logptr
tar -zcf 2011-12-09.tar.gz ./2011-12-09_235916.log ./2011-12-09_235916.logaccount_ptr ./2011-12-09_235916.loginitial_ptr ./2011-12-09_235916.logptr
tar -zcf 2011-12-10.tar.gz ./2011-12-10_235900.log ./2011-12-10_235900.logaccount_ptr ./2011-12-10_235900.loginitial_ptr ./2011-12-10_235900.logptr
tar -zcf 2011-12-11.tar.gz ./2011-12-11_235900.log ./2011-12-11_235900.logaccount_ptr ./2011-12-11_235900.loginitial_ptr ./2011-12-11_235900.logptr

Remove the 'echo' once you've tried a dry run and you're sure it will be creating the archives you want.

find /path/to/files would be far more efficient than find / by the way, since find / trawls your entire system...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Combine tar and gzip together?

Hello I just wandering, instead to doing "tar cvf foo.tar * " and then gzip foo.tar , can't it be combined to one command ? (1 Reply)
Discussion started by: umen
1 Replies

2. UNIX for Dummies Questions & Answers

can i tar and gzip in one liner ?

hello can i combine this 2 commands in one liner command? (1 Reply)
Discussion started by: umen
1 Replies

3. UNIX for Dummies Questions & Answers

TAR and GZIP help

Hi, There are 700 .pdf files in a certain directory on the server and I need to TAR them first and then compress them using GZIP to free up the space. The combined size of the .pdf files is 3gb. However, there is only 1gb of free space on the server. So as you can see when I try to TAR these... (3 Replies)
Discussion started by: VandeMatram
3 Replies

4. UNIX for Advanced & Expert Users

tar/gzip/gz...which one to use?

P0251WLADC.svm_wl1 > /svm_wl1/billing/data/server/archive/ALLEVT $ du -k FEB2006 22050224 FEB2006 As you can see,i have a folder called "FEB2006" which is around 22 GB. i guess zip or compress wont work...( i don know how do we compress a folder) i wished to use ""tar" ( i suppose... (5 Replies)
Discussion started by: abhijeetkul
5 Replies

5. UNIX for Dummies Questions & Answers

tar and gzip

Hi, I would like to have a combined gzip and tar that will compress and create multiple output tar.gz files. I want to have multiple files output because i cannot create an archive because there is no more space on my harddisk. I cannot transfer it locally because of slow connection. I want to... (3 Replies)
Discussion started by: tungaw2004
3 Replies

6. Shell Programming and Scripting

tar + gzip + split together

Hi All I need guidance on this requirement . We have a directory structure which has data of approx 100 GB We need to tar the structure then zip it and create different files of not more than 10 GB A separate tar file then a .gz should not be created , on the fly a script is needed... (7 Replies)
Discussion started by: aamir1234
7 Replies

7. Shell Programming and Scripting

tar files by date

Hi, I have a solaris 10, I would like to tar log files by date, or by range of hours into one tar file. All I coud do is by name (very simple...:cool:). (4 Replies)
Discussion started by: pointer
4 Replies

8. UNIX for Dummies Questions & Answers

Create Tar and GZip files under Unix

Hi All I have 2 tar files and inside a Gzip file (actually its folder) that i got from a Unix user to check the code for him and find some problem. I decompress the Tar file and use 7-ZIP to open the Gzip file and Extract all folders and files. I found the code problem and change it but now when... (1 Reply)
Discussion started by: giladboker
1 Replies

9. Shell Programming and Scripting

tar and gzip files

Hi Guys, I am using RHEL5 and Solaris 9 & 10. I want to tar and gzip my files then remove them after a successful tar command... Lets say I have files with extension .arc then I want to tar and gzip these files. After successful tar command I want to remove all these files (i.e .arc). ... (3 Replies)
Discussion started by: Phuti
3 Replies

10. Red Hat

Tar with particular date files

I need to find out only Jun 10 created and modified file with tar command ,, I am using Linux red hat x86_64 GNU/Linux. ls -lrt -rw-r--r-- 1 nova nova 2757 Jun 7 11:00 feed.ctl -rwxrwxr-x 1 nova nova 457 Jun 7 11:00 acc_feed.csh -rwxr-xr-x 1 nova nova 473 Jun 7 12:11... (2 Replies)
Discussion started by: balajikalai
2 Replies
BF_TAR(1)																 BF_TAR(1)

NAME
bf_tar - shell script to write a tar file of a bogofilter directory to stdout SYNOPSIS
bf_tar [-r] [-R] bogofilter_directory DESCRIPTION
bf_tar bundles a bogofilter working directory in tar format and copies it to standard output (your console, or where you redirect it, see EXAMPLES below). OPTIONS
The -r option causes bf_tar to remove inactive log files after the archive has been written successfully. The default is to leave log files. The -R option causes bf_tar to remove inactive log files before the archive is written. This may reduce chances that the resulting archive is recoverable should it become damaged. The archive may be smaller though. The default is to leave log files. EXIT STATUS
The script exits with status code 0 if everything went well, and nonzero if it encountered trouble. EXAMPLES
o bf_tar ~/.bogofilter > outfile.tar Writes a standard .tar file containing the essential files from ~/.bogofilter to outfile.tar. o bf_tar ~/.bogofilter | gzip -9 -c > outfile.tar.gz Writes a gzipped .tar.gz file containing the essential files from ~/.bogofilter to outfile.tar.gz. o bf_tar `pwd`/mydirectory > outfile.tar Prepend $(pwd)/ or `pwd`/ if you want to specify an absolute path instead of a relative path. NOTES
This script is meant for use with Berkeley DB based bogofilter versions. This script requires a SUSv2 compliant pax utility. This script expects a SUSv2 compliant shell. Solaris systems should have the SUNWxcu4 package installed (when bogofilter is configured) so that /usr/xpg4/bin/sh can be used. 07/23/2007 BF_TAR(1)
All times are GMT -4. The time now is 10:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy