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

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

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