Is it possible to get gnome-volume-manager style auto mount/umount of USB drives in /media (or elsewhere) when nobody is logged into the desktop? The behavior when I'm logged in (auto-mounting in a directory named after the Volume Name, auto-unmounting, etc) is exactly what I would like when I'm not logged in. It doesn't matter if the mount point is owned by root, as I just want to back up some files in a cron job but only if there's a drive plugged in.
I suppose I could script it all, except: 1. I'm not a very skilled script writer, 2. I don't really know where to start to accomplish this, and 3. It seems to me that there's already something on the system that does perfectly what I want.
-Alan
On Tue, 30 Nov 2010 10:32:47 -0800 Alan Evans wrote:
I just want to back up some files in a cron job but only if there's a drive plugged in
If the cron job is running as root, you should be able to just do something like:
if mount LABEL=BACKUP /backup then ...do backup stuff... umount /backup fi
or you could use UUID=gibberish syntax, etc (whatever seems convenient to properly identify the partition on the usb drive).
On Tue, Nov 30, 2010 at 10:42 AM, Tom Horsley wrote:
if mount LABEL=BACKUP /backup then ...do backup stuff... umount /backup fi
Wow. It's really that easy?
I did have to redirect stderr to null since I'm not interested to getting mail from cron every time the drive is not plugged in. But otherwise, that will probably work form me.
I presume that this is safe in the case that somebody *is* logged and and the drive is already auto-mounted by that user in /media? My script mounts the drive in /mnt, and it's a little weird having two mount points for the same device, but I suppose that was intended and properly handled by the kernel...
-Alan
On 11/30/2010 11:38 AM, Alan Evans wrote:
I did have to redirect stderr to null since I'm not interested to getting mail from cron every time the drive is not plugged in. But otherwise, that will probably work form me.
There should be a way to write the job so that it dies silently if the drive's not mounted. I'm not good enough with shell scripts to know how, but somebody here probably is.
On Tue, 30 Nov 2010 11:38:13 -0800 Alan Evans wrote:
I presume that this is safe in the case that somebody *is* logged and and the drive is already auto-mounted by that user in /media?
Not sure about multiple mount points. You'd think if the kernel allows it, that it would get it right, but you never know. I "hide" my backup disk so annoying automount stuff will never mount it:
http://home.comcast.net/~tomhorsley/wisdom/braindump/hide-disk.html
On 11/30/2010 10:32 AM, Alan Evans wrote:
Is it possible to get gnome-volume-manager style auto mount/umount of USB drives in /media (or elsewhere) when nobody is logged into the desktop? The behavior when I'm logged in (auto-mounting in a directory named after the Volume Name, auto-unmounting, etc) is exactly what I would like when I'm not logged in. It doesn't matter if the mount point is owned by root, as I just want to back up some files in a cron job but only if there's a drive plugged in.
I suppose I could script it all, except: 1. I'm not a very skilled script writer, 2. I don't really know where to start to accomplish this, and 3. It seems to me that there's already something on the system that does perfectly what I want.
-Alan
Not Fedora, but this might help: https://wiki.archlinux.org/index.php/Udev#Auto_mounting_USB_devices
On Tue, 2010-11-30 at 10:32 -0800, Alan Evans wrote:
Is it possible to get gnome-volume-manager style auto mount/umount of USB drives in /media (or elsewhere) when nobody is logged into the desktop? The behavior when I'm logged in (auto-mounting in a directory named after the Volume Name, auto-unmounting, etc) is exactly what I would like when I'm not logged in. It doesn't matter if the mount point is owned by root, as I just want to back up some files in a cron job but only if there's a drive plugged in.
I suppose I could script it all, except: 1. I'm not a very skilled script writer, 2. I don't really know where to start to accomplish this, and 3. It seems to me that there's already something on the system that does perfectly what I want.
-Alan
Alan I had a similar situation about fifteen years ago, although it was with a zip drive then. Refining my solution every time the dust hit the fan, I have arrived at the following:
I made a subdirectory (/media/flash) to mount the flash drive on. I put the following entry in /etc/fstab so only the right USB drive would be mounted, and it wouldn't be mounted automagically: UUID=3470cd52-98ec-4eb8-972f-53be4909a856 /media/flash auto noauto,defaults 1 2 You can get the UUID by using ls -l /dev/disk/by-uuid
The attached script (in /etc/cron.daily) runs every night. It backs up my /home stuff using dump(1), then copies some goodies to my /root/conf.d directory (where I keep stuff I need to reference when the disk crashes) and backs that up (with tar(1)). (It backs up Monday's stuff at 0330 Tuesday, etc., hence the counterintuitive file names.)
By keeping the USB drive unmounted it's preserved from most disasters. By keeping it plugged in it's available for backup. By using the UUID in /etc/fstab I prevent my files from being backed up on the wrong USB drive - you know, the one you inserted and forgot to remove... If the USB drive can't be mounted, the error is in the email and the drive isn't unmounted. If there's an error during the backup, the drive stays mounted. If the drive is already mounted, it's because there was an error, so the script terminates. Root email is your friend.
Don't be afraid of scripts. You learn by doing. The goal is to err, and err, and err again, but less, and less, and less.