How to get your NAS to check you are backing up outlook.pst regularly and email you if you haven't

From SynologyWiki

Jump to: navigation, search

Even if you regularly run backup software you may not be backing up your outlook.pst file!

STOP - Do you have Windows XP, Windows 2003, or Windows Vista32? If so then you don't need this wiki. If you have Vista64 you would still benefit from this wiki.

STOP2 - Do you use a MS Exchange Server? If so then you also don't need this wiki.

For users of older MS Windows operating systems (e.g. Windows NT, 98, ME and 2000) and Vista64 outlook.pst can frequently not backup even if you run backup software regularly (I explain why below).

This wiki will show you how to create a script that will check how old your outlook.pst file is in your backed up data on your NAS, and if it is too old it will email you a reminder to backup outlook.pst.

Contents

Why should I be interested in this mod?

MS Windows operating systems other than Windows XP, Windows 2003, and Windows Vista32 don't allow applications (such as backup software) to access files that have been locked by another application (e.g. by MS Outlook). The Windows function that allows applications access to locked files is called "Shadow Copy". If you have MS Windows NT, 98, ME, 2000 or Vsta64 your system does not support "Shadow Copy" and hence Synology's Data Replicator 3 (DRIII) can't access (and therefore can't backup) files that are locked by an application.

If you use Microsoft's Outlook in local mode (non MS Exchange mode) all your MS Outlook data is (by default) stored in a file called outlook.pst. When MS Outlook is open it locks the file outlook.pst so it has exclusive access to it, great for Outlook but rubbish for everything else. If you run your backup software (e.g. DRIII) whilst you have MS Outlook open, it can't/won't backup the file outlook.pst.

So you need to remember to close MS Outlook before each backup takes place. But do you remember? I occasionally don't, hence this wiki! The problem can go unnoticed because if you schedule DRIII to run automatically at certain times, it will not intrusively notify you that it was unable to backup outlook.pst, it just skips the file and stores the fact in its log file.

Potentially the problem is very serious because if your backup software does not create multiple restore points (i.e. it just keeps 1 backup set) it will delete the previous outlook.pst file you had. So in effect if you leave MS Outlook open and a backup runs, it won't be able to backup outlook.pst and will delete any previous version of outlook.pst you had in your backup. If you use Synology's DRIII you can protect against the previous file version being deleted by making sure you use the "Enable file versions" option.

Overview of the mod

  1. Enable the CLI
  2. Install ipkg
  3. Install nail (an ipkg email client)
  4. Create the script
  5. Create a cronjob to run the script

The mod

  1. Login to the Command Line Interface as root
  2. If you don't already have an email client you will need to install one. I recomend nail, see nail in A short list of the more useful 900+ ipkg packages. To install nail you will need ipkg. If you don't already have ipkg installed see ipkg in Overview on modifying the Synology Server, bootstrap, ipkg etc. After installing nail test it to make sure it is working.
  3. Create a directory on the NAS to hold your script, e.g. "mkdir /volume1/my_scripts"
  4. Change to that directory, i.e. "cd /volume1/my_scripts"
  5. Create the check_outlook.pst_is_backed_up_regularly.sh script, i.e. "vi check_outlook.pst_is_backed_up_regularly.sh" and then paste the contents of the script given below into it. Make any changes and then save and exit vi.
  6. Set access rights, e.g. "chmod 755 check_outlook.pst_is_backed_up_regularly.sh"
  7. Edit the /etc/crontab file, i.e. "vi /etc/crontab" and add the line given in the example below. Save the file and close vi.
  8. Restart crond to get it to re-read the modified crontab file, i.e. "crond restart"
  9. Finished

The check_outlook.pst_is_backed_up_regularly.sh script

Below is the /volume1/my_scripts/check_outlook.pst_is_backed_up_regularly.sh script. This script will need some tailoring:

  1. It assumes you use nail as your email client. You will need to modify it if you dont.
  2. You will need to set your email address appropriately
  3. You will need to change "/volume1/my_backed_up_data_directory" to the shared directory on your NAS that you tell DRIII (or A.N.Other software) to use.
  4. You will need to change the "-mtime" value to what you want. The example below uses "-8" which means it checks to see if the outlook.pst file is older than 8 days.
  5. If it is older than 8 days it will send you an email to close outlook and run an imediate backup. You can change the email message to be as polite (or insulting) as you want.

#!/bin/sh
#This script checks I have backed up outlook.pst within the last week and then sends me an email if I haven't

var_check=$(find "/volume1/my_backed_up_data_directory" -name "outlook.pst" -mtime -8)

if [$var_check = ""]
    then

#send the email

var_subject="Outlook.pst hasn't been backed up for over a week"
var_content="Outlook.pst hasn't been backed up for over a week.

This is an automated email from your Synology NAS. Please remember to close Outlook before scheduled backups run. If you want you can close outlook now and then backup your computer using the Immediate button in Data Replicator 3 (DR3).

Do not reply to this email.

Thank you."

echo "$var_content" | /opt/bin/nail -s "$var_subject" youremailname@youremailaddress.com

#if the email fails nail will create a file dead.letter, test to see if it exists and if so wait 10minutes and then resend

while ls "/root/dead.letter"
    do
      echo email failed - waiting 10 minutes and then re-sending
      sleep 600
      rm "/root/dead.letter"
      echo "$var_content" | /opt/bin/nail -s "$var_subject" youremailname@youremailaddress.com
      sleep 10
done

fi

/etc/crontab entry

The last line below is the line to add to the end of your /etc/crontab file. Note: it is the TAB character between the column entries, not spaces. The wiki system does not seem to support tabs (or if it does I don't know how to do it). So if you copy and paste the entry below you will need to delete the spaces and use the TAB key to align the columns. The example below will run your script at 1am every monday, change the values as needed.


#minute hour    mday    month   wday    who     command
0       1       *       *       1       root    sh /volume1/my_scripts/check_outlook.pst_is_backed_up_regularly.sh

Are you using the LAN NAS to WAN NAS mod?

If you are also using the DataReplicator to LAN NAS to WAN NAS - For critical data with minimum data transfer mod then I recomend you make the change below to the script "sub_LAN_NAS_to_WAN_NAS_rsync_backup.sh" given in that wiki. This is because outlook.pst will possibly be one of the biggest files in the LAN to WAN synchronisation, and will be deleted on the WAN NAS if it isn't in the last backup set on the LAN NAS. If your last DRIII backup set does not include the outlook.pst file (becuase outlook was open when the backup ran) then the file will be deleted from the WAN NAS. When the next LAN to WAN rsync takes place and outlook.pst is back in the last backup set on your LAN NAS you will end up transfering the whole outlook.pst file over the internet to the WAN NAS.

replace the line

rsync -a -z --bwlimit=200 -L --delete --timeout=1200 --stats -e "ssh -v -l rsync -i /volume1/user_roots/rsync_user/.ssh/my_LAN_NAS_rsync_user_keys/my_LAN_NAS_rsync_user_rsa" --password-file=/root/my_WAN_NAS_rsync_password_file /volume1/my_LAN_and_WAN_backups rsync@xxx.xxx.xxx.xxx::$d1 >> /volume1/my_scripts/backup_log.txt

with...

# Set my_PC_name variable to the PC name as used by DRIII. This assumes only 1 DRIII client is being used
# If you want more than one PC to be backed up to this directory you will have to hard code the PC name
my_PC_name=`ls /volume1/$my_DRIII_LAN_backups_directory`

if
 ls "/volume1/my_LAN_and_WAN_backups/$my_PC_name/DRIVEC/Documents and Settings/BKL/Local Settings/Application Data/Microsoft/Outlook//outlook.pst"
    then
     rsync -a -z --bwlimit=200 -L --delete --timeout=1200 --stats -e "ssh -v -l rsync -i /volume1/user_roots/rsync_user/.ssh/my_LAN_NAS_rsync_user_keys/my_LAN_NAS_rsync_user_rsa" --password-file=/root/my_WAN_NAS_rsync_password_file /volume1/my_LAN_and_WAN_backups rsync@xxx.xxx.xxx.xxx::$d1 >> /volume1/my_scripts/backup_log.txt
    else
     echo "error: rsync skipped - No outlook.pst file" >> /volume1/my_scripts/backup_log.txt
     echo "Re-run Data Replicator 3 and then run the script make_symbolic_link_and_rsync_LAN_NAS_to_WAN_NAS.sh" >> /volume1/my_scripts/backup_log.txt
fi
Personal tools