StevensNet.com

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

Blogs

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

Tags

Batch File
Opinion
Technical
VBScript
Windows

NTBackup: An Enterprise Backup Solution (Part 1)

Sunday, December 12, 2010 in Technical Articles (Views: 5097)
For those who use NTBackup, it's not just a tool included in Windows Server 2003, XP and older Operating Systems. I have previously posted here how NTBackup can be installed on 2008 and 2008 R2.

In this blog, I am going to share with you the batch file I use to call NTBackup to do our backups. Why NTBackup? Because it's free, included, and gives me the capability to back up individual files and folders. This is a sharp contrast to Windows Backup, which makes you back up an entire disk.

Here is the batch file, along with commentary… Of course, parts are obscured for security's sake. There are a lot of command line parameters, as to be flexible with the tool. Items which are bolded are not meant for the batch file, as well as to slow down the copy/paste method and describe the complexity of this file.

On my Windows 2008 backup server, I keep NTBackup and all support files (including the batch files) in C:\Backup.

Of course, it's not normal in the world we live in not to provide a disclaimer. Make sure you test this file, use and modify it to your liking. In no way am I liable for anything you do with this script, NTBackup, or somehow cripple yourself trying. If you lose data, get fired, or are attacked by a gang looking for money and homework, I won't be responsible. However, if you do something cool or are successful with it, I wouldn't mind hearing it.

Some considerations to make when you run disk to disk backups:

• Don't use compressed folders, if you can avoid it. The main reason for this is all about performance. One example is for us to backup a lot of our pictures and media takes about 3 1/2 hours on compressed folders, but only 2 on non-compressed folders.
• NT Backup doesn't have encryption built in. You can always use EFS to take care of this. See my above point about encryption.

@echo off

These next lines will tell the batch file to display syntax if anything is missing. It doesn't check to see if the parameters are in the right order, or check out. For a greater description of the batch parameters, see the syntax section. The syntax section will also give you examples as to how to run the script.

if [%1]== [] GOTO SYNTAX
if [%2]== [] GOTO SYNTAX
if [%3]== [] GOTO SYNTAX
if [%4]== [] GOTO SYNTAX
if [%5]== [] GOTO SYNTAX
if [%6]== [] GOTO SYNTAX
if [%7]== [] GOTO SYNTAX

Now, we're putting the variables in place. One thing you may ask is what the localdir variable would be if we are backing up to a network drive. This is something the renfile.vbs script processes. The vbscript is also on stevensnet.com and serves the purpose of renaming a file on another machine.

set UserBackupDir=%3\%2
set LocalDir=%4\%2
set BackupServer=%5
set UserToBackupDir=%6

This just simply tells us whether we're going to do a normal (or full) backup or a differential. Sure, you can change this to support incremental backups, but I am not a fan of this method.

if [%1]== [/n] GOTO FULL
if [%1]== [/d] GOTO DIFF

If somehow the logic slips this far, show the syntax.

GOTO SYNTAX

:DIFF

The first thing I do is keep differential backups for one week. I backup Differential Monday-Saturday, so this would be 6 backups. I want the newest backup to be first. This makes things much easier to determine which file is what backup. Again, the renfile.vbs script is at stevensnet.com as well.

if exist %UserBackupDir%\%2_Differential06.bkf erase %UserBackupDir%\%2_Differential06.bkf
if exist %UserBackupDir%\%2_Differential05.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_Differential05.bkf %LocalDir%\%2_Differential06.bkf
if exist %UserBackupDir%\%2_Differential04.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_Differential04.bkf %LocalDir%\%2_Differential05.bkf
if exist %UserBackupDir%\%2_Differential03.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_Differential03.bkf %LocalDir%\%2_Differential04.bkf
if exist %UserBackupDir%\%2_Differential02.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_Differential02.bkf %LocalDir%\%2_Differential03.bkf
if exist %UserBackupDir%\%2_Differential01.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_Differential01.bkf %LocalDir%\%2_Differential02.bkf
if exist %UserBackupDir%\%2_Differential.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_Differential.bkf %LocalDir%\%2_Differential01.bkf

Here is where we actually call NTBackup.

ntbackup backup %UserToBackupDir% /d %7 /f %UserBackupDir%\%2_Differential.bkf /snap:off /v:no /r:no /rs:no /hc:on /j %COMPUTERNAME% /l:s /m Differential /um

GOTO EMAIL



:FULL

This is the same concept as the differentials, but I do want to keep more than one live copy of the backup on disk.

if exist %UserBackupDir%\%2_FullBackup_04.bkf erase %UserBackupDir%\%2_FullBackup_04.bkf if exist %UserBackupDir%\%2_FullBackup_03.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_FullBackup_03.bkf %LocalDir%\%2_FullBackup_04.bkf
if exist %UserBackupDir%\%2_FullBackup_02.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_FullBackup_02.bkf %LocalDir%\%2_FullBackup_03.bkf
if exist %UserBackupDir%\%2_FullBackup_01.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_FullBackup_01.bkf %LocalDir%\%2_FullBackup_02.bkf
if exist %UserBackupDir%\%2_FullBackup.bkf cscript renfile.vbs %BackupServer% %LocalDir%\%2_FullBackup.bkf %LocalDir%\%2_FullBackup_01.bkf

Of course, we need to call NTBackup.

ntbackup backup %UserToBackupDir% /d %7 /f %UserBackupDir%\%2_FullBackup.bkf /snap:off /v:no /r:no /rs:no /hc:on /j %COMPUTERNAME% /l:s /um

This is part 2 of the blog, but email reporting is a great feature of the batch file. We'll go into logging a bit later.

GOTO EMAIL


:SYNTAX

This is how the batch file works, with examples…

echo Consolidated Backup Script, written by Lee Stevens of StevensNet.com. There are several command line parameters, so here is what you need to use.
echo We will assume the name of the script is called Data_Backup.bat.
echo Note: All command line arguments are mandatory.
echo.
echo Usage: Data_Backup (backup type) (Folder Name) (Dest folder) (Local folder) (Server Name)
echo (Backup Folder) (Description)
echo Definitions:
echo.
echo Backup Type: Normal (Full) is /n - Differential is /d
echo.
echo Folder Name: This is the folder name you are backing up.
echo For example: User_Data.
echo This is a very important variable, as many things later reference it.
echo It is expected that you have a good naming convention because the majority
echo of this script revolves around this variable.
echo.
echo Dest Folder: This is where the backup file will be stored.
echo For example: \\Server1\Backups\User_Data.
echo This can also be a local path such as C:\Backups\User_Data.
echo.
echo Local Folder: For an instance of NTBackup that will be backing up a remote
echo server, this would be the local folder on the remote server that the backups
echo are being stored on. This is used for the renfle.vbs script mentioned. For
echo more information on this, go to stevensnet.com and search for the blog
echo referencing the renfile.vbs script. If just doing the backup locally, just
echo leave this as the local path.
echo.
echo Server Name: Again, this option is for remote backups and tells the script what
echo server is being backed up. If this is the local machine, you can use the
echo COMPUTERNAME variable, or type in the remote Computer Name.
echo.
echo Backup Folder: This is the name of the folder that is being backed up.
echo.
echo Description: This is a Description for your backup, for later when you email
echo yourself a report. This will also go in the backup logs. Also, if you are
echo wanting to put spaces in your description, don't forget to put this argument
echo inside quotation marks.
echo.
echo Putting it all together, assuming the following (this is a local backup):
echo - Backup will be a full backup
echo - You're backing your User_Data folder up to D:\Backups
echo - The local folder is D:\Backups on Server1
echo - We are backing up the F:\User_Data folder
echo.
echo The command line would look like this:
echo Data_Backup /n User_Data D:\Backups D:\Backups Server1 F:\User_Data "User Data Backup" echo.
echo Assuming a remote backup from Server2 to Server1:
echo - Backup will be a full backup
echo - You're backing your User_Data folder up to \\Server1\Backups (Share)
echo - The local folder is D:\Backups on Server1
echo - We are backing up the F:\User_Data folder.
echo.
echo The command line would look like this:
echo Data_Backup /n User_Data \\Server1\Backups D:\Backups Server1 F:\User_Data "User Data Backup"
echo.
echo For more information, visit StevensNet.com, as this blog/article/script may
echo have changed.
echo.
echo This script is provided free of charge and there are no warranties or liability
echo from Lee Stevens or StevensNet.com in your usage of the script. Make sure to
echo test this script and make sure it works before putting this into any production
echo environment.
GOTO END


:EMAIL

In Part 2, we will discuss how the reporting and logs work.

call sendreport.bat %2 "[%Date%]: "%7""

GOTO END


:END

 

Related Blogs You May Be Interested In:


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