Make directory used as mount point read-only


 
Thread Tools Search this Thread
Operating Systems Linux Make directory used as mount point read-only
# 1  
Old 10-17-2014
Debian Make directory used as mount point read-only

For my backup , I mount and external hard disk to /mnt/mybackup and then I do an rsync to /mnt/mybackup

If for some reason the rsync fails, I want to prevent it from writing data on the server hard disk itself since the external hard disk will no longer be mounted on it.

I want /mnt/mybackup directory to be read-only and when my external device (e.g /dev/sda1) is mounted on it then I want it to be read/write-able by rsync

Please advise me on this

Last edited by rbatte1; 10-17-2014 at 08:48 AM..
# 2  
Old 10-17-2014
Could you create a subdirectory on the external drive and write to that? In this case, a write with the filesystem not mounted would get a "target not found" or equivalent message. It would mean that you external drive would have a directory and everything under that, so your recovery would have to reflect that too.


Does that give you an option?



Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 10-17-2014
Hi,

I used to use this type of check when I used external devices.

Code:
PARCHK=`df -k | grep mybackup | wc -l`

if [ ${PARCHK} -ne 1 ]
        then
        echo "The portable hard drive partitions are not mounted, please correct."
        exit 1
        else
        echo "There are ${PARCHK} partitions mounted, backup starting."
fi

This should work for you if you change the messages to suit.

Regards

Dave
This User Gave Thanks to gull04 For This Post:
# 4  
Old 10-17-2014
While the backup filesystem is unmounted, can't you do a chmod 0 /mnt/mybackup? That should prevent accidental syncing when the backup filesystem is unmounted.

When you mount a filesystem on that directory, it should appear with the permissions of the root directory of the filesystem you have mounted (rather than the overlaid mount point directory) thereby allowing rsync to work as desired.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 10-21-2014
Quote:
Originally Posted by Don Cragun
While the backup filesystem is unmounted, can't you do a chmod 0 /mnt/mybackup? That should prevent accidental syncing when the backup filesystem is unmounted.

When you mount a filesystem on that directory, it should appear with the permissions of the root directory of the filesystem you have mounted (rather than the overlaid mount point directory) thereby allowing rsync to work as desired.
before doing chmod 0 on /mnt/mybackup

Code:
drwxr-xr-x  2 root root 4096 2012-07-26 16:41 mybackup

after doing chmod 0 on /mnt/mybackup

Code:
d---------  2 root root 4096 2014-10-21 11:18 mybackup

i did a test:

Code:
/mnt# touch mybackup/afile.txt

The file was successfully created.

I thought that would make the mybackup directory inaccessible even by root.

please advise.

---------- Post updated at 11:30 AM ---------- Previous update was at 11:26 AM ----------

Quote:
Originally Posted by gull04
Hi,

I used to use this type of check when I used external devices.

Code:
PARCHK=`df -k | grep mybackup | wc -l`

if [ ${PARCHK} -ne 1 ]
        then
        echo "The portable hard drive partitions are not mounted, please correct."
        exit 1
        else
        echo "There are ${PARCHK} partitions mounted, backup starting."
fi

This should work for you if you change the messages to suit.

Regards

Dave
Thanks for the script.i already use a script to check if the external hard disk is REALLY mounted.
i created a file called "am-a-file-on-the-external-hd.txt" on the external hard disk and before backup i check if that file exists.

---------- Post updated at 11:37 AM ---------- Previous update was at 11:30 AM ----------

just for info, i had twice landed into the issue where the filesystem was 100% full. The customer forgot to plug the usb or the usb was a bit loose.

---------- Post updated at 11:57 AM ---------- Previous update was at 11:37 AM ----------

i tried running the rsync...the rsync process could write on the unmounted /mnt/mybackup directory...which is bad Smilie
# 6  
Old 10-21-2014
Can you check with mount command then if exit code is 0 do the rsync, else don't rsync ?
Touching a file will work on both directory and mountpoint so that check is not good.

Something like
Code:
mount | grep "/your/mountpoint"
if [ $? -eq 0 ]; then
echo "will rsync"
else
echo "will not rsync, unable to find mountpoint"
fi

This User Gave Thanks to Peasant For This Post:
# 7  
Old 10-21-2014
Quote:
Originally Posted by Peasant
Can you check with mount command then if exit code is 0 do the rsync, else don't rsync ?
Touching a file will work on both directory and mountpoint so that check is not good.

Something like
Code:
mount | grep "/your/mountpoint"
if [ $? -eq 0 ]; then
echo "will rsync"
else
echo "will not rsync, unable to find mountpoint"
fi

OK i understand..but this is before starting the backup..what if during the backup itself (assume the backup will take 3 hours) the external drive gets connected for some reason ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to create a new mount point with 600GB and add 350 GBexisting mount point? IN AIX

How to create a new mount point with 600GB and add 350 GBexisting mount point Best if there step that i can follow or execute before i mount or add diskspace IN AIX Thanks (2 Replies)
Discussion started by: Thilagarajan
2 Replies

2. AIX

How to change the mount point of LV?

I have situation where my disk upon reboot, has its mount point as # LOGICAL VOLUME: disk4vol VOLUME GROUP: disk4vg LV IDENTIFIER: 00f609aa00004c0000000152414b786c.1 PERMISSION: read/write VG STATE: active/complete LV STATE: closed/syncd TYPE: jfs2 WRITE VERIFY: off MAX LPs: 512 PP SIZE: 512... (1 Reply)
Discussion started by: mrmurdock
1 Replies

3. UNIX for Beginners Questions & Answers

Can we have 2 mount point under the same name but at different directory?

guys i would like to know can we have 2 mount point which is same name but on different directory? (3 Replies)
Discussion started by: leecopper
3 Replies

4. Red Hat

NFS mount point

Hi, Can you tell me something about NFS mount point ? Regards, Maddy (3 Replies)
Discussion started by: Maddy123
3 Replies

5. Shell Programming and Scripting

Mount point usage

Hi Guys, I have Solaris 9 and RHEL 5 boxes I implemented script to send me an email when my mount point is > 90. Now the ouput id like these: /dev/dsk/emcpower20a 1589461168 1509087840 64478720 96% /data1 /dev/dsk/emcpower21a 474982909 451894234 18338846 97% /data2... (2 Replies)
Discussion started by: Phuti
2 Replies

6. Solaris

Mount point in a server

Hi , How to find out mount point in a server ? OS -- SunOS 5.6 Generic sun4u sparc SUNW Thanks (4 Replies)
Discussion started by: Maddy123
4 Replies

7. Solaris

Mount Point Sorting?

Dear Gurus, Could it be possible to have the output of df -k sorted? The df -k output messed up after recent power trip. Also, is there any folders that I should look into to reduce the root size (other than /var/adm and /var/crash) after server crash? Many thanks in advance. ... (2 Replies)
Discussion started by: honmin
2 Replies

8. UNIX for Advanced & Expert Users

mount point lists

is there any command to know the list of mount points in a server.i need only the mount point lists.i tried using df but it was not helpful.i am using Solaris (1 Reply)
Discussion started by: dr46014
1 Replies

9. UNIX for Dummies Questions & Answers

mount point

hi people, I'm trying to create a mount point, but am having no sucess at all, with the following: mount -F ufs /dev/dsk/diskname /newdirectory but i keep getting - mount-point /newdirectory doesn't exist. What am i doing wrong/missing? Thanks Rc (1 Reply)
Discussion started by: colesy
1 Replies

10. UNIX for Dummies Questions & Answers

Recover mount point

A disk was sliced into 6 slices with m01 being the mount point for one of the slices. This mount point was deleted with rmdir (ie. rmdir m01). What is the easiest way to recover this mount point? (1 Reply)
Discussion started by: here2learn
1 Replies
Login or Register to Ask a Question