...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.


Batch File

NTBackup: An Enterprise Backup Solution (Part 2)

Sunday, December 12, 2010 in Technical Articles (Views: 3369)
In Part 1 of this series, we talked about running NTBackup, and in this section we'll talk about what to do with the logs and email them. For this, you will need some tools, I use sendemail.exe, a freeware tool, but you can use a tool of your liking. For the purpose of this blog, we're going to use my tool of choice.

In the interest of security, don't use a high security account to send email, since the information in this batch file is in plain text. This file is called sendreport.bat, and like the last blog, I will bold my comments for you to see. Also, all my files are in C:\Backup, so keep this in mind while you read the batch file:

Quickly, here's a breakdown of the command line arguments:

%1: Backup folder: If your backup is called UserData, this is the folder and name that the file will get. This is to insure things stay uniform.

%2: Description (and email subject)

Here's the file:

@echo off

Set authentication for the mail user here.

set mailuser=""
set mailpassword="YourPassword"

We are going to create a folder for the logs, if one doesn't already exist.
if not exist \backup\logs\%1 md \backup\logs\%1
cd \backup\logs\%1

I keep the last week of backup logs, not that they are huge files, but they are also being emailed. So, I have a copy in my inbox past 7 days, and if not, I can look at these logs manually. The set copycmd is a statement which ignores overwriting an existing file.

Set copycmd=/y
if exist %1backup07.log erase %1backup07.log
if exist %1backup06.log copy %1backup06.log %1backup07.log
if exist %1backup05.log copy %1backup05.log %1backup06.log
if exist %1backup04.log copy %1backup04.log %1backup05.log
if exist %1backup03.log copy %1backup03.log %1backup04.log
if exist %1backup02.log copy %1backup02.log %1backup03.log
if exist %1backup01.log copy %1backup01.log %1backup02.log

The NTBackup logs are sent here, so we just need to get to this folder.

cd %USERPROFILE%\"local settings\application data\microsoft\windows nt\ntbackup\data"

There should only be a single backup log, but just to make sure, I'll copy them all into the new backup log.

type *.log >c:\backup\logs\%1\%1backup01.log

Of course, clean up after yourself – otherwise more backup logs will pile up and your emails will keep getting longer…

erase *.log
cd \backup

I like putting a header on my backup report, it makes it easier to read.

Echo Backup Report >%1backuplog.txt
echo Created on %date% at %time% >>%1backuplog.txt
echo. >>%1backuplog.txt

This is the final log which will be emailed.

type \backup\logs\%1\%1backup01.log >>%1backuplog.txt

I then call sendemail.exe to send the message. Syntax, of course, varies with your tool of choice.

sendemail -t %mailto% -u %2 -f %mailuser% -xu %mailuser% -xp %mailpassword% -s %mailsvr% -o message-file=%1backuplog.txt

Clean up the final files.

erase *.txt


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.