3

We have an automated rsnapshot job every day that writes on a mounted disk. Lately, instead of writing on the mounted disk it did it on the main filesystem, slowly filling the space available.

Is there an option that I can use in the mount definition (fstab) to ensure that writes are not made to main disk if mount is not available? Or is it something i have to put in a script related to the snapshot?

Thanks

3 Answers 3

6

When a filesystem is mounted the mount point acquires the permissions of the root inode of that filesystem. If a filesystem is not mounted the directory acting as the mount point is just another directory on the parent filesystem.

You can use this fact to your advantage to prevent accidentally writing to a mount point which may not be mounted:

  1. Unmount the target filesystem.
  2. Change the permissions of the mountpoint to something unfriendly.
    Something like chmod 0000 /path/to/mountpoint should work nicely.
  3. Remount the target filesystem
    The permissions on the mountpoint should change to match the permissions of the root inode of the mounted filesystem.

Note that this doesn't work so well if root is doing the writing and the usual permissions checks are bypassed.
You may be able to do something similar with immutable flags (schg or uchg on BSD systems, the i attribute on Linux systems) but I've not tested the behavior of filesystem attributes personally. Intuitively they should work the same as filesystem permissions do though.


Note that ideally you'd want to modify your backup scripts to ensure that the appropriate filesystem is mounted, otherwise you're going to have to catch and handle the errors the solutions above will generate.
Detecting that the appropriate filesystem(s) aren't in the output of mount may be a more robust solution.

0
2

The typical solution would be a check in your script e.g. with the mountpoint command.

if mountpoint -q $dir ; then
   echo "$dir is not mounted"
   exit 1
else
   echo "$dir is mounted" 
fi

An alternative would be a test with stat :

if [ `stat -fc%t:%T "$dir"` != `stat -fc%t:%T "$dir/.."` ]; then
    echo "$dir is mounted"
else
   echo "$dir is not mounted"
   exit 1
fi
2
  • 1
    the stat solution has the advantage of being relatively cross-platform (you can implement it on pretty much any *nix system, but you may need to check the man page for your system: the example provided is Linux-specific).
    – voretaq7
    Dec 9, 2013 at 20:58
  • The mountpoint while being quite unportable has the advantage of being quite intuitive, even the PFY understands it, where stat always needs that manpage lookup to remind me of how clever it is ;) but I appreciate your caveat.
    – HBruijn
    Dec 9, 2013 at 21:09
2

A bit old but in case someone else find this.

See /etc/rsnapshot.conf

# If no_create_root is enabled, rsnapshot will not automatically create the
# snapshot_root directory. This is particularly useful if you are backing
# up to removable media, such as a FireWire or USB drive.
#
no_create_root  1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .