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;








1
















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?










share|improve this 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


















1
















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?










share|improve this 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














1












1








1









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?










share|improve this question















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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • @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











2 Answers
2






active

oldest

votes


















1














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





share|improve this answer























  • 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


















2














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.






share|improve this answer




















  • 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

















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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





share|improve this answer























  • 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















1














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





share|improve this answer























  • 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













1












1








1







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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













2














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.






share|improve this answer




















  • 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















2














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.






share|improve this answer




















  • 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













2












2








2







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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












  • 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



Popular posts from this blog

How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos