Scripting rsync against a filesystem with a quota

Matt McCutchen matt at mattmccutchen.net
Sun Aug 15 18:07:36 MDT 2010


On Wed, 2010-08-11 at 16:07 +0100, William Hunter wrote:
> I'm trying to write a script that will synchronise various local
> folders on a Mac OS X Workstation to an SMB mounted Windows (2003,
> mostly) Server where the user I'm copying as has a quota applied. I
> want to compare the available space I have, which I can find with:
> 
> 
> df /Volumes/$USER | grep % | awk -F'[ ] ' '{ print $4 }'
> 
> 
> Against the amount of data that rsync thinks it is going to copy.

Do I understand correctly that you are picking out the "Available" field
from the df output?

> What I'm after is the most efficient way of finding out how much data
> rsync wants to copy, dying (relatively) gracefully should it be within
> X of the quota (say, 10MB or so).
> 
> 
> At the moment I can use the same rsync command I'd run to do the copy
> but with the -n option:
> 
> 
> rsync -a -u -z -E -r -l -n
> --progress /path/to/src /Volumes/path/to/dest/ | grep "total size is"
> | awk -F'[ ]' '{ print $4 }'
> 
> 
> to do a dry-run to grep and cut a number from rsync's output.

Are you copying to a new destination or an existing destination?  If it
is an existing destination, what you really want is not the total size
of the source but the anticipated change in size of the destination,
given that some files may have been copied already and other destination
files may be subject to deletion if you use --delete.  Alternatively, if
the destination is the only thing on the volume, you could compare the
total volume size to the source size.

> The only thing is that this might take a while if there are very many
> files and potentially there are hundreds of thousands. I'd then have
> to go and run the same command all over again should the data fit,
> this time without the -n option. I also feel that my units may be
> rather disparate (i.e. df's output isn't the same unit sizes as
> rsync's).

"BLOCKSIZE=1 df" will give output in bytes, like the rsync "total size"
field, but there is still filesystem overhead.

> I'm sure there must be a better way than running rsync twice.

The only possibility I can think of is to use rsync in
non-incremental-recursion mode and patch it to check the quota just as
it finishes building the file list.

> On another note I'm getting an error:
> 
> 
> copyfile(.._..v6AxMh,./., COPYFILE_UNPACK) failed:13
> 
> 
> When trying to run with -E.

Upstream rsync has no such error message.  If you're using the
Apple-modified rsync, we don't support it here.

-- 
Matt



More information about the rsync mailing list