Kaseya Community

Weekly Backup Routine with NTBackup

  • NTBackupScript.zip
    This script will create a weekly full backup, and upto 6 incremental backups using a vbs script.

    In order to complete the backup, you must first create the bks selection list file in the server backup share. Name the bks file [machine.groupid].bks.

    Upload the 2 attached vbsscripts in the zip file to your kaseya server. The 2 files are "replace.vbs" and "ntbackupTEMPLATE.vbs"

    Edit the Kaseya script "NTBackup Step 1 TEMPLATE" to use the appropriate unc share or local path, and temp directory.


    (attachment updated: 11/06/2006)

    Legacy Forum Name: Weekly Backup Routine with NTBackup,
    Legacy Posted By Username: myArch-man
  • http://www.kaseya.com/kforum/attachment.php?id=357

    Summary:

    This scriptenables using NTBackup.exein aweekly backup maintenance plan for Windows XP/2000/2003. Once the script and supporting components have been setup, NTBackup will execute and save the backup file to a location of your choice.

    Backup files will be saved in the following format:

    machine.groupid YYYY w[WeekNumber].bkf

    i.e.

    machine.groupid 2006 W44.bkf

    Once a backup completes, the backup log is uploaded to the kaseya server, and email/alerts are generated.

    User Variablesto be defined:

    #share# = UNC or Local path to were completed backups will reside.

    LogFolder# = Location of NTBackup logfiles.

    i.e: CBig SmileOCUME~1AdministratorLOCALS~1APPLIC~1MicrosoftWINDOW~2NTBackupdata

    I'm not sure but I believe this location is dependent on which account created the Backup Selection (bks) file.

    NTBackup step 1 contains other variables, modification is optional of course. Smile

    Prereqs before running script chain:

    1. Open NTBackup and switch to advanced mode

    2. Make your selections, and save the selection list as "machine.groupid.bks"

    3. Copy the bks file to where you will be saving backups to!

    4. Upload NTBackupTEMPLATE.vbs (Thank you to John Howard, Microsoft UK)and Replace.vbs to your Kaseya server.

    5. Modify the #share# and #LogFolder# variables to suit your needs.

    6. Modify the Impersonate User setting with the same account that created the BKS file. ---I'm not sure if this step is even needed, but what the heck. Wink

    Your Ready to go!

    BTW, Updated script components are in the previous post.

    Feedback is welcome! Thanks!



    vbs script text to follow



    NTBackupTEMPLATE.vbs

    ' ************************************************************************************
    ' * Weekly Backup Script for NTBackup
    ' * John Howard, Microsoft UK. Created 25th June 2005
    ' *
    ' * Feel free to use/modify for your own needs.
    ' * No guarantees though although it works for me :-)
    ' * However, if you can do better, contact me through http://blogs.technet.com/jhoward
    ' ************************************************************************************

    Option Explicit
    On error resume next
    Const NO_ERROR = 0
    Const BACKUP_SHARE = "\RemoteServersharename"
    Const BACKUP_SELECTION = "BackupSelections.bks"
    Const BACKUP_PROGRAM = "c:windowssystem32ntbackup.exe "

    Dim szYYWW ' Date in YYYY-WW format (Week of year)
    Dim szYYMMDD ' Date in YYYY-MM-DD format
    Dim szFlagsSelection ' The backup selection script, prepopulated
    Dim szSetDescription ' The description of the backup set
    Dim szDestinationFile ' The destination file in the destination directory
    Dim szFlagsJobName ' Flags for the name of the job [/j "jobname")
    Dim szFlagsVerify ' Flags for verify the backup [yes|no]
    Dim szFlagsRemoteStorage ' Flags for remote storage [/rs:no|yes]
    Dim szFlagsHardwareCompress ' Flags for hardware compression [/hcRed Facedff|on]
    Dim szFlagsLogging ' Flags for logging in ntbackup [/l:f|s|n] Full SUmmary None
    Dim szFlagsAppend ' Flags for appending data [/a] or nothing
    Dim szFlagsRestrict ' Flags for restricting access [/r:yes|no]
    Dim szFlagsType ' Flags for backup type [/m normal|Incremental|Differential...]
    Dim oFSO ' File System Object to see if file already exists
    Dim owShell ' To execute a shell command
    Dim rc ' Return code
    Dim szError ' If we have an error, record it in here
    Dim szCommandLine ' What we are going to run as a backup

    Set oFSO = Nothing
    set owShell = Nothing
    rc = NO_ERROR ' OK So far
    szszCommandLine = "" ' Not sure what we're running yet
    szError = "" ' Not had an error yet

    ' Setup our variables
    if (NO_ERROR = rc) Then
    szYYWW = year(now()) & " w" & formatNumber(DatePart("WW",now()))
    szYYMMDD = year(now()) & "-" & formatNumber(month(now())) & "-" & formatNumber(day(now()))
    szFlagsSelection = chr(34) & "@" & BACKUP_SHARE & "" & BACKUP_SELECTION & chr(34)
    szFlagsJobName = "/j " & chr(34) & "Exchange Backup" & chr(34)
    szFlagsVerify = "/v:yes" ' Verify YES|NO
    szFlagsRemoteStorage = "/rs:no"
    szFlagsHardwareCompress = "/hcRed Facedff" ' Hardware compression off - this is to disk
    szFlagsLogging = "/l:f" ' f=full s=summary n=none
    szFlagsAppend = "/a" ' /a for Append or leave blank to overwrite
    szFlagsRestrict = "/r:no" ' no|yes Restrict access to administrators
    szFlagsTapeName = "/t:NTBackup " & szYYWW
    szDestinationFile = "DestFileName " & szYYWW & ".bkf"
    szSetDescription = "/d " & chr(34) & "Created " & szYYMMDD & chr(34)
    end if

    ' Instantiate File System Object
    if (NO_ERROR = rc) Then
    err.clear
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    if (err.number) or (oFSO is nothing) Then
    rc = -1
    szError = "Failed Creating FSO: " & err.description & " -0x" & hex(err.number)
    end if
    end if

    ' Look to see if the file exists to determine the backup type
    if (NO_ERROR = rc) Then
    if not oFSO.FileExists(BACKUP_SHARE & "" & szDestinationFile) then
    ' Normal | Copy | Differential | Incremental Backup Type
    szFlagsType = "/m normal "
    szFlagsAppend = "" ' Don't Append if does not exist
    else
    ' File exists, so incremental backup. We are already in Append mode
    szFlagsType = "/m incremental "
    szSetDescription = "/d " & chr(34) & "Inc " & szYYMMDD & chr(34)
    end if

    ' Release File SYstem Object
    set oFSO = Nothing
    end if


    ' Create a Shell Object to be able to run the backup executable
    if (NO_ERROR = rc) Then
    err.clear
    Set owShell = wscript.createobject("wscript.shell")
    if (err.number) or (owShell is nothing) Then
    rc = -2
    szError = "Failed Creating wscript.shell: " & err.description & " -0x" & hex(err.number)
    end if
    end if

    ' Build the backup command and run it
    if (NO_ERROR = rc) Then
    szCommandLine = BACKUP_PROGRAM & _
    "backup" & " " & _
    szFlagsSelection & " " & _
    szSetDescription & " " & _
    "/f " & chr(34) & BACKUP_SHARE & "" & szDestinationFile & chr(34) & " " & _
    szFlagsAppend & " " & _
    szFlagsLogging & " " & _
    szFlagsVerify & " " & _
    szFlagsRestrict & " " & _
    szFlagsRemoteStorage & " " & _
    szFlagsHardwareCompress & " " & _
    szFlagsType & " " & _
    szFlagsJobName & " "

    rc=owshell.run(szCommandLine,,True)
    end if

    set owShell = Nothing
    wscript.quit(rc)


    Function FormatNumber(szIn)
    FormatNumber = szIn
    if len(szIn) = 1 then FormatNumber = "0" & szIn
    End Function


    Replace.vbs

    Const ForReading = 1
    Const ForWriting = 2

    strFileName = Wscript.Arguments(0)
    strOldText = Wscript.Arguments(1)
    strNewText = Wscript.Arguments(2)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

    strText = objFile.ReadAll
    objFile.Close
    strNewText = Replace(strText, strOldText, strNewText)

    Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
    objFile.WriteLine strNewText
    objFile.Close











    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: myArch-man
  • I wrote another (better)NTBackup script posted here:

    http://www.kaseya.com/kforum/view_topic.php?id=1557&forum_id=15

    It uses the built in scripting functions to "build" the ntbackup command line instead of a vbs script.

    The below scriptuses vbs for what should be done in native kaseya scripting. (whatever that is.. :-D)

    The "replace.vbs" script may be handy if you need to replace known text in files with variables.




    Legacy Forum Name: Script Discussion,
    Legacy Posted By Username: myArch-man