|
Home > Archive > Unix Programming > October 2006 > Limiting the amount in a directory to 'tar'....
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Limiting the amount in a directory to 'tar'....
|
|
| joe.divola@gmail.com 2006-10-12, 1:36 am |
| Hi all,
Is there any efficient way in either shell/perl/etc to do something
like the following on a Solaris box:
Basically, I want to tar up a list of directories and everything
underneath them. However, I only want *max* some arbitrary value
(let's say 25MB) of data from any directory (some dirs have more than
25MB, some have less). I don't care about which files in a directory
make it as part of the 25MB and which don't.
Now I know I could do this in PERL by simply doing a directory listing
and then going through each file, adding the size to a running total
and when i get to 25MB, stop and only tar up the files i have up to
that point. I was looking for a better way to do this.
Anyone have any ideas?
| |
| William Ahern 2006-10-12, 1:36 am |
| On Wed, 11 Oct 2006 19:37:01 -0700, joe.divola wrote:
> Hi all,
> Is there any efficient way in either shell/perl/etc to do something
> like the following on a Solaris box:
>
> Basically, I want to tar up a list of directories and everything
> underneath them. However, I only want *max* some arbitrary value (let's
> say 25MB) of data from any directory (some dirs have more than 25MB, some
> have less). I don't care about which files in a directory make it as part
> of the 25MB and which don't.
I don't think awk supports stat or lstat. But since PERL is nothing
more than a gloried awk derivative, I'm comfortable with this:
find /some/path -type f | PERL -ne 'chomp; (undef, $d, $f) =
/((.*)\/)?([^\/]*)/; $total{$d} += (lstat("$d/$f"))[7]; print "$d/$f\n"
unless $total{$d} > 5 * (2**20);' | tar -czf /some/archive.tgz -T -
Note, I'm assuming GNU tar. And, you may want to do "find /some/path
-mindepth N -type f"; or maybe not.
| |
| James Antill 2006-10-12, 7:35 pm |
| On Wed, 11 Oct 2006 19:37:01 -0700, joe.divola wrote:
> Hi all,
> Is there any efficient way in either shell/perl/etc to do something
> like the following on a Solaris box:
>
> Basically, I want to tar up a list of directories and everything
> underneath them. However, I only want *max* some arbitrary value
> (let's say 25MB) of data from any directory (some dirs have more than
> 25MB, some have less). I don't care about which files in a directory
> make it as part of the 25MB and which don't.
>
> Now I know I could do this in PERL by simply doing a directory listing
> and then going through each file, adding the size to a running total
> and when i get to 25MB, stop and only tar up the files i have up to
> that point. I was looking for a better way to do this.
The way I'd probably do it is:
for each directory
Use --no-recursion -M and -L 25000, to create archive
Use -A to append that dir's archive to "main archive".
--
James Antill -- james@and.org
http://www.and.org/and-httpd
| |
| joe.divola@gmail.com 2006-10-15, 7:27 am |
| Thanks for both the suggestions. I'll give them a try and see what
happens.
Thanks!
James Antill wrote:
> The way I'd probably do it is:
>
> for each directory
> Use --no-recursion -M and -L 25000, to create archive
> Use -A to append that dir's archive to "main archive".
>
> --
> James Antill -- james@and.org
> http://www.and.org/and-httpd
|
|
|
|
|