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)

jonny
  • 357
  • 1
  • 3
  • 14

3 Answers3

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.

3dinfluence
  • 12,409
  • 2
  • 27
  • 41
6

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

mount | grep -q /backups || exit 1
  • just modified my crontab as `if [ ! -z "$(ls /backups/)" ]; then /usr/bin/rsnapshot daily; fi;` – jonny Sep 21 '11 at 16:58
2

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

You should have a look at the option no_create_root

HTH

Yann Sagon
  • 276
  • 3
  • 8