Ensuring network drives are mounted before performing a backup [duplicate]Crontab running before nfs mountedBash Scripting: Require script to be run as root (or with sudo)help mounting network storage driveProblem restoring from tar backup: why are there /dev/disk/by-id/ symlinks and how can I avoid them?How to get the mount point of flash drive by using uuid?Backup with dd upon rebootCentos 6 - Backup and Restore/RecoverHow can I detect if I have access to a resource on an FTP server?Backup Ubuntu server with cron/rsync: Problems with resuming large filesWhat is the difference between $$ and $! when using /bin/bash -cqnap backup without creating a network share
Need feedback - Can the composition/colors of this design be fixed if something is lacking or is not a better fit?
How can I end combat quickly when the outcome is inevitable?
Pathfinder warbow concept review
Overlapping String-Blocks
Medieval flying castle propulsion
What ways have you found to get edits from non-LaTeX users?
1980s live-action movie where individually-coloured nations on clouds fight
Meaning of 'lose their grip on the groins of their followers'
Why doesn't Adrian Toomes give up Spider-Man's identity?
Russian word for a male zebra
You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one
How to trick the reader into thinking they're following a redshirt instead of the protagonist?
Generate basis elements of the Steenrod algebra
A IP can traceroute to it, but can not ping
Longest bridge/tunnel that can be cycled over/through?
How did old MS-DOS games utilize various graphic cards?
Wooden cooking layout
How can this tool find out registered domains from an IP?
Fixing obscure 8080 emulator bug?
Check if three arrays contains the same element
Are there any important biographies of nobodies?
Does Disney no longer produce hand-drawn cartoon films?
Is it expected that a reader will skip parts of what you write?
Geopandas and QGIS Calulating Different Polygon Area Values?
Ensuring network drives are mounted before performing a backup [duplicate]
Crontab running before nfs mountedBash Scripting: Require script to be run as root (or with sudo)help mounting network storage driveProblem restoring from tar backup: why are there /dev/disk/by-id/ symlinks and how can I avoid them?How to get the mount point of flash drive by using uuid?Backup with dd upon rebootCentos 6 - Backup and Restore/RecoverHow can I detect if I have access to a resource on an FTP server?Backup Ubuntu server with cron/rsync: Problems with resuming large filesWhat is the difference between $$ and $! when using /bin/bash -cqnap backup without creating a network share
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
Crontab running before nfs mounted
4 answers
I'm trying to write a backup script that can be deployed on many different linux servers, some of which mount network drives as described in /etc/fstab. I want my script to be able to see if any network drives have come unmounted before a backup to ensure that they don't go unsaved. Is there any way to reliably check for this in a bash script?
backup bash scripting
marked as duplicate by Iain, Thomas, Jenny D, chicks, peterh May 31 at 11:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Crontab running before nfs mounted
4 answers
I'm trying to write a backup script that can be deployed on many different linux servers, some of which mount network drives as described in /etc/fstab. I want my script to be able to see if any network drives have come unmounted before a backup to ensure that they don't go unsaved. Is there any way to reliably check for this in a bash script?
backup bash scripting
marked as duplicate by Iain, Thomas, Jenny D, chicks, peterh May 31 at 11:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@Iain et al: Just as a point of information, the duplicate answer is OS-specific. This one is not.
– Jim L.
May 31 at 17:10
add a comment |
This question already has an answer here:
Crontab running before nfs mounted
4 answers
I'm trying to write a backup script that can be deployed on many different linux servers, some of which mount network drives as described in /etc/fstab. I want my script to be able to see if any network drives have come unmounted before a backup to ensure that they don't go unsaved. Is there any way to reliably check for this in a bash script?
backup bash scripting
This question already has an answer here:
Crontab running before nfs mounted
4 answers
I'm trying to write a backup script that can be deployed on many different linux servers, some of which mount network drives as described in /etc/fstab. I want my script to be able to see if any network drives have come unmounted before a backup to ensure that they don't go unsaved. Is there any way to reliably check for this in a bash script?
This question already has an answer here:
Crontab running before nfs mounted
4 answers
backup bash scripting
backup bash scripting
asked May 22 at 20:47
MindlessMutagenMindlessMutagen
82
82
marked as duplicate by Iain, Thomas, Jenny D, chicks, peterh May 31 at 11:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Iain, Thomas, Jenny D, chicks, peterh May 31 at 11:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
@Iain et al: Just as a point of information, the duplicate answer is OS-specific. This one is not.
– Jim L.
May 31 at 17:10
add a comment |
@Iain et al: Just as a point of information, the duplicate answer is OS-specific. This one is not.
– Jim L.
May 31 at 17:10
@Iain et al: Just as a point of information, the duplicate answer is OS-specific. This one is not.
– Jim L.
May 31 at 17:10
@Iain et al: Just as a point of information, the duplicate answer is OS-specific. This one is not.
– Jim L.
May 31 at 17:10
add a comment |
2 Answers
2
active
oldest
votes
One method that comes to mind is to iterate over the list of mountpoints and see how many files are present under each one. A value of 1 probably means the filesystem isn't mounted (and only the directory itself is present). This strategy won't work if the mountpoints are nested, however. By "nested" I mean mountpoints like:
/mnt/server1/share1
/mnt/server1/share1/share2
/mnt/server1/share1/share2/share3
I have also seen this fail when someone/some process didn't know that a mount wasn't there, and copied files to it anyway, and the files got written to the underlying filesystem, instead of to the filesystem that should have been mounted there.
But if your structure is more "flat" (or if it can be made flat for backup purposes), like:
/mnt/server1/share1
/mnt/server1/share2
/mnt/server2/share3
then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
N=$(find $DIR | head -10 | wc -l)
if [ $N -eq 1 ]; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
Another method that might be slightly OS-specific, or at least subject to change if mount
's output format changes, is to do a brute-force check of mount
's output. Assuming that your mount
always uses spaces and never uses tabs, then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
if ! mount | grep -F " $DIR "; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
add a comment |
Combining the test
command with the -d
flag and checking to see if the mount exists per this question:
#!/bin/bash
mount="/fileserver"
if mountpoint -q "$mount" && test -d /path/to/share; then
cp -ru /path/to/files /. -t /path/to/share
fi
Edited per Michael Hampton's comment.
1
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
Also,mountpoint
is not available on some OSes.
– Jim L.
May 31 at 17:16
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
One method that comes to mind is to iterate over the list of mountpoints and see how many files are present under each one. A value of 1 probably means the filesystem isn't mounted (and only the directory itself is present). This strategy won't work if the mountpoints are nested, however. By "nested" I mean mountpoints like:
/mnt/server1/share1
/mnt/server1/share1/share2
/mnt/server1/share1/share2/share3
I have also seen this fail when someone/some process didn't know that a mount wasn't there, and copied files to it anyway, and the files got written to the underlying filesystem, instead of to the filesystem that should have been mounted there.
But if your structure is more "flat" (or if it can be made flat for backup purposes), like:
/mnt/server1/share1
/mnt/server1/share2
/mnt/server2/share3
then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
N=$(find $DIR | head -10 | wc -l)
if [ $N -eq 1 ]; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
Another method that might be slightly OS-specific, or at least subject to change if mount
's output format changes, is to do a brute-force check of mount
's output. Assuming that your mount
always uses spaces and never uses tabs, then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
if ! mount | grep -F " $DIR "; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
add a comment |
One method that comes to mind is to iterate over the list of mountpoints and see how many files are present under each one. A value of 1 probably means the filesystem isn't mounted (and only the directory itself is present). This strategy won't work if the mountpoints are nested, however. By "nested" I mean mountpoints like:
/mnt/server1/share1
/mnt/server1/share1/share2
/mnt/server1/share1/share2/share3
I have also seen this fail when someone/some process didn't know that a mount wasn't there, and copied files to it anyway, and the files got written to the underlying filesystem, instead of to the filesystem that should have been mounted there.
But if your structure is more "flat" (or if it can be made flat for backup purposes), like:
/mnt/server1/share1
/mnt/server1/share2
/mnt/server2/share3
then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
N=$(find $DIR | head -10 | wc -l)
if [ $N -eq 1 ]; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
Another method that might be slightly OS-specific, or at least subject to change if mount
's output format changes, is to do a brute-force check of mount
's output. Assuming that your mount
always uses spaces and never uses tabs, then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
if ! mount | grep -F " $DIR "; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
add a comment |
One method that comes to mind is to iterate over the list of mountpoints and see how many files are present under each one. A value of 1 probably means the filesystem isn't mounted (and only the directory itself is present). This strategy won't work if the mountpoints are nested, however. By "nested" I mean mountpoints like:
/mnt/server1/share1
/mnt/server1/share1/share2
/mnt/server1/share1/share2/share3
I have also seen this fail when someone/some process didn't know that a mount wasn't there, and copied files to it anyway, and the files got written to the underlying filesystem, instead of to the filesystem that should have been mounted there.
But if your structure is more "flat" (or if it can be made flat for backup purposes), like:
/mnt/server1/share1
/mnt/server1/share2
/mnt/server2/share3
then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
N=$(find $DIR | head -10 | wc -l)
if [ $N -eq 1 ]; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
Another method that might be slightly OS-specific, or at least subject to change if mount
's output format changes, is to do a brute-force check of mount
's output. Assuming that your mount
always uses spaces and never uses tabs, then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
if ! mount | grep -F " $DIR "; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
One method that comes to mind is to iterate over the list of mountpoints and see how many files are present under each one. A value of 1 probably means the filesystem isn't mounted (and only the directory itself is present). This strategy won't work if the mountpoints are nested, however. By "nested" I mean mountpoints like:
/mnt/server1/share1
/mnt/server1/share1/share2
/mnt/server1/share1/share2/share3
I have also seen this fail when someone/some process didn't know that a mount wasn't there, and copied files to it anyway, and the files got written to the underlying filesystem, instead of to the filesystem that should have been mounted there.
But if your structure is more "flat" (or if it can be made flat for backup purposes), like:
/mnt/server1/share1
/mnt/server1/share2
/mnt/server2/share3
then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
N=$(find $DIR | head -10 | wc -l)
if [ $N -eq 1 ]; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
Another method that might be slightly OS-specific, or at least subject to change if mount
's output format changes, is to do a brute-force check of mount
's output. Assuming that your mount
always uses spaces and never uses tabs, then:
MNTS="/mnt/server1/share1 /mnt/server1/share2 /mnt/server2/share3"
for DIR in $MNTS; do
if ! mount | grep -F " $DIR "; then
print "%s appears to not be mountedn" "$DIR"
else
# back it up
fi
done
answered May 24 at 0:00
Jim L.Jim L.
2455
2455
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
add a comment |
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
I wound up using a solution like this, with the MNTS variable being an environment variable set on each server during customization.
– MindlessMutagen
May 30 at 15:41
add a comment |
Combining the test
command with the -d
flag and checking to see if the mount exists per this question:
#!/bin/bash
mount="/fileserver"
if mountpoint -q "$mount" && test -d /path/to/share; then
cp -ru /path/to/files /. -t /path/to/share
fi
Edited per Michael Hampton's comment.
1
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
Also,mountpoint
is not available on some OSes.
– Jim L.
May 31 at 17:16
add a comment |
Combining the test
command with the -d
flag and checking to see if the mount exists per this question:
#!/bin/bash
mount="/fileserver"
if mountpoint -q "$mount" && test -d /path/to/share; then
cp -ru /path/to/files /. -t /path/to/share
fi
Edited per Michael Hampton's comment.
1
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
Also,mountpoint
is not available on some OSes.
– Jim L.
May 31 at 17:16
add a comment |
Combining the test
command with the -d
flag and checking to see if the mount exists per this question:
#!/bin/bash
mount="/fileserver"
if mountpoint -q "$mount" && test -d /path/to/share; then
cp -ru /path/to/files /. -t /path/to/share
fi
Edited per Michael Hampton's comment.
Combining the test
command with the -d
flag and checking to see if the mount exists per this question:
#!/bin/bash
mount="/fileserver"
if mountpoint -q "$mount" && test -d /path/to/share; then
cp -ru /path/to/files /. -t /path/to/share
fi
Edited per Michael Hampton's comment.
edited May 24 at 3:53
answered May 22 at 20:57
DavidwDavidw
84611020
84611020
1
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
Also,mountpoint
is not available on some OSes.
– Jim L.
May 31 at 17:16
add a comment |
1
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
Also,mountpoint
is not available on some OSes.
– Jim L.
May 31 at 17:16
1
1
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
The mountpoint may always exist even if the filesystem is not mounted on it. This doesn't make a good test by itself.
– Michael Hampton♦
May 23 at 0:08
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
@MichaelHampton Ah, you are correct, revising with a better version.
– Davidw
May 23 at 4:49
Also,
mountpoint
is not available on some OSes.– Jim L.
May 31 at 17:16
Also,
mountpoint
is not available on some OSes.– Jim L.
May 31 at 17:16
add a comment |
@Iain et al: Just as a point of information, the duplicate answer is OS-specific. This one is not.
– Jim L.
May 31 at 17:10