I have a few PC's with an ext4 filesystem that I want to backup to a file server which is also ext4. Problem is there are some discrepancies in file sizes when using rsync, and I have noticed this is due to sparse files.
The problem is I want to create an exact rsync copy of the filesystem using rsync over a network to keep weekly backups, in case I need to restore, and the restored data should be the same size as whats running on the PC.
Creating the test files, 1 sparse and 1 not:
mkdir testing
dd if=/dev/zero of=testing/sparse-file.img bs=1 count=0 seek=5M
cp testing/sparse-file.img testing/non-sparse-file.img --sparse=never
Rsync with and without sparse option:
mkdir testa testb
rsync testing/* testa
rsync --sparse testing/* testb
Results:
du -h
5.1M ./testing
4.0K ./testb
11M ./testa
16M .
testing has 1 file 5MB and one sparse file, testb had both files become sparse, testa had both files become non-sparse
But how do I make rsync maintain the file sparseness? So the filesystem will have the exact same size on the restored system.
I want to have certainty when I restore my system I'll know exactly how big the restored data will be, with sparse option, my restored system is going to be more sparse then what it was originally (I guess this is acceptable), and with the non-sparse option, this will result in an unpredictable larger restored system.