Archive for the 'Batch Files' Category

Adaptation to EricBackup.bat

I took the liberty to adapt EricBackup.bat created by Eric.
Eric graciously permitted me to post to his blog aswell.

I have almost completely rewritten the batchfile for it to meet my fancy ;)
Replaced blat with sendmail and using delage32 to cleanup previous backupfiles and logfiles.
Date and time variables are in European format, change this if you want/need to.
The first part declares a bunch of variables, read this carefully.

Hands down to Eric, he laid the foundation for me to create this.

Below the source I have created. Comments are welcome.

MyBackup.bat

@ECHO OFF
:: ====
:: PROGRAM           : MYBACKUP.BAT
:: BY                : M.T.D. JONKER
:: ADAPTED FROM      : EricBackup.bat Version 2.8, EricGreer@GMail.com, http://blog.integrii.net/?p=76
:: CREATION DATE     : 20-12-2008
:: LATEST REVISION   : 22-02-2009
::====
::22-02-2009: REDID REMOVAL OF OLD BACKUPFILES AND LOGFILES THROUGH EXTERNAL TOOL DELAGE32
::20-01-2009: ADDED REMOVAL OF PREVIOUS LOGFILES
::20-01-2009: CREATED VARIABLE “BACKUPFILE” TO REMOVE CLUTTER
::20-01-2009: REWROTE REMOVAL OF PREVIOUS BACKUPFILES
::10-01-2009: ADDED REMOVAL OF PREVIOUS BACKUPFILES
::22-12-2008: REPLACED BLAT WITH SENDMAIL
::20-12-2008: REWROTE BATCHFILE
::====
TITLE ADVANCED NTBACKUP SCRIPT
COLOR 1F
::====SET VARIABLES.HERE====
::ADJUST VARIABLES TO MEET YOUR PREFERENCE

::BACKUP RELATED VARIABLES
::SET USERNAME (AS SHOWN IN C:\DOCUMENTS AND SETTINGS\<USERNAME>),
SET USER=<username>
::PATH TO PUT LOGFILES OF THIS BATCHFILE AND NTBACKUP
SET ARCHIVEPATH=C:\Backups\logs
:: ORIGINAL (DEFAULT) LOCATION OF NTBACKUP LOGFILE
SET LOGPATH=”%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data”
::SET THE DESTINATION FOLDER OF YOUR BACKUP
SET DESTINATION=C:\BACKUPS\%COMPUTERNAME%
::SET PATH TO SENDMAIL.EXE
SET MAILPATH=C:\Backups\sendmail.exe
::SET PATH TO delage32.exe
SET DAPATH=C:\Backups\delage32.exe
::SET NAME OR IP OF SMTPSERVER TO BE USED
SET SMTPSERVER=smtp.server.com
::SET THE TO ADDRESS
SET TO=name@domain.com
::SET THE FROM ADDRESS
SET FROM=name@domain.com
::SET THE SOURCE OF YOUR BACKUP (FOR EXAMPLE: D:) NOT USED IN SYSTEMSTATE BACKUP
::SET SOURCE=D:
::SET A NOTE TO DESCRIBE YOUR BACKUP (USED IN FILENAME, SO REFRAIN FROM USING NON COMPATIBLE CHARACTERS)
::SET NOTE=D-DRIVE
::====COMMAND LINE PASSING====
::THE VARIABLES NOTE AND SOURCE CAN BE PASSED FROM THE COMMAND LINE.
::EIHTER SET THEM ABOVE OR USE THE SETTING BELOW
::COMMENT/UNCOMMENT AS NEEDED
::WHEN PASSED FROM THE COMMAND LINE BOTH SOURCE AND NOTE MUST BE PROPERLY FILLED
::SO USE SHORT FILENAMES SUCH AS C:\DOCUME~1\, WITHOUT QUOTES
SET SOURCE=%2
::USED IN FILENAME, SO REFRAIN FROM USING NON COMPATIBLE CHARACTERS
SET NOTE=%3
::====DONE SETTING MANUAL VARIABLES====

::DETERMINE BACKUPMODE
SET BACKUPMODE=NONE
IF “%1″ == “systemstate” SET BACKUPMODE=SYSTEMSTATE
IF “%1″ == “normal” SET BACKUPMODE=NORMAL
IF “%1″ == “differential” SET BACKUPMODE=DIFFERENTIAL
IF %BACKUPMODE% == NONE GOTO NOPARAMS

::SET TIME AND DATE VARIABLES, (EUROPEAN FORMAT)  DO NOT TOUCH (UNLESS OTHER FORMAT)
FOR /F “TOKENS=1,2 DELIMS=:” %%A IN (’TIME /T’) DO (
SET HR=%%A
SET MIN=%%B
SET TM=%%A%%B
SET TME=%%A:%%B
)
FOR /F “TOKENS=2,3,4 DELIMS=- ” %%A IN (’DATE /T’) DO (
SET D=%%A
SET M=%%B
SET Y=%%C
SET DT=%%A-%%B-%%C
SET DTE=%%C%%B%%A
)
::====!!!OTHER VARIABLES, DO NOT CHANGE!!!====
:: NAME OF SYSTEM TO BE BACKED UP
SET SYS=%COMPUTERNAME%
::NAME OF BACKUPFILE (THIS IS LATER USED IN REMOVING PREVIOUS BACKUPFILES)
SET BACKUPFILE=%SYS%_%BACKUPMODE%_%NOTE%_%DT%.bkf
::LOGFILE OF THIS BATCHFILE
SET BATCHLOG=%ARCHIVEPATH%\%BACKUPMODE%_%NOTE%_%DT%_%TM%.txt
::NAME OF NTBACKUP LOGFILE TO BE ARCHIVED
SET NTBARCLOG=%BACKUPMODE%_%NOTE%_%DT%_%TM%.log
::====DONE SETTING VARIABLES====
::====

::CREATE ARCHIVE AND DESTINATION PATHS IF THEY DO NOT EXIST
IF NOT EXIST “%ARCHIVEPATH%” MD “%ARCHIVEPATH%” & ECHO “ARCHIVE PATH DID NOT EXIST, SO IT WAS CREATED.” & ECHO.>> %BATCHLOG%
IF NOT EXIST “%DESTINATION%” MD “%DESTINATION%” & ECHO “DESTINATION PATH DID NOT EXIST, SO IT WAS CREATED.” & ECHO.>> %BATCHLOG%

::BACKUP SELECTION, LOG TO CMD WINDOW
ECHO.
ECHO *********************************************************
ECHO * JOB %NOTE% STARTED
ECHO *********************************************************
ECHO *
IF %BACKUPMODE% NEQ SYSTEMSTATE ECHO * JOB SOURCE: %SOURCE%

IF %BACKUPMODE% == SYSTEMSTATE ECHO * %SYS% %BACKUPMODE% BACKUP STARTED AT %TME% ON %DT% & ECHO * TO %DESTINATION%\%BACKUPFILE% & ECHO %SYS% %BACKUPMODE% BACKUP STARTED AT %TME% ON %DT% TO %DESTINATION%\%BACKUPFILE% >> %BATCHLOG%
IF %BACKUPMODE% == DIFFERENTIAL ECHO * %SYS% %BACKUPMODE% BACKUP OF %SOURCE% STARTED AT %TME% ON %DT% & ECHO * TO %DESTINATION%\%BACKUPFILE% & ECHO %SYS% %BACKUPMODE% BACKUP OF %SOURCE% STARTED AT %TME% ON %DT% TO %DESTINATION%\%BACKUPFILE% >> %BATCHLOG%
IF %BACKUPMODE% == NORMAL ECHO * %SYS% %BACKUPMODE% BACKUP OF %SOURCE% STARTED AT %TME% ON %DT% & ECHO * TO %DESTINATION%\%BACKUPFILE% & ECHO %SYS% %BACKUPMODE% BACKUP OF %SOURCE% STARTED AT %TME% ON %DT% TO %DESTINATION%\%BACKUPFILE% >> %BATCHLOG%

::START BACKUP DEPENDING ON BACKUPMODE
IF %BACKUPMODE% == SYSTEMSTATE ntbackup.exe backup systemstate /n “%sys%-Backup” /d “%sys%-Backup” /v:no /r:no /rs:no /hc:off /j “%sys%-Backup” /l:s /f “%destination%\%BACKUPFILE%” >> %BATCHLOG%
IF %BACKUPMODE% == DIFFERENTIAL ntbackup.exe backup “%source%” /n “%sys%-Backup” /d “%sys%-Backup” /v:no /r:no /rs:no /hc:off /m differential /j “%sys%-Backup” /l:s /f “%destination%\%BACKUPFILE%” >> %BATCHLOG%
IF %BACKUPMODE% == NORMAL ntbackup.exe backup “%source%” /n “%sys%-Backup” /d “%sys%-Backup” /v:no /r:no /rs:no /hc:off /m normal /j “%sys%-Backup” /l:s /f “%destination%\%BACKUPFILE%” >> %BATCHLOG%

::ARCHIVE LOGFILES
::CLEAR TIME VARIABLES AND SET ANEW
SET HR=
SET MIN=
SET TM=
SET TME=
FOR /F “TOKENS=1,2 DELIMS=:” %%A IN (’TIME /T’) DO (
SET HR=%%A
SET MIN=%%B
SET TM=%%A%%B
SET TME=%%A:%%B
)
::GET NTBACKUP LOGFILE NAME
FOR /F “TOKENS=1,2,4 DELIMS= ” %%A IN (’dir %LOGPATH% *.log ^| find “%dt%” ^| find “%tme%”‘) DO SET NTBLOG=%%C >NUL
ECHO NTBACKUP LOGFILE FOT THIS JOB: %LOGPATH%\%NTBLOG% >> %BATCHLOG%
::COPY AND RENAME THE NTBACKUP LOGFILE
IF EXIST %LOGPATH%\%NTBLOG% copy %LOGPATH%\%NTBLOG% %ARCHIVEPATH% /Y >NUL
IF EXIST %ARCHIVEPATH%\%NTBLOG% ren %ARCHIVEPATH%\%NTBLOG% “%NTBARCLOG%”
::CHECK LOGFILE FOR BACKUP SUCCESS
SET ERRORLEVEL=
find /I “BACKUP COMPLETED” “%ARCHIVEPATH%\%NTBARCLOG%” >NUL
GOTO %ERRORLEVEL%
:0
SET SUCCESS=1
ECHO * BACKUP COMPLETED SUCCESSFULLY & ECHO BACKUP COMPLETED SUCCESSFULLY >> %BATCHLOG%
GOTO SUCCESSBACKUP
:1
SET SUCCESS=0
ECHO * BACKUP FAILED & ECHO BACKUP FAILED >> %BATCHLOG%
GOTO FAILBACKUP

:SUCCESSBACKUP
::SEND EMAIL WITH NTBACKUP LOGFILE ATTACHED
IF %SUCCESS% == 1 %MAILPATH% /smtpserver %SMTPSERVER% /to %TO% /from %FROM% /subject %BACKUPMODE% Backup %NOTE% Successful /body %BACKUPMODE% Backup %NOTE% Successful /attachment %ARCHIVEPATH%\%NTBARCLOG% >> %BATCHLOG%

::CLEANUP PREVIOUS BACKUPFILES
::IF NO PREVIOUS BACKUPFILE EXISTS, SKIP TO CLEANIN LOGFILES
IF NOT EXIST %DESTINATION%\*%BACKUPMODE%_%NOTE%* ECHO NO PREVIOUS BACKUPFILE(S) FOR %BACKUPMODE%_%NOTE% EXIST >> %BATCHLOG% & GOTO CLLOG
::IF PREVIOUS BACKUPFILE(S) EXIST, DELETE ALL PREVIOUS BACKUPFILES. FILTERED BY VARIABLES %BACKUPMODE% & %NOTE%
::THE FOLLOWING STATEMENT IS COMPLETELY DEPENDEND ON THE MAKEUP OF THE VARIABLE %BACKUPFILE%
IF %NOTE% == note %DAPATH% %DESTINATION%\*%BACKUPMODE%_%NOTE%* 60 >> %BATCHLOG% & GOTO CLLOG
IF %BACKUPMODE% == SYSTEMSTATE %DAPATH% %DESTINATION%\*%BACKUPMODE%_%NOTE%* 60 >> %BATCHLOG% & GOTO CLLOG
::FOR /F “TOKENS=1-7 DELIMS=_-.” %%A IN (’DIR %DESTINATION%\*%BACKUPMODE%_%NOTE%* /B’) DO IF “%%F%%E%%D” LSS “%DTE%” SET BF=%%A_%%B_%%C_%%D-%%E-%%F.%%G & DEL %DESTINATION%\%BF% & IF ERROLEVEL NEQ 0 ECHO PREVIOUS BACKUPFILE %DESTINATION%\%BF% DELETED >> %BATCHLOG% & GOTO CLLOG
ECHO NO (PREVIOUS) BACKUPFILE(S) DELETED >> %BATCHLOG%

:CLLOG
::CLEANUP ARCHIVED LOGFILES
::IF NO PREVIOUS LOGFILE EXISTS, SKIP TO NEXT
IF NOT EXIST %DESTINATION%\*%BACKUPMODE%_%NOTE%* ECHO NO PREVIOUS LOGFILE(S) FOR %BACKUPMODE%_%NOTE% EXIST >> %BATCHLOG% & GOTO NEXT
::IF PREVIOUS LOGFILE(S) EXIST, DELETE ALL PREVIOUS LOGFILES. FILTERED BY VARIABLES %BACKUPMODE% & %NOTE%
::THE FOLLOWING STATEMENT IS DEPENDEND ON THE MAKEUP OF THE VARIABLE %BATCHLOG% & %NTBARCLOG%
IF %NOTE% == note %DAPATH% %ARCHIVEPATH%\*%BACKUPMODE%_%NOTE%* 60 >> %BATCHLOG% & GOTO NEXT
::FOR /F “TOKENS=1-5 DELIMS=_-.” %%A IN (’DIR %ARCHIVEPATH%\*%BACKUPMODE%_%NOTE%* /B’) DO IF “%%F%%E%%D” LSS “%DTE%” SET LF=%%A_%%B_%%C-%%D-%%E_*.* & DEL %ARCHIVEPATH%\%LF% & IF ERROLEVEL NEQ 0 ECHO PREVIOUS LOGFILE(S) %ARCHIVEPATH%\%LF% DELETED >> %BATCHLOG% & GOTO NEXT
ECHO NO (PREVIOUS) LOGFILE(S) DELETED >> %BATCHLOG% & GOTO NEXT

:FAILBACKUP
IF %SUCCESS% == 0 %MAILPATH% /smtpserver %SMTPSERVER% /to %TO% /from %FROM% /subject %BACKUPMODE% Backup %NOTE% Failed /body %BACKUPMODE% Backup %NOTE% Failed /attachment %ARCHIVEPATH%\%NTBARCLOG% >> “%BATCHLOG%”

:NEXT
IF EXIST “%ARCHIVEPATH%\%NTBARCLOG%” ECHO NTBACKUP.EXE .LOG FILE ARCHIVED AT “%ARCHIVEPATH%\%NTBARCLOG%” >> %BATCHLOG%
ECHO BATCHLOG .TXT FILE ARCHIVED AT “%BATCHLOG%” >> %BATCHLOG%

GOTO END

:NOPARAMS
ECHO ********************************************************
ECHO THIS FILE MUST BE CONFIGURED BY OPENING IT IN NOTEPAD.
ECHO SETTING THE VARIABLES IN THE VARIABLES SECTION.
ECHO TO RUN THE FILE AFTER YOU CONFIGURE IT,
ECHO YOU MUST SPECIFY A BACKUP TYPE AS THE FIRST PARAMETER.
ECHO THE FIRST PARAMETER SHOULD BE IN lowercase.
ECHO SOURCE AND NOTE CAN BE PASSED FROM THE COMMAND LINE,
ECHO READ THE VARIABLES SECTION OF THIS FILE
ECHO.
ECHO EXAMPLE 1:
ECHO MYBACKUP systemstate [source] [note]
ECHO.
ECHO EXAMPLE 2:
ECHO MYBACKUP normal [source] [note]
ECHO.
ECHO EXAMPLE 3:
ECHO MYBACKUP differential [source] [note]
ECHO.
ECHO ********************************************************
PAUSE

:END
CLS
EXIT

Source and support files can be downloaded here

SharePoint Services 3.0 Command Line Backup Script With 7 Day Full Retention and Email Reporting

This backup script fully backs up your SharePoint Services 3.0 site to a specified location and keeps copies of backups for 7 days. You’ll have to set the variables at the top of the script, then schedule it to run with the windows task scheduler, and then you’re off!

Oh, and you’ll need blat.exe – you can download it directly from me if you like here. OR Google it if you don’t trust me.

location – Location you want your backups to be stored.
blat – Location of blat.exe
relayserver – An email server you have relay access to.
yourserver – Your SharePoint site’s URL.
templog – Temp location logs are stored before being emailed.
file – Name of the SharePoint backup files that will be created.
to – Who the email reports go to.
who – Who the email should come from.
reply – Where email replies should go.

SPBackup.bat

echo blog.integrii.net SharePoint Services 3 7 Day Command Line Backup Script Version 1

set location=d:\sharepoint\backup
set blat=c:\windows\system32\blat.exe
set relayserver=mail.yourrelayserver.com
set yoursite=https://sharepoint.yoursite.com
set emailsub=SharePointBackupReport
set templog=c:\batch\spbackup.txt
set file=Backup.bak
set to=sys-ops@yourdomain.com
set who=sharepointbackup@yourdomain.com
set reply=noreply@yourdomain.com

del %location%\%file%.7day
rename %location%\%file%.6day %file%.7day
rename %location%\%file%.5day %file%.6day
rename %location%\%file%.4day %file%.5day
rename %location%\%file%.3day %file%.4day
rename %location%\%file%.2day %file%.3day
rename %location%\%file%.1day %file%.2day
rename %location%\%file% %file%.1day
“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\Stsadm.exe” -o backup -overwrite -url %yoursite% -backupmethod full -filename %location%\%file% > %templog%
dir %location% >> %templog%
%blat% “%templog%” -t %to% -s “%emailsub%” -i %who% -f “%reply%” -q -server “%relayserver%”

Please comment any problems you have so we can get this baby just right!

Automatic and Dynamic All Purpose NTBackup.exe Script with Email Notifications and Log Archiving (EricBackup.bat)

This script can do a SystemState, Normal or Differential backup via NTBackup from any location, to any location and have an email report sent to you shortly before the logfile is archived in your designated directory. All you have to do is set all the settings that i describe below in the top section of the script, put in any mapped drives you need to be mapped (net use x: \\server\share /user:user pass) where I have it commented and run it with the desired backup type specified. You can run ericbackup.bat alone to see a help display, too. This certainly isn’t anything new, but it is handy because this script can be easily molded, with it’s built in settings, to work in almost any situation. If you are running this as a task, you must remember to include the type of backup in the run line of the task. Simply specifying the .bat will not work, you must specify as the example useage below shows.

I would also like everyone to know that this file can be run remotely with psexec… see this article for PowerShell and this article for batch on how to do that. But remember: If you use psexec to run this remotely, the user will be “Default User”.

blatpathThe path to blat.exe, which is used to email your reports to you.
relayserverAn email server your computer has access to. This is required to have your report email sent to you.
emailThe email your reports will be sent to.
fromemailThis is the address the email will appear to be sent from. Important because some mailservers will filter mail baised ont his. Your own email should be fine.
emailuserYour email server user login.
emailpassYour email server password.
sourceThe directory your backup will be targeting. Systemstate backups will ignore this automatically. If you’re targeting the root of a drive, you leave out the ending \ character (ex: c: not c:\). If you want to use a ANSI .bks file, you can specify that here with an @ symbol ahead of it. EX) @c:\filelist.bks Using a unicode .bks file lets you list multiple target locations.
destinationThe location your backup files will be placed into… in *.BKF format. If you’re targeting the root of a drive, you leave out the ending \ character (ex: c: not c:\).
textlogpathPath to the text logfile which will track progress and be emailed then archived.
archivepathThe place logs will be placed for storage. Files will be renamed appropriately.
usernameThis is very important. This is the name of the folder in your user profile. For example, if you opened a CMD window you would see the path to your local profile. This variable is the name of the last folder in that path. If my user folder is eric.greer then this will be eric.greer. Most of the time this folder name is the exact same as the user name it will run under. If this script is running in remotely via PSExec or as the system account, it will require Default User, without quotes, to be entered here.
note
Just a note. This will be placed on your email subject along with on the filename. Good to include the location. Spaces are not supported very well here, and don’t use quotation marks either.

Example Useage: (After setting variables on the top of the script!)

ericbackup.bat normal

ericbackup.bat systemstate

ericbackup.bat differential

This will start a normal backup with the settings you specified within the batch file.

EricBackup.bat

@echo off
:Variables

REM Insert your variables below before running this batch from the command line.

set blatpath=c:\programs\blat.exe
set relayserver=localhost
set email=blog@integrii.net
set fromemail=blog@integrii.net
set emailuser=your.user
set emailpass=your.pass
set source=C:\Scripts
set destination=K:\Backup
set textlogpath=K:\Backup\%computername%-Backup.txt
set archivepath=K:\Backup\OldLogs
set username=administrator
set note=ScriptsBackup

REM Map your drives here if you need to.

REM If you use psexec to run this remotely, the user will be "Default User"
REM Dont touch anything below here.
REM Dont touch anything below here.
REM Dont touch anything below here.
REM Dont touch anything below here.
REM Dont touch anything below here.

:TimeStuffFromMichaelSmith

for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set Month=%%j
set Day=%%k
set Year=%%l
set Date=%%j-%%k-%%l
set dirdate=%%j%%k%%l
)
for /f "Tokens=1-2 delims=/ " %%i in ('time /t') do (
set tm=%%i
set ampm=%%j
)

:Preparation

echo.
echo **************************
echo EricBackup.bat Version 2.8
echo EricGreer@GMail.com
echo http://blog.integrii.net/?p=76
echo **************************
echo.

if "%1" == "systemstate" set backupmode=systemstate & echo "%1 mode selected." & goto goodtogo
if "%1" == "normal" set backupmode=normal & echo "%1 mode selected." & goto goodtogo
if "%1" == "differential" set backupmode=differential & echo "%1 mode selected." & goto goodtogo
if "%1" == "Systemstate" set backupmode=systemstate & echo "%1 mode selected." & goto goodtogo
if "%1" == "Normal" set backupmode=normal & echo "%1 mode selected." & goto goodtogo
if "%1" == "Differential" set backupmode=differential & echo "%1 mode selected." & goto goodtogo
if "%1" == "SystemState" set backupmode=systemstate & echo "%1 mode selected." & goto goodtogo

goto noparams

:goodtogo

set server=%computername%
set logpath=C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data

if not exist "%archivepath%" md "%archivepath%" & echo "Archive Path did not exist, so it was created." >> %textlogpath%
if exist "%textlogpath%" del "%textlogpath%" & echo "Previous %textlogpath% existed, so it was deleted." >> %textlogpath%
if exist "%logpath%\*.log" del "%logpath%\*.log" & echo "Previous ntbackup logfile existed, so it was deleted." >> %textlogpath%

:Backup

echo %server% backup started at %tm% %ampm% on %Year%-%Month%-%Day% into "%destination%" >> %textlogpath%
echo %server% backup starts %tm% %ampm% on %Year%-%Month%-%Day% into "%destination%"

if %backupmode% == systemstate ntbackup.exe backup systemstate "%source%" /n "%server%-Backup" /d "%server%-Backup" /v:no /r:no /rs:no /hc:off /j "%server%-Backup" /l:s /f "%destination%\%server%-Backup-%Year%-%Month%-%Day%-SYSTEMSTATE.bkf" >> %textlogpath%
if %backupmode% == differential ntbackup.exe backup "%source%" /n "%server%-Backup" /d "%server%-Backup" /v:no /r:no /rs:no /hc:off /m differential /j "%server%-Backup" /l:s /f "%destination%\%server%-Backup-%Year%-%Month%-%Day%-DIFFERENTIAL.bkf" >> %textlogpath%
if %backupmode% == normal ntbackup.exe backup "%source%" /n "%server%-Backup" /d "%server%-Backup" /v:no /r:no /rs:no /hc:off /m normal /j "%server%-Backup" /l:s /f "%destination%\%server%-Backup-%Year%-%Month%-%Day%-NORMAL.bkf" >> %textlogpath%

:RenameLogs

if exist "%logpath%\*.log" ren "%logpath%\*.log" %server%-Backup.log
if exist "%logpath%\%server%-Backup.log" copy "%logpath%\%server%-Backup.log" "%archivepath%" /y

echo NTBackup.exe .log file archived at "%archivepath%\%note%-%server%-%Year%-%Month%-%Day%.log" >> %textlogpath%
echo EricBackup.bat .txt file archived at "%archivepath%\%Year%-%Month%-%Day%-%server%-%note%.txt" >> "%textlogpath%"

:Send
%blatpath% "%textlogpath%" -attach "%archivepath%\%server%-Backup.log" -t %email% -s "%server% Backup Log %Year%-%Month%-%Day% at %tm% %ampm%" -i %fromemail% -f "%fromemail%" -q -server "%relayserver%" -u "%emailuser%" -pw "%emailpass%"

:Archive
if exist "%archivepath%\templog.txt" del "%archivepath%\templog.txt"
if exist %textlogpath% copy "%textlogpath%" "%archivepath%\templog.txt"
if exist "%archivepath%\%Year%-%Month%-%Day%-%server%-%note%.txt" del %archivepath%\%Year%-%Month%-%Day%-%server%-%note%.txt
if exist %archivepath%\templog.txt ren %archivepath%\templog.txt "%Year%-%Month%-%Day%-%server%-%note%.txt"

if exist "%archivepath%\%note%-%server%-%Year%-%Month%-%Day%.log" del "%archivepath%\%note%-%server%-%Year%-%Month%-%Day%.log"
if exist "%archivepath%\%server%-Backup.log" ren "%archivepath%\%server%-Backup.log" "%note%-%server%-%Year%-%Month%-%Day%.log"
if exist "%archivepath%\%server%-Backup.log" del "%archivepath%\%server%-Backup.log"
if exist "%logpath%\%server%-Backup.log" del "%logpath%\%server%-Backup.log"

if exist "%textlogpath%" del "%textlogpath%"

goto eof

:noparams
echo This file must be configured by opening it in notepad and setting the variables in the variables section at the top of the script.
echo You do not need to touch anything else beyond the variables with remarks above them!
echo To run the file after you configure it in notepad you must specify a backup type as the first paramiter.
echo.
echo EXAMPLE 1:
echo ericbackup Systemstate
echo.
echo EXAMPLE 2:
echo ericbackup Normal
echo.
echo EXAMPLE 3:
echo ericbackup Differential
echo.
echo **************************
echo.

:eof

Download BLAT

This script has been a lot of work to get just right, and I would appreciate it if any problems are reported to me. This is a big timesaver for me and i use it every other day in different environments with no problems.

Burn CDs from Command Line

Check out this awesome tool by Alex Feinman to burn CDs from a command line. This program makes it really easy to script CD burning for scheduled archive procedures!

Check out how easy the command line is for it:

createcd -r:d c:\burnfiles

Thats it! That would automatically gather all the files from c:\burnfiles and within, then burn them using drive D. Best of all, it’s freeware.

Rehosted here. (createcd.exe).
This utility is free for non-commercial (personal) use.