Ok, I have this in fstab
//windows_mashine/Backup /backups cifs credentials=/root/.credentials,rw,_netdev,iocharset=utf8,uid=1000 0 0
I have rsnapshot in my cron which backups /etc/ and /usr/local/ and some other files to /backups
Recently I find that when other mashine is down and /backups cannot be mounted rsnapshot backups to physical folder /backups thus it eats partition / space. How can I avoid this?
Can I prevent any writing to /backups when it is not mounted (rsnapshot runs as root, since it need to backup some system files)
Another option is to set the directory to be immutable. To do this you need to run the following command with the mount point unmounted.
chattr +i /backups
I do this on any directory that is intended to only be a mount point just to prevent this sort of thing. Because there are situations where you're not in a position to add a check to see if something is mounted. Like if the process isn't a script that you control or it's a human that is generating or moving the data. This approach will prevent unwanted data getting written into an unmounted mount point in those situations. I would still add the mount check to your scripts so that you can output meaningful errors though.
Why not just have the backup script test whether /backups is mounted, and exit if not?
the easiest way to handle this is.. with rsnapshot directly.
You should have a look at the option
no_create_root
HTH