LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-23-2013, 12:52 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129

Rep: Reputation: 17
tar files that are more than x days old & dir with spaces


I have been struggling with this for a few days and need some divine assistance.
I have a requirement to read a cifs share folder, any files in the folder/subfolder(s) that are more than six days old need to be zipped and moved to an achieve location then removed ... caveat is that the integrity of the folder structure must be maintained even if folder is empty. NO folder deletion!!
Oh, and some folder names have spaces in them so have to allow for that.

here is what I have tried thus far:
Code:
find /mnt/bus_pc/phoesb04/Salvage -type f -mtime +6 | xargs -d "\n" tar -czvPf /mnt/midtier_logsarchive/phoesb04/Salvage/Salvage_`date -d "yesterday" +%Y%m%d`.tgz
seems to work on the spaces in the folder, however, it only tar/zip the last folder processed.

I copied the cifs to local to work on and see if it was something to do with the cifs being actively connected to Biztalk environment.

Code:
tar -czvPf ~/PolicyService_`date -d "yesterday" +%Y%m%d`.tgz /tmp/bus_pc/phoesb04/PolicyService/
works!!
but when I ran the above script pointing to the local copy, same results as when on the cifs.
Code:
find /tmp/bus_pc/phoesb04/PolicyService -type f -mtime +6 | xargs -d "\n" tar -czvPf ~/PolicyService_`date -d "yesterday" +%Y%m%d`.tgz;
only last dir processed

Code:
 
 find /mnt/bus_pc/phoesb04/PolicyService -type f -mtime +6 -exec tar -czvPf ~/PolicyService_`date -d "yesterday" +%Y%m%d`.tgz {} \;
only last dir processed

shouldn't be this difficult so what am I missing here. Thank you!
 
Old 08-23-2013, 01:10 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
with your last one , change the \; to +

that will pass all results to tar once (at the end), instead of executing tar for each line

Last edited by Firerat; 08-23-2013 at 01:11 PM.
 
1 members found this post helpful.
Old 08-23-2013, 01:58 PM   #3
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129

Original Poster
Rep: Reputation: 17
Code:
find /mnt/bus_pc/phoesb04/PolicyService -type f -mtime +6 -exec tar -czvPf ~/PolicyService_`date -d "yesterday" +%Y%m%d`.tgz {} +
did not work ... same results. ty
 
Old 08-23-2013, 02:07 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
i tested it and it did work for me.
 
Old 08-23-2013, 02:24 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
To maintain the directory structure you must search for directories independently from their modification time. To manage blank spaces in file or directory names use -print0 and the matching option -0 of xargs. In addition use --no-recursion otherwise directories will be archived twice (the find command already does recursion so you have to avoid that tar do the same). Maybe something like this is what you're looking for
Code:
find /mnt/bus_pc/phoesb04/PolicyService \( -mtime +6 -type f -o -type d \) -print0 | xargs -0 tar --no-recursion -czPf ~/PolicyService_`date -d "yesterday" +%Y%m%d`.tgz
 
1 members found this post helpful.
Old 08-23-2013, 03:06 PM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by j-me View Post
Code:
find /mnt/bus_pc/phoesb04/PolicyService -type f -mtime +6 -exec tar -czvPf ~/PolicyService_`date -d "yesterday" +%Y%m%d`.tgz {} +
did not work ... same results. ty
odd, it _should_ work..

anyway, I think colucix's is much better, since it has the empty dir which I missed
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar dir and sub dir removing files but not existing not empty dir j-me Linux - General 2 08-12-2013 11:37 AM
[SOLVED] Command to copy files older than <n> days keeping dir structure. MoonMan89 Linux - General 4 07-15-2010 10:28 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 02:49 AM
un tar all files in dir Longinus Linux - Newbie 6 03-18-2004 12:33 AM
Bash script (untar *.tar files and then cd to the untared dir) k0ljat Linux - Newbie 2 12-30-2003 05:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration