4 ms·
My use case for `chattr +i`: an rsync backup, on a cronjob, into an external drive mounted at a given point. Make the mountpoint directory `+i` so that the root
by alethiophile 9y ago
My use case for `chattr +i`: an rsync backup, on a cronjob, into an external drive mounted at a given point. Make the mountpoint directory `+i` so that the root-run rsync doesn't blindly fill up your root filesystem with the backup target, if it gets run while the external drive isn't mounted.
- switch007 9y agoAlso useful: "mountpoint" can tell you if a path is mounted. https://linux.die.net/man/1/mountpoint https://linux.die.net/man/1/mountpoint E.g. mountpoint -q /mnt/backup || exit 1
- jbverschoor 9y agoWhat if it gets unmounted right after the mountpoint call :)
- switch007 9y agoWhat if it gets mounted just before you run chattr +i :) I agree setting the flag is the superior option.
- xorcist 9y agoYou miss the point of making a directory immutable which doubles as a mountpoint. Mounting something just creates a new filsystem namespace over a path. It doesn't touch the existing directory. So you can safely leave the directory in question immutable, you never remove the flag, and it will only prevent writes to the directory when it is not overlaid by a mount.
- Renevith 9y agoThanks for this tip! I've been achieving this by pointing a symlink at a subdirectory that only exists when the external drive is mounted, and having my backups target that symlink. But this seems cleaner.
- jakeogh 9y agoMe too. Not sure why using an immutable mountpoint is better than a possibly broken symlink, both result in a write failure. I like the symlink, because it's visually obvious when it's broken in the shell, and I can keep my real mounts under /mnt or /pool etc while also putting the target (symlink) in /home/user.