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.

  System32.zip (75.5 KiB, 1,479 hits)


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 protected]
:: 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

 

Now you have to create a schedule for daily backup.


Disclaimer: All posts and opinions on this site are provided AS IS with no warranties. These are our own personal opinions and do not represent our employer’s view in any way.

This article currently have 13,617 views

Saugata
Follow me

CC BY-ND 4.0 This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.

9 comments

  1. Place batch file in your %systemroot% then set schedule it for backup, unless log archive and mail sent not working..

    I don’t know why, but i am also trying to find out the reason..

  2. Did you placed Blat.exe and Forfiles.exe to your System32 folder?

    And also tell me which mail server you have??

    And to test your server use following command with

    blat “%windir%system32eula.txt” -to type-your-mail-id-here -s “TestMail” -f “type-your-mail-id-here” -server “type-your-smtp-server-ip”

    After executing above command u will get a test mail.

    **Also i have fixed that problem to placing bat file under %systemroot%, now u can placed this batch file anywhere..

  3. Hi,

    First of all Many Thanks!! for the awesome batch file you really saved my life..

    I did test the batch file and it works perfectly.. But i just wanted to know wether would it be possible to copy the .bkf file to a share folder.

    I would like to have few more lines in the said batch script.

    net use f: /delete
    net use F: \flsrvSYS$ /USER:flsrvSYS SYS@1234

    Now I want a command to copy the System_State_Backup_Test_16-05-2011.bkf to f:

    Also while i test the connection by sending a test mail i get the following error.

    The SMTP server does not like the sender name.
    Have you set your mail address correctly?

    It would be very helpful if you could help me setting up the above conditions in the batch script.

    Awating for your positive reply.

    Ankit S

  4. Hi Ankit,
    Try this..
    http://pastebin.com/NBh91aEE
    Note: You have to set your network path info on the batch file..
    set mapdrivename=H:
    set mapdrivepath=\servershare
    set mapdriveuser=user
    set mapdrivepass=password

    Do you have internal smpt server in your network? if yes, check if it required authentication before sending mail?
    If no, then try following command from command prompt to send a test mail to your mailbox.
    blat “%windir%system32eula.txt” -to type-your-mail-id-here -s “TestMail” -f “type-your-mail-id-here” -server “type-your-smtp-server-ip”

  5. Hi Saugata,

    Many Thanks for your reply!!.

    While setting the scheduled task i use
    NT AUTHORITYSYSTEM user account.

    Now when i schedule the batch file using said account, I do not get any log files in the Backup Log Folder. I did check that “System” user account has full access on my profile folder.

    Can you please help pinning down what might the reason for not getting the Backup Report when .bat is run through schedule task??

    PS: I do get the Backup Report when i run the .bat file by double-clicking the same.

    Regard
    Ankit S

  6. Hi Saugata,

    I was just wondering, If have the same batch srcipt for Backing System State Data of Win 2008 R2 Server.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.