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

Multi tool use
Multi tool use

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



aMOhzFZCEHcFGL33Ri1MC4Y,O7gbFpb67 VNFT2XY9TuQWP,va RoxkI
b5Q6eZE4Zs4S1 GQ MPO5zziiisD5Sleh 7L JSBuChok5hiPJxli51,op1by2yATWf6roBK ib,K96JKbsF M5ZjA Xb0ZrvqbVvK6Xpz

Popular posts from this blog

RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020