archiving equal sets of files from directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting archiving equal sets of files from directories
# 1  
Old 04-06-2008
archiving equal sets of files from directories

Good morning.

I am trying to write a script on SunOS that will tar up files from a set of directories. This is no problem, but what I need to do is to create 3 different archives each containing a third of the files from a particular sub-directory.

So if I have a directory structure:

masterdir

-0
--dir
---dir
----0
----1
----2
----3

-1
--dir
---dir
----0
----1
----2
----3

-2
--dir
---dir
----0
----1
----2
----3

So I have a directory with 10 subdirectories labeled 0-9 and in each one a series of subdirectories labeled 0-1000 containing a series of files.

I need to create archives with identical directory structures and each one containing approximately 1/3 of the files from each leaf directory.

Any suggestions on the best way to accomplish this?

Thanks in advance
# 2  
Old 04-06-2008
Is the list of files stable, or might new files appear while you are processing the files you have so far?

I would try to come up with a system for dividing the files (maybe just a simple grep expression) and once you are satisified with that, feed it to | xargs tar cf -

If you have numeric file names, you could simply sort by the last digit modulo three. If the list of files doesn't change, you could even just categorize by line number within the list, but then you won't get the same files next time you run this on a set of files which is almost, but not quite identical.

Code:
awk 'NR % 3 == 0'  list>set1
awk 'NR % 3 == 1' list >set2
awk 'NR % 3 == 2' list >set3

Here, I suppose you could have run a find command to generate the file list -- if the list of files will not change while you are doing this, you could re-run find three times, if you want to avoid using a temporary file.

Code:
for m in 0 1 2 ; do
  find -what -ever | awk -v m=$m 'NR % 3 == m' | xargs tar cf tar$m.tar
done

Instead of tar, you could run it with wc to see that the number of files is roughly similar for all three runs, before you proceed to actually tar them up.

There may be architectures where xargs or tar are too crippled for this, but if you can use this, it's simple and straightforward.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

2. Shell Programming and Scripting

Archiving the files

hi, Am trying to acrhive a bunch of files on some ftp site and somehow managed to come out with the below logic. I'm getting "syntax error: unexpected end of file" error. Interestingly this below snipeet works fine if run for the first time but the subsequent runs fail! Anybody has any idea... (3 Replies)
Discussion started by: Amee5
3 Replies

3. Shell Programming and Scripting

Archiving older files

Hello Group, I would request your help to build a shell script in order to find files older than 90 days then create the same directory structure under the second disk (/archive directory) and move the file preserving the same timestamps (ownership, etc). Also keep the log of files moved... (4 Replies)
Discussion started by: csierra
4 Replies

4. Shell Programming and Scripting

Issue while archiving the files

Hi, In our current process we are reading the file, (which is placed by external vendor)from one particular folder and processing those files through ETL(informatica). We are reading these file as " ls -ltr *.txt" Once the process is finish these files are moved to archived script by "mv"... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

5. Shell Programming and Scripting

Archiving the Files in a folder

My requirement is to put all the files from output directory(ATT) to archive directory(archive\) creating a new folder with datetimestamp(20100212_120014) every time it runs. where ${IMF_TARGET_DIR} is my base directory. ${IMF_ARCHIVE_DIR} is my Archive directory... (1 Reply)
Discussion started by: vsmeruga
1 Replies

6. Shell Programming and Scripting

Files common in two sets ??? How to find ??

Suppose we have 2 set of files set 1 set 2 ------ ------ abc hgb def ppp mgh vvv nmk sdf hgb ... (1 Reply)
Discussion started by: skyineyes
1 Replies

7. Shell Programming and Scripting

Archiving the files

Hi, Suppose I have 2 files of yesterday's. And today I have received 3 files. Before processing anything I want to archieve the 2 files of yesterday's into a different folder. How can this be done? Regards, Sunitha (1 Reply)
Discussion started by: Sunitha_edi82
1 Replies

8. Virtualization and Cloud Computing

Clouds (Partially Order Sets) - Streams (Linearly Ordered Sets) - Part 2

timbass Sat, 28 Jul 2007 10:07:53 +0000 Originally posted in Yahoo! CEP-Interest Here is my follow-up note on posets (partially ordered sets) and tosets (totally or linearly ordered sets) as background set theory for event processing, and in particular CEP and ESP. In my last note, we... (0 Replies)
Discussion started by: Linux Bot
0 Replies

9. Shell Programming and Scripting

Archiving and moving the files

hi all i have a requirement where in i have to zip all the files with "*.bkp" after 14 days and move the zip files to Archive directory .... i am able to achieve the first functionality but not able to achive the second one ...here is my code find ${LOG_DIR} -name "*.bkp" -mtime +14 | xargs -i... (1 Reply)
Discussion started by: nvuradi
1 Replies
Login or Register to Ask a Question