Automatic Backup of Outlook connected to Exchange Server

Posted on 2008-10-13
Last Modified: 2012-05-05
We need to backup Outlook automatically, every day.

Here are the circumstances:
Outlook 2007
Connected over Internet to Exchange Server.

There isn't a  .pst file.  There's an .ost file. My understanding of the  .ost  file is that it isn't the same as a .pst.  I don't know if backing up a copy of the .ost will help when there's damage to Outlook information.

Unless this is otherwise, I would like to have a complete export of the mailbox to a  local  .pst done every night automatically.  I am unsure of the scriptability of Outlook 2007.

Is there any software that would reliably do this?  The host makes a backup of the Exchange Server every night, but they want too much $$$ to perform a recovery.  If we had a local copy, we wouldn't have to get into an argument with them should we need to restore.  WE just had an incident where messages disappeared, and the host blamed us, and the rep asked if we 'had any proof' that they were responsible for the missing files.  


Question by:computerlarry
LVL 97

Assisted Solution

war1 earned 50 total points
Comment Utility
Hello computerlarry,

Backing up the OST file will back up what is on the Exchange.  You will need Exchange server and Outlook to open OST file.  For PST file, you only need Outlook to open the file. (You can convert OST file to PST file, but will involve some cost.)

Hope this helps!
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, computerlarry.

Outlook is very scriptable and copying everything to a PST file is pretty simple.  Running it at night though is a bit of a problem.  Outlook has to be running under the account that owns the mailbox for a script to work.  That means everyone would have to leave their computer logged in at night for the backup to run.  The workstation could be locked, but it would have to stay logged in.  Another approach would be to schedule the backup to run during the day.  I can provide the script if you want to go this route.  The script will have to be added to each computer.

Author Comment

Comment Utility
BlueDF - could I please have that script?

LVL 76

Accepted Solution

David Lee earned 450 total points
Comment Utility
Sure.  Here it is.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on Module1
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comments wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Select Macro Security
10.  Ensure the security setting is one of the bottom two options
11.  Close Outlook
12.  Start Outlook

Run the macro whenever you want to backup the mailbox.
Sub BackupMailboxToPSTFile()

    'Change the path on the following line to your path

    Const BACKUP_PATH = "C:\eeTesting\Backups\"

    Dim strBackupFileName As String, _

        objFSO As Object, _

        olkRootFolder As Outlook.MAPIFolder, _

        olkFolder As Outlook.MAPIFolder, _

        olkFolderCopy As Outlook.MAPIFolder, _

        olkBackup As Outlook.MAPIFolder

    strBackupFileName = "BU " & Format(Time, "hhmm") & "_" & Format(Date, "dd mmm yyyy") & ".pst"

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If objFSO.FileExists(BACKUP_PATH & strBackupFileName) Then

        MsgBox "The mailbox was already backed up within the last minute.", vbInformation + vbOKOnly, "Folder BackUp"


        Session.AddStore BACKUP_PATH & strBackupFileName

        Set olkBackup = OpenOutlookFolder("Personal Folders")

        olkBackup.Name = strBackupFileName

        Session.RemoveStore olkBackup

        Session.AddStore BACKUP_PATH & strBackupFileName

        Set olkBackup = OpenOutlookFolder(strBackupFileName)

        Set olkRootFolder = Session.GetDefaultFolder(olFolderInbox).Parent

        For Each olkFolder In olkRootFolder.Folders

            Set olkFolderCopy = olkFolder.CopyTo(olkBackup)


        Session.RemoveStore olkBackup

    End If

    Set objFSO = Nothing

    Set olkBackup = Nothing

    Set olkRootFolder = Nothing

    Set olkFolder = Nothing

    Set olkFolderCopy = Nothing

    MsgBox "Backup complete.", vbInformation + vbOKOnly, "Backup Mailbox to PST"

End Sub

Function IsNothing(obj)

  If TypeName(obj) = "Nothing" Then

    IsNothing = True


    IsNothing = False

  End If

End Function

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder

    Dim arrFolders As Variant, _

        varFolder As Variant, _

        olkFolder As Outlook.MAPIFolder

    On Error GoTo ehOpenOutlookFolder

    If strFolderPath = "" Then

        Set OpenOutlookFolder = Nothing


        If Left(strFolderPath, 1) = "\" Then

            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)

        End If

        arrFolders = Split(strFolderPath, "\")

        For Each varFolder In arrFolders

            If IsNothing(olkFolder) Then

                Set olkFolder = Session.Folders(varFolder)


                Set olkFolder = olkFolder.Folders(varFolder)

            End If


        Set OpenOutlookFolder = olkFolder

    End If

    On Error GoTo 0

    Exit Function


    Set OpenOutlookFolder = Nothing

    On Error GoTo 0

End Function

Open in new window


Expert Comment

Comment Utility
As would be code to copy all the *. pst? incremental *.pst

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now