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
$