As I understand your situation:
You have a NAS drive mounted on your RPi. Let's assume that mount point is:
You also mount a thumb drive on your RPi. Let's assume that mount point is:
You have a script called
rsnapshot that you have scheduled to run at regular intervals in a
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
The following may work to resolve Issue 1:
Schedule a re-mount of the NAS in root's
sudo crontab -e # use root's crontab instead of running sudo in yours
When the editor opens, add this line to root's
@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
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.
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:
# snippet for checking if NAS is mounted
if [[ $(findmnt -M "/mnt/wdmycloud/raspi") ]]
echo "NAS Drive Mounted at /mnt/wdmycloud/raspi"
# proceed with copy/backup operations
echo "NAS Drive NOT mounted, Try Again Later"
# wait, resolve, exit ??
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
Let us know if this doesn't work & we'll try to help.