9

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)

3 Answers 3

18

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.

1
  • 1
    It works and doesn't require to modify anything except mount point folder. Great!
    – jonny
    Sep 21, 2011 at 18:23
6

Why not just have the backup script test whether /backups is mounted, and exit if not?

mount | grep -q /backups || exit 1
2
  • 1
    just modified my crontab as if [ ! -z "$(ls /backups/)" ]; then /usr/bin/rsnapshot daily; fi;
    – jonny
    Sep 21, 2011 at 16:58
  • @jonny the best answer here.
    – RichieHH
    Jan 29, 2023 at 0:44
2

the easiest way to handle this is.. with rsnapshot directly.

You should have a look at the option no_create_root

HTH

1
  • that doesnt work since the mount point is there regardless of whether an external device is mounted there or not
    – RichieHH
    Jan 29, 2023 at 0:08

You must log in to answer this question.

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