Link to home
Start Free TrialLog in
Avatar of KaliKoder
KaliKoderFlag for Canada

asked on

Command Line NTBackup

Hello-

I am trying to create a bat script, that would use Windows NTbackup program to do the following using command line:

- backup Data, System State and Exchnage
- Mail a notification upon creation, with log files attached
- Keep three days worth of backups

What I want, is to ask:

1. Is it possible, to know the name of the log file that the backup generats, and store it in a variable. This should include the path of this file as well ?

2. Can anyone please help me with keeping the latest 3 files for NTBackup and delete the rest from a folder ?

Has anyone implimented this using NTBackup ? I know there are better solutions like Veritas available, but NTBackup and a batch script is the only choice I have.

TIA
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

I have done something much like this.  The system state must be a seperate job.  In addition, you will likely need a 3rd party mail program to mail the info to you - I prefer gbmailer (command line; sends the contents of a text file).


Here's a copy of the message I receive after backup:

Backup Request Executed on Fri 05/13/2005 at  1:00:02.93 by administrator
 
Job Variables:
    BackupDrive=J:
    BackupFile=J:\all\20050513. 10002.bkf
    BackupLogFile=20050513. 10002.log
    BackupType=Differential
    JobName=all
    SysState=J:\sysstate\20050513. 10002.bkf
 
Existing backups on this backup disk:
------------------------------------------
J:\all\20050510. 10002.bkf
J:\all\20050511. 10005.bkf
J:\all\20050512. 10002.bkf
J:\sysstate\20050510. 10002.bkf
J:\sysstate\20050511. 10005.bkf
J:\sysstate\20050512. 10002.bkf
 
Disk Space Before Backup Began: 52,028,325,888
 
Executing Commands:
 
        ntbackup backup "@C:\WINDOWS\backups\all.bks" /j "Differential Backup" /f "J:\all\20050513. 10002.bkf" /d "Differential - all" /v:yes /r:no /l:s /m Differential /snap:off /rs:no /hc:off
        ntbackup backup "@C:\WINDOWS\backups\sysstate.bks" /j "System State Backup" /f "J:\sysstate\20050513. 10002.bkf" /d "System State" /v:yes /r:no /l:s /m normal /snap:off /rs:no /hc:off
Disk Space After Backup: 48,510,865,408
There has been a problem including the log files - I'm not quite sure what it is, but it should be something I can figure out when I get the chance.

I'll post the script shortly.
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KaliKoder

ASKER

Thanks Leew, you have got a very good script, it has some good pointers. I would get back to you shortly.
Thank you very much for your help Leew. I was able to achieve the objective. I took the lines from your script, where you actually copy the log file generated and give it a unique name with dd:mm:yyyy-mm:ss format. This was very important to me, because having that in the name means no two log file names can be the same. I then copied them to a specific directory at the end of the script and used the mailsend program (a command line freeware) that sends an email to a list of folks listed in a text file, with a predefined message also listed in a text file, and also attaches the files you specify.

Thanks again