BackupWithCrontabAndNFSfileSystem

From RdiffBackupWiki

Jump to: navigation, search

crontab and NFS

cron/crontab is ideal for daily backups, because the machine schedules automatically the job execution. A simple crontab entry for daily backups would look like this:

 @daily /usr/local/bin/rdiff-backup --print-statistics  /mnt/home-from-server /mnt/backup/home >& /var/log/backup/home.log
  • The instruction '@daily' instructs 'cron' to execute the following line daily.
  • The option '--print-statistics' prints a summary, which is here re-directed to the log file '/var/log/backup/home.log'.
  • The directory '/mnt/home-from-server' is the home area of the server that is to be backed up, mounted via NFS in read-only mode.
  • The directory '/mnt/backup/home' is the location where the backup is stored.

A problem with this setup arises when the NFS server is not working. In that case the mount point '/mnt/home-from-server' still exists, but it is empty. Therefore, 'rdiff-backup' sees no files and, by updating the backup, erases all files in the current backup. To avoid that, one needs to check whether the NFS file system is mounted. Using 'crontab', a solution could be as follows:

 @daily grep -c 'HOME' /mnt/home-from-server/NFSid && /usr/local/bin/rdiff-backup --print-statistics /mnt/home-from-server /mnt/backup/home >& /var/log/backup/home.log

The file '/mnt/home-from-server/NFSid' contains the word 'HOME' and 'grep' returns the value '1'. Therefore, the second part of the instruction (the rdiff-backup call) after '&&' is executed as well. If NFS does not work, 'grep' returns '0' and the backup is not executed. Alternatively one could use the option '--test-server' and 'grep' the relevant content of the output.

Personal tools