Preventing Copying to a Mount Point via Immutability
When using rsync
for backups, there's a risk that if the target mount point is not mounted, the data could be copied to the underlying directory instead and filling up the disk. To prevent this, we can make the mount point immutable using the Change Attribute (chattr
) command. All commands and examples are run on ProxMox, a Debian-based distribution.
Make a directory immutable.
- Make sure the directory is unmounted:
sudo umount /mnt/backup
- Set the directory to immutable:
sudo chattr +i /mnt/backup
- Verify the directory is immutable:
lsattr -a /mnt/backup
You should see the output:----i---------e------- /mnt/backup/.
--------------e------- /mnt/backup/..
Trust, but verify.
- Attempt to create a test file:
sudo touch /mnt/backup/testfile
You should see an error:touch: setting times of '/mnt/backup/testfile': No such file or directory
Revert this change.
- To revert the change, simply change
+i
to-i
:sudo chattr -i /mnt/backup