Automatic NT-Backup (System State Backup) with retention period and e-mail notification after complete.


A simple script for automatic System State backup where you can easily set backup retention period and it also send you an e-mail notification after completion. With this script you can also archive backup log and if you wish u can also set backup log retention period. It can also set backup files with date stamp.
For e.g., SysBackup_ComputerName_24-03-2009.bkf

You need two small utility,
  • Blat.exe for sending mail, you can get details from here.
  • Forfiles.exe for checking old files, you can get details from here.
Just download following zip file and extract its content to %windir%\ or%windir%\system32 folder.
Download:

Mail Notification





Following are the basic Backup Settings

::Backup Settings START
::Set Backup Path
::~~~~~~~~~~~~~~~~~~~~
set savepath=D:\TestBackup
::Set Backup Name
::~~~~~~~~~~~~~~~~~~~~
set backupname=SysBackup
::Set Backup Retention Period(in days)
::~~~~~~~~~~~~~~~~~~~~
set retention=3
::Set Log Archive Path(Only Folder Name)
::~~~~~~~~~~~~~~~~~~~~
set logarchivepath=BackupLog
::If ‘yes’ then backup log retention will enabled
::~~~~~~~~~~~~~~~~~~~~
set logretention=yes
::If avove settings is “yes” then set log Retention Period(in days)
::~~~~~~~~~~~~~~~~~~~~
set logretentionperiod=3
::———-x———
::E-Mail Settings (SMTP without authentication will work)
::———-x———
::If ‘yes’ a mail will be fired after backup
::~~~~~~~~~~~~~~~~~~~~
set _mailnotification=yes
::If ‘yes’ backup log will attached with mail
::~~~~~~~~~~~~~~~~~~~~
set attachment=no
::Type your e-mail address(for multiple e-mail ID, use ‘,’)
::~~~~~~~~~~~~~~~~~~~~
set email=urname@domain.com
:: Type from mail ID
::~~~~~~~~~~~~~~~~~~~~
set from=%computername%@TC-Auto-NTBackUP
::Set SMTP Server IP Address
::~~~~~~~~~~~~~~~~~~~~
set mserver=10.0.0.1
::Backup Settings END
Batchfile NTBackup.bat
?Download NTBackup.bat
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
@echo offcolor 0cMODE CON: COLS=50 LINES=11echo ***************************************echo Auto SystemState Backup with Retentionecho Log Archive and Mail Notificationecho Code By : Saugata Dattaecho ~~~echo (c) http://technochat.inecho Date: %DATE%, Time: %TIME%echo ***************************************::Backup Settings START::Set Backup Path::~~~~~~~~~~~~~~~~~~~~set savepath=D:\TestBackup::Set Backup Name::~~~~~~~~~~~~~~~~~~~~set backupname=SysBackup::Set Backup Retention Period(in days)::~~~~~~~~~~~~~~~~~~~~set retention=3::Set Log Archive Path(Only Folder Name)::~~~~~~~~~~~~~~~~~~~~set logarchivepath=BackupLog::If 'yes' then backup log retention will enabled::~~~~~~~~~~~~~~~~~~~~set logretention=yes::If avove settings is "yes" then set log Retention Period(in days)::~~~~~~~~~~~~~~~~~~~~set logretentionperiod=3::----------x---------::E-Mail Settings (SMTP without authentication will work)::----------x---------::If 'yes' a mail will be fired after backup::~~~~~~~~~~~~~~~~~~~~set _mailnotification=yes::If 'yes' backup log will attached with mail::~~~~~~~~~~~~~~~~~~~~set attachment=no::Type your e-mail address(for multiple e-mail ID, use ',')::~~~~~~~~~~~~~~~~~~~~set email=vdco.kolkata@familycreditindia.com:: Type from mail ID::~~~~~~~~~~~~~~~~~~~~set from=%computername%@FC-Auto-NTBackUP::Set SMTP Server IP Address::~~~~~~~~~~~~~~~~~~~~set mserver=172.16.10.7::Backup Settings END::--------------------------------::Don't change following lines.::--------------------------------forfiles -p "%savepath%" /m *.bkf /s /d -%retention% /c "cmd /C del @FILE":: get the date and time and then into single variablefor /F "tokens=1-4 delims=/ " %%i in ('date /t') do (set MM=%%jset DD=%%kset YYYY=%%lset date=%%k-%%j-%%lset dirdate=%%j%%k%%l)for /f "Tokens=1-2 delims=/ " %%i in ('time /t') do (set tm=%%iset ampm=%%j)::Deleting Old Backup Log filesif not exist "%HOMEPATH%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\*.log" goto _nodeldel "%HOMEPATH%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\*.log" >nul:_nodelntbackup.exe backup systemstate /v:no /r:no /rs:no /hc:off /J %backupname% /l:s /f "%savepath%\%backupname%_%computername%_%date%.bkf"if not exist "%savepath%\%logarchivepath%" md "%savepath%\%logarchivepath%" >nulmove "%HOMEPATH%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\*.log" %savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt >nulif not "%_mailnotification%" == "yes" goto _endif not "%attachment%" == "yes" goto _noattachblat "%savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt" -attach "%savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt" -to %email% -s "NT Backup Success/Failure Report of %computername%" -f "%from%" -server "%mserver%" > nulgoto _skip:_noattachblat "%savepath%\%logarchivepath%\%backupname%_%computername%_%date%.txt" -to %email% -s "NT Backup Success/Failure Report of %computername%" -f "%from%" -server "%mserver%" > nul:_skipif not "%logretention%" == "yes" goto _endforfiles -p "%savepath%\%logarchivepath%" /m *.txt /s /d -%logretentionperiod% /c "cmd /C del @FILE":_endexit
Now you have to create a schedule for daily backup.



Comments