I'm testing out a few methods for transferring datasets between Debian 12 VMs, specifically comparing gocryptfs encrypted datasets and LUKS file containers for remote backups. My source dataset is a simple directory containing 5,000 files totaling about 14GB. After backing it up to a gocryptfs volume on another VM, I rsynced that volume to a third VM. While everything seems fine on the source and backup VMs, I've noticed something strange with the directory size on the rsynced gocryptfs replica. The directory's size reported on the source and backup is correct, but on the replica, it's larger—indicating a change in the directory itself, not the files within it. I checked the directory's size even while it was encrypted (not mounted) and found the same discrepancy. I'm trying to understand why the directory size changed when using rsync to transfer the gocryptfs dataset to another host. Any insights would be appreciated!
3 Answers
The directory size can vary depending on how directory entries are created. For filesystems like Ext4, the order and number of entries contribute to the size. Even if you don't add or remove files, the directory can grow based on how many files were previously in it.
Just to clarify, the 'size' of a directory typically refers to its metadata, not the content. You might find it more helpful to use the 'du' command to check the space used by files within that directory. Also, for a more efficient encrypted backup, consider using tools like kopia or restic instead of handling rsync with LUKS or gocryptfs manually.
Hi and thank you for your answer. About point 2: why is it considered inefficient?
In UNIX filesystems, once a directory grows due to added files, it rarely shrinks back down even if files are removed. The directory's size reflects its maximum capacity at any point, so the size discrepancy you're seeing can be attributed to that. When rsync runs, it might create temporary files that can affect how large the directory appears if there were more files present at one time.
Interesting perspective, thanks for sharing!
Thank you for your answer!