# Backup Outlook Data Files using a Batch (.bat)

Last reviewed on February 12, 2013

This is really old school, from back in the days of DOS and Win3.1, but it still works great with Outlook and Windows 7. Copy a code block to notepad and save using the file extension .bat. Double click to run it. You can add it to the Startup folder if desired.

Use this instead of the Backup utility provided by Microsoft (which does not work with 64-bit Outlook).

Note: If your path doesn't include spaces, you don't need to use the double quotes.

For more information about the copy and xcopy commands and the switches you can use with them, see COPY, XCOPY, and MOVE Overwrite Functionality Changes in Windows (MSKB article)

Copy the pst file to a new location (overwrite existing file), when the copy is finished, start Outlook.

The /y switch overwrites the existing file, if it exists. Wait tells the batch to stop until the copy is finished before starting outlook.

copy /y "C:\path\to\original\datafile.pst" "C:\path\to\Backup\datafile.pst"
:wait
start outlook.exe


Copy the data file and give it a random name; when the copy is finished, start Outlook:

%random% replaces the file name with a random number to prevent files from being overwritten. Use the date stamp to identify the age of the files.

copy "C:\path\to\original\datafile.pst" "C:\path\to\Backup\"%random%.pst
:wait
start outlook.exe


Copy the pst file and rename it using today's date, start Outlook when the copy is complete.

This gets the date and breaks it down into year, month, day format, which we use in the filename of the copy. The batch waits for the copy to finish before starting Outlook.

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do copy "C:\path\to\outlook.pst" "C:\path\to\Backup\"backup-%%g-%%e-%%f.pst
:wait
start outlook.exe


Copy all pst files in the folder, add the date to their file name. Start Outlook when the copy is finished.

This copies all of the pst files in the folder and like the previous batch file, this one adds the date to the filename of the copied pst files.

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do copy "C:\Users\dianep\Documents\Outlook Files\"*.pst "C:\Users\dianep\Documents\Outlook Files\Backup\"*-%%g-%%e-%%f.pst
:wait
start outlook.exe


Copy other Outlook support files using a batch file

You can use a batch file to copy other files Outlook uses, including templates, signatures, and stationery. You can use the same methods used to copy the pst files, however, if you want to copy subfolders within a folder path, you'll need to use XCOPY instead of COPY.

Because the support files change less often, you can run this batch file weekly or after you make changes (such as editing your signature.)

To copy folders within a path, you'll need to use XCOPY and the /y and /e switches:

xcopy /y /e "C:\Users\username\AppData\Roaming\Microsoft\Templates\*.*" "C:\Backup\Templates\"