/ bash

backups: check if path is a (nfs) mountpoint

Here's the crontab entry:
0 3 * * * /bin/mountpoint -q /mnt/backup && /usr/bin/rsync -a /source/ /mnt/backup/

echo $? is giving you the return code of the last command. You can use it in an if .. then clause as well. Here I am using it simply with && which only executes the second command if the first returned code 0. So if the NFS Server is not mounted no backup will be executed.

[root@host1 ~]# mountpoint -q /root ; echo $?
[root@host1 ~]# mountpoint -q /mnt/backup ; echo $?

Alternatively, you could use this one-line if clause

0 3 * * * if mountpoint -q /mnt/backup ; then /usr/bin/rsync -a /source/ /mnt/backup/ ; else echo "Backup on Server abc failed." | mailx -s "Backup failed" webmaster@company.com ; fi

Oh, and here's another cool bash shortcut. With !$ you can use the last parameter of the last command. See:

[root@host1 ~]# mkdir -p /mnt/incredibly/long/path/to/something/
[root@host1 ~]# cd !$
cd /mnt/incredibly/long/path/to/something/
[root@host1 /mnt/incredibly/long/path/to/something]#