Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I use rsync with the --size-only and --sparse options together, if a file already exists at the destination as a full file (otherwise the same) it's not overwritten.

If I omit the --size-only option, the non-sparse file is overwritten with the sparse version. I do want the file to be overwritten and I want to keep the --size-only option (unless I can be convinced that I don't).

This is part of a script that gets run periodically. In the past, the --sparse option was not used and a lot of space has been wasted.

How can I continue to use --space-only (and other options I haven't included here) and have the large files overwritten as the script does its work? A search-and-destroy mission would be too "expensive".

I have tested this with rsync 3 in Ubuntu with ext3 and CentOS with ext4. The actual rsync is performed over an ssh connection.

Note that in the following demonstration nothing changes about the source or destination files (size, times or contents) between runs of rsync.

Demonstration:

$ dd if=/dev/zero of=sparse.out bs=1 seek=1M count=1
1+0 records in
1+0 records out
1 byte (1 B) copied, 0.000307332 s, 3.3 kB/s

$ stat sparse.out
  File: `sparse.out'
  Size: 1048577         Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 2377326     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  dennis)   Gid: ( 1000/  dennis)
Access: 2011-07-28 22:06:52.000000000 -0500
Modify: 2011-07-28 22:06:52.000000000 -0500
Change: 2011-07-28 22:06:52.000000000 -0500

$ du -h sparse.out
8.0K    sparse.out

$ rsync --size-only sparse.out sparse.out.rsync

$ stat sparse.out.rsync
  File: `sparse.out.rsync'
  Size: 1048577         Blocks: 2064       IO Block: 4096   regular file
Device: 802h/2050d      Inode: 2377329     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  dennis)   Gid: ( 1000/  dennis)
Access: 2011-07-28 22:09:19.000000000 -0500
Modify: 2011-07-28 22:09:20.000000000 -0500
Change: 2011-07-28 22:09:20.000000000 -0500

$ du -h sparse.out.rsync
1.1M    sparse.out.rsync

$ rsync --size-only --sparse sparse.out sparse.out.rsync

$ stat sparse.out.rsync
  File: `sparse.out.rsync'
  Size: 1048577         Blocks: 2064       IO Block: 4096   regular file
Device: 802h/2050d      Inode: 2377329     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  dennis)   Gid: ( 1000/  dennis)
Access: 2011-07-28 22:09:19.000000000 -0500
Modify: 2011-07-28 22:09:20.000000000 -0500
Change: 2011-07-28 22:09:20.000000000 -0500

$ du -h sparse.out.rsync
1.1M    sparse.out.rsync

$ rsync --sparse sparse.out sparse.out.rsync

$ stat sparse.out.rsync
  File: `sparse.out.rsync'
  Size: 1048577         Blocks: 16         IO Block: 4096   regular file
Device: 802h/2050d      Inode: 2377330     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  dennis)   Gid: ( 1000/  dennis)
Access: 2011-07-28 22:11:23.000000000 -0500
Modify: 2011-07-28 22:11:23.000000000 -0500
Change: 2011-07-28 22:11:23.000000000 -0500

$ du -h sparse.out.rsync
8.0K    sparse.out.rsync

$ stat -c '%b %B %o %s' sparse.out sparse.out.rsync
16 512 4096 1048577
16 512 4096 1048577

$ cmp sparse5.out sparse5.out.rsync
$
share|improve this question
2  
I suspect you'll have to relax one of your constraints. How about running a local program on the target once to sparsify files wherever possible? –  Gilles Jul 31 '11 at 22:25

1 Answer 1

--size-only tells rsync to skip files which match in size. Since sparse files are preallocated they can be the same size while having different content. I would suggest that you remove the --size-only option and make sure that modification times are synced (--times). rsync then won't check the contents of the file if the modification times match (which is what I assume you are trying to avoid wtih --size-only), while still syncing files which have been modified.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.