How can I check whether a volume is mounted where it is supposed to be using Python?
Posted
by Ben Hymers
on Server Fault
See other posts from Server Fault
or by Ben Hymers
Published on 2010-05-18T18:06:55Z
Indexed on
2010/05/18
18:10 UTC
Read the original article
Hit count: 316
I've got a backup script written in Python which creates the destination directory before copying the source directory to it. I've configured it to use /external-backup
as the destination, which is where I mount an external hard drive. I just ran the script without the hard drive being turned on (or being mounted) and found that it was working as normal, albeit making a backup on the internal hard drive, which has nowhere near enough space to back itself up.
My question is: how can I check whether the volume is mounted in the right place before writing to it? If I can detect that /external-backup
isn't mounted, I can prevent writing to it.
The bonus question is why was this allowed, when the OS knows that directory is supposed to live on another device, and what would happen to the data (on the internal hard drive) should I later mount that device (the external hard drive)? Clearly there can't be two copies on different devices at the same path!
Thanks in advance!
© Server Fault or respective owner