Yes, that's the intended behavior of grsync, rsync, etc., and many other backup tools and it is the user's responsibility to check that the volume is mounted prior to executing these tools (as you allude to). You can create a script that runs the grsync command instead of running it directly, and then put some commands that check to see if the volume is mounted before running the grsync command (or just run the mount check commands manually, that works too). Something like this might work:
cd /home/username/
mkdir scripts
cd scripts
nano grsyn.sh
sudo chmod 750 grsync.sh
nano grsync.sh
Then, in the file that opens in the nano text editor, copy and paste and adjust this script to your needs:
if grep -qs '/mnt/backup ' /proc/mounts; then
echo "I will proceed with grsync because the volume is ready."
grsync [enter your commands/flags here]
else
echo "The volume is not ready, so I am not running grsync."
fi
You can run the script manually by navigating to your scripts' directory and typing ./grsync.sh
. The q
flag is optional and can be removed depending on user preference. You can optionally create a cron job to run this script as follows:
sudo crontab -e
Below the last entry, copy/paste and adjust the following to your needs:
0 8 * * * /bin/bash /home/username/scripts/ >> /home/username/grsync.log
This script will run your desired grsync command every day at 8am.
New users and/or less complex workflows might only require a simple check, and in that case it is easiest to enter a single command at the console. To do that, use the grep syntax above, but just make sure to omit the q
flag so the result prints to standard output:
grep -s '/mnt/backup ' /proc/mounts
This will then print a result similar to this if the Volume is mounted:
/dev/sdb /mnt/backup ext4 rw,nosuid,nodev,noatime,attr2,inode64,logbufs=8,logbsize=32k,noquota 0 0
If you receive no output, and as long as your grep string is accurate, then this would indicate the volume is likely not mounted. Lastly, if you want this integrated within the graphical front end of grsync instead of handling at the command line, then simply enter the manual command into the Extra Options / Execute this command before rsync / Halt on failure.