Hi, I'm doing a 30 day rotational backup using rysnc. If I go to the root of the backup directory and use: du --max-depth=1 -h, it gives me the actual space being taken up by each incremental directory, the space being taken by the current directory, and then the total of all. For example: 44G /Current 1G /06-20-2004 750M /06-19-2004 Etc... Etc.. .. .. 70G Total But what I would like to do is automatically get the size of the last created hard linked directory daily through a script. But in the example above, if I move into one of the sub directories, like /06-20-2004, and run: du -sh, it gives me a total of 44G. This is the size of the actual files including the hard links. I'm looking for the 1G or so figure without having to run du from the root, which understandably takes a long time. Thanks, Max
On Sat, Jun 19, 2004 at 01:55:02PM -0500, Max Kipness wrote:> But what I would like to do is automatically get the size of the last > created hard linked directory daily through a script.Try the attached perl script. It counts the blocks in the arguments you specify (like du does), but it leaves out any files that have more links than the number of instances we find in our scan (i.e. if we find "foo" with a link count of 2 and we run across it again in our scan, we count its blocks; if it had a link count of 3 or more and we only ran across it twice, we'd skip it). ..wayne.. -------------- next part -------------- #!/usr/bin/perl -w use strict; my %hash; # Keep track of multi-linked inodes my $total_blocks = 0; my @todo = @ARGV; push(@todo, '.') unless @todo; foreach my $fn (@todo) { my($inode,$nlinks,$blocks) = (lstat($fn))[1,3,12]; if (-d _) { opendir(DP, $fn) or die $!; push(@todo, map("$fn/$_", grep(!/^\.\.?$/, readdir(DP)))); closedir DP; } elsif ($nlinks > 1) { if (!defined($hash{$inode})) { $hash{$inode} = $nlinks - 1; next; } next if --$hash{$inode}; } $total_blocks += $blocks; } print "$total_blocks blocks\n"; print int($total_blocks / 2 + .5), "K\n"; # Assumes 512-byte blocks
> -----Original Message----- > From: Wayne Davison [mailto:wayned@samba.org] > Sent: Saturday, June 19, 2004 3:22 PM > To: Max Kipness > Cc: rsync@lists.samba.org > Subject: Re: DU and Hard Links? > > On Sat, Jun 19, 2004 at 01:55:02PM -0500, Max Kipness wrote: > > But what I would like to do is automatically get the size > of the last > > created hard linked directory daily through a script. > > Try the attached perl script. It counts the blocks in the > arguments you specify (like du does), but it leaves out any > files that have more links than the number of instances we > find in our scan (i.e. if we find "foo" > with a link count of 2 and we run across it again in our > scan, we count its blocks; if it had a link count of 3 or > more and we only ran across it twice, we'd skip it). > > ..wayne.. >Wayne, that did the trick. Thanks. Max