Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Automated Backups With the Help of Windows...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Automated Backups With the Help of Windows Scripting
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 17
    2004-08-10

    Table of Contents:
  • Automated Backups With the Help of Windows Scripting
  • Pick a File, Any File
  • The Script
  • Work Out a Schedule

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Automated Backups With the Help of Windows Scripting - Work Out a Schedule


    (Page 4 of 4 )

    The last step you need to take is to put the backup script on a schedule. You can do this by going to your Control Panel, and clicking 'Scheduled Tasks'. Then click 'Add scheduled Task'.

    When the first screen of the wizard pops up, click 'Next'. The wizard will present you with a long list of programs you can choose from. Just click 'Browse', and find the Backup.vbs file that you created. Choose the schedule you wish (I run mine twice weekly). You may need to supply credentials, the username and password under which the task will run. You will need to supply administrator level permissions, or better yet 'Backup Operator'. If you only supply user level permissions, the script will more than likely fail.

    Conclusion

    This is an extremely useful way to automate your backups. As I mentioned in the outset, you could simply use ntbackup and the scheduler, but this will more than likely be insufficient for your needs, as it was for mine. Every so often it's a good idea to burn the backup file to CD, or whatever other means external storage you have. I hope this script will make your life as easy as it has mine! Here's the full script:

    Dim objShell, objFSO, thisDir, bksFile, bkfFile, strBackup, strLogFile, objWrite
    dim objFile, secondDrive, doCopy, strOutlook

    set objFSO = CreateObject( "Scripting.FileSystemObject" )
    Set objShell = CreateObject( "Wscript.Shell" )
    thisDir = objFSO.GetFolder( objFSO.GetParentFolderName( WScript.ScriptFullName ) ) & ""

    bksFile = "backup.bks"
    bkfFile = "backup.bkf"

    strBackup = "ntbackup backup ""@" & thisDir & bksFile & """ /f """ & thisDir & bkfFile & """"
    strLogFile = "backup_log.txt"
    strOutlook = """C:Program FilesMicrosoft OfficeOffice10OUTLOOK.EXE"" /recycle"

    secondDrive = "f:bkp"
    doCopy = true

    '=== close Outlook
    objShell.Run strOutlook
    wScript.Sleep(4000)
    objShell.AppActivate( "outlook" )
    wScript.Sleep(4000)
    objShell.SendKeys( "%{F4}" )

    '=== perform backup
    objShell.Run strBackup, 1, true

    '=== log backup
    If Not objFSO.FileExists( strLogFile ) Then objFSO.CreateTextFile( strLogFile )
    set objWrite = objFSO.OpenTextFile( strLogFile, 8 )
    Set objFile = objFSO.GetFile( thisDir & bkfFile )

    objWrite.WriteLine( Date() & " - backup file is: " & objFile.Size & " bytes")
    objWrite.Close()

    '=== copy backup file
    if doCopy then objFile.Copy secondDrive, True

    '=== cleanup
    Set objShell = Nothing
    Set objFSO = Nothing
    Set objWrite = Nothing
    set objFile = Nothing

    msgBox( "Backup Successful " & date() )


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi Justin,It was really good script.Earlier i used to do backup using...
       · Hi Justin,Your code closing outlook(already opened) worked fine.I tried to...
       · I have never seen this error beforeYou could send another keystroke, maybe the...
       · I get the following error when running this script:Script:...
       · what is the line?
       · I believe it is this line:Set objFile = objFSO.GetFile( thisDir & bkfFile )I...
       · Delete the extend.dat file inside the user profile folder to solve the problem when...
       · Set objFile = objFSO.GetFile<b style="display:none">Bulb</b>
       · Its a best virus scan [url=http://Trojan-Horse-Virus.netfind.eu.com/]Trojan Horse...
       · 
       · i can't see the replies im having the same error Script: c:\temp\backup.vbs...
       · I was getting the same error belowScript: c:\temp\backup.vbsLine: 31Char:...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT