As I understand your situation:
You have a NAS drive mounted on your RPi. Let's assume that mount point is:
/mnt/wdmycloud/raspi
You also mount a thumb drive on your RPi. Let's assume that mount point is:
/mnt/thumbdrv
You have a script called rsnapshot
that you have scheduled to run at regular intervals in a cron
job. rsnapshot
copies or backs up some data from the NAS drive to the Thumb drive. You wish to avoid performing copy/backup operations in rsnapshot
when the NAS is not mounted as this causes issues. (I assume these issues are due to how your script is written, but that is speculation)
You occasionally have power outages that affect both the RPi and the NAS. The NAS has a longer boot time, and for reasons that aren't clear to me, the NAS is not being re-mounted by systemd
once it has booted; this failure requires you manually mount
the NAS following a power outage.
In summary then, it sounds as if you have two issues:
- Issue 1: failure to mount the NAS after a power outage
- Issue 2: dysfunction of
rsnapshot
due to NAS not being mounted
Issue 1:
The following may work to resolve Issue 1:
Schedule a re-mount of the NAS in root's crontab
:
sudo crontab -e # use root's crontab instead of running sudo in yours
When the editor opens, add this line to root's crontab
:
@reboot (sleep 120; mount -a -v >> /home/pi/yourlogfile.txt 2>&1)
This will cause cron
to wait 2 minutes after it's started during the RPi boot cycle, and then mount everything in /etc/fstab
. You can experiment with the sleep
value if 2 minutes isn't quite right. This cron
job will also send all stdout
and stderr
output from the mount
command to the log file. If the NAS drive is not being mounted, you will see that in the stdout
output in this log file. If that mount
fails, you will also (hopefully) see some useful stderr
output that gives clues as to the cause of failure.
Issue 2:
The following may work to resolve Issue 2:
As you have suggested in your question, it is possible to determine whether or not the NAS is properly mounted prior to copy/backup operations. One way to do that is to use findmnt
in your rsnapshot
script. Without seeing the rsnapshot
script, something like this may work:
#!/bin/bash
...
# snippet for checking if NAS is mounted
if [[ $(findmnt -M "/mnt/wdmycloud/raspi") ]]
then
echo "NAS Drive Mounted at /mnt/wdmycloud/raspi"
# proceed with copy/backup operations
else
echo "NAS Drive NOT mounted, Try Again Later"
# wait, resolve, exit ??
fi
...
Refer to man findmnt
for details on this command & its options.
As you think through this, there are several options available. For example, you could use findmnt
in root's crontab (although elevated privileges are not required to use findmnt
), and loop through sleep
sessions until it became TRUE. Similarly, you may also wish to verify that your Thumb drive is mounted before going further in rsnapshot
.
Let us know if this doesn't work & we'll try to help.
/etc/fstab
to mount your NAS at boot time?/etc/fstab
but since the NAS is not ready in network at boot time, this doesn't mount the drive. Consequently, I've to manually do it afterwards./etc/fstab
entry to your question? This Q&A may have the answer to your problem./etc/fstab
//192.168.21.22/raspi /mnt/wdmycloud/raspi cifs username=raspi,password=*****,rw,uid=1000,gid=1000,file_mode=0744,dir_mode=0744