How to avoid putting files in a folder that's supposed to be a mount point

You create a folder that you intend to be a mount point for a disk intermittently, say /home/user/Backup. You mount the disk only when you want to create or add to a backup for security reasons. But your memory is not good and you sometime forget to mount the disk prior to running your backup.

The first time that happens and you forget to mount it, all the backup files will be created on your main disk in /home/user/Backup instead of on the (still unmounted disk) thus filling up your main disk with files not intended to be there. Worse, when you then mount the disk, those files are now hidden and you don’t even know they are there until you unmount the disk and do an “ls /home/user/Backup”

A very simple trick to see if he disk is mounted is to, while the disk is unmounted, type “touch /home/user/Backup/DISK_IS_NOT_MOUNTED”. This will create a file of zero length with the name DISK_IS_NOT_MOUNTED. Once the disk is mounted, this file is invisible.

If you type “ls /home/user/Backup” while looking for one of your backup files and see that file name, you know you forgot to mount the disk. If it is not there, the disk is mounted. If it is there and there are other files also, you will realize you accidentally created files there when the disk wasn’t mounted and you know you need to fix the problem.

4 Likes

May I suggest another way… Set the /home/user/Backup as immutable with:

sudo chattr +i /home/user/Backup

Now, /home/user/Backup cannot be deleted or renamed, no link can be created to this directory and no data can be written to it. However you can mount your backup disk to this point. :wink:

If needed, reverse process is:

sudo chattr -i /home/user/Backup

BTW, please do tell me if there is a way to accomplish same behavior without using elevated privileges.