On Mon, Aug 10, 2009 at 10:21:58AM -0500, Jay Hall wrote:
> I am sure there is an easy explanation for this, but I cannot find it.
> I am backing up my /etc directory using the following command.
> tar -cvf - /etc | dd of=/dev/nsa1 obs=10240

Why are you using dd? Tar was originally built to write to tape:

tar -cvf /dev/nsa1 /etc

> When the command completes, I receive the following message.
> 3080+0 records in
> 154+0 records out
> 1576960 bytes transferred in 0.179921 secs (8764740 bytes/sec)
> What concerns me is when running du -h /etc, the size of the folder is  
> reported as 1.7M.

du rounds sizes up to the filesystem block size, which is 512 bytes by
default. So you'll bound to see differences. And see below.
> Is the number of bytes written to the tape less than the reported size  
> of the directory because of the way the files are written to the  
> tape?  If so, how can the amount of space used be calculated?
The fact that you are using tar also plays a part. Tar has some overhead to
store information about the files it contains.

If you want to know the total size of all files:

find /etc -type f -ls | awk \
'BEGIN {t=0; c=0}; END {print t " bytes in " c " files"}; {t=t+$7; c++}'

This returns '1320254 bytes in 362 files' in my case, while the tar/dd combo
returns 1617920 bytes. The difference is the overhead for tar.

If you really want to check if tar does the right thing, restore the backup to
a different place (e.g. /tmp/etc) and check with diff:

# rewind your tape to the correct position (not shown)
cd /tmp; tar xvf /dev/nsa1
diff -ru /etc /tmp/etc

The diff command should give no output.

R.F.Smith                                   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)

Attachment: pgp0PgunzNVEO.pgp
Description: PGP signature

Reply via email to