Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The VPS I manage uses a simple hard link rsync archive daily backup system saved to a loop file. This is great, because each backup only takes up as much space as what has changed each day, and all user/group permissions are kept.

I would like to give users direct access to their home directories in each backup, but I'm worried about intentional or accidental backup data destruction, as how it stands now users can actually change, destroy or add to backed up data they originally owned. I've been looking for a way to mount this filesystem similar to an ro mount option, but something that would still allow rw access to root, but I've had absolutely no luck. In other words, I want users to be able to view and copy their backed up data without actually being able to change it, and have that data maintain the original permissions.

I've got no real preferences as far as filesystem, as long as it's a standard unix filesystem that can preserve permissions, support hard links and deny write access to users without actually stripping the w permission from everything.

share|improve this question

1 Answer 1

Mount the backups in a location accessible only to root, and make a read-only bind-mount accessible to users. For example,

% chown root:root /root/.private
% chmod 700 /root/.private
% mount -o rw [...] /root/.private/mnt

% mount --bind /root/.private/mnt /export/mnt
% mount -o remount,ro /export/mnt

Now /root/.private/mnt is read-write for root only, and /export/mnt is read-only for everybody.

Read-only bind mounts require Linux kernel 2.6.26 or higher. Note that a remount must be performed after the bind in order to change the mount options.


I don't know of any way to perform remounts in fstab; my rc.local is set up to call a script that looks something like this:

#!/usr/bin/perl -an
BEGIN{@ARGV=qw(/etc/fstab /proc/mounts)}/#/,or$o{$F[1]}[@ARGV]=",$F[3],"}{$$b[0]=~/,rw,/&&$$b[1]=~/,ro,/&&system qw(mount -o remount,ro),$a while($a,$b)=each%o

Fairly terrible code (shows that I hang out on PCG too often for my own good), but it wasn't ever intended to be shared… basically forces remount,ro on everything that is ro in /etc/fstab but is rw in /proc/mounts. I have it scripted because I've got a dozen of these; if you've got just one I would just hard-code it in a simple shell script.

share|improve this answer
    
This does the trick, thanks. However, is there any way to specify the remount in fstab? –  Uejji Apr 9 '12 at 5:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.