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

Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company