+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Help with Backup Script in Coding and Web Development; Trying to do an automatic backup when USB drive is plugged in, I'm using autorun to call the script but ...
  1. #1

    Join Date
    May 2008
    Posts
    14
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Help with Backup Script

    Trying to do an automatic backup when USB drive is plugged in, I'm using autorun to call the script but it doesn't seem to working.


    Option Explicit
    Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objShell: Set objShell = CreateObject("Wscript.Shell")
    Dim colDrives: Set colDrives = objFSO.Drives
    Dim drive
    Dim drvbackup
    Dim errReturn
    For each drive in colDrives
    If objFSO.FileExists(drive & "\Autobackup.cmd") Then
    If Instr(1,drive,":\",1)>0 Then
    drvBackup = drive
    Exit For
    ElseIf Instr(1,drive,":",1)>0 Then
    drvBackup = drive & "\"
    Exit For
    Else
    drvBackup = drive & ":\"
    Exit For
    End If
    End If
    Next
    If drvBackup = "" Then
    msgbox "Cannot locate Autobackup.cmd on any of the drives attached to this computer"
    wscript.quit 3
    Else
    errReturn = objShell.Run("robocopy.exe C:\ " & drvBackup & "BackupFolder /E /V /NP /ZB /R:3 /W:1",1,1)
    If errReturn <> 0 Then
    msgbox "Backup completed with the following error: " & errReturn
    Else
    msgbox "Backup completed successfully!"
    End If
    End If
    wscript.quit 0

  2. #2
    penfold_99's Avatar
    Join Date
    Feb 2008
    Location
    East Sussex
    Posts
    1,003
    Thank Post
    60
    Thanked 167 Times in 119 Posts
    Rep Power
    69
    hi,

    I'm trying to follow what your trying to do, but i think your going about it a bit backwards.

    You can find out was the driver letter the script is being run from using this.

    drive = objFSO.GetDriveName(Wscript.ScriptFullName)

    The instead of shelling out to robo copy, you can use

    objFSO.CopyFolder locationA locationB

    is the script running or erroring out?

  3. #3

    Join Date
    May 2008
    Posts
    14
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I'm trying to run an automatic backup, I have a external USB drive that has an autorun file that calls this script. I'm trying to copy the entire C:\ to the USB drive to a folder named, Backup Folder

    It errors out, Line 29 Char. 5




    Quote Originally Posted by penfold_99 View Post
    hi,

    I'm trying to follow what your trying to do, but i think your going about it a bit backwards.

    You can find out was the driver letter the script is being run from using this.

    drive = objFSO.GetDriveName(Wscript.ScriptFullName)

    The instead of shelling out to robo copy, you can use

    objFSO.CopyFolder locationA locationB

    is the script running or erroring out?
    Last edited by soze; 12th June 2008 at 08:47 PM.

  4. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,159
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    125
    There's a lot of checking which I don't understand and just makes the logic harder to follow but I think you may have too many endifs :-)

    this works to find the drive letter:

    Code:
    For each drive in colDrives
      If objFSO.FileExists(drive.driveLetter & ":\Autobackup.cmd") Then
        drvBackup=drive.driveLetter
        exit for
      end if
    Next
    and the rest of the code seems fine

  5. #5

    Join Date
    May 2008
    Posts
    14
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks, I'm going to test it out. This was for a automatic backup of a external USB drive. I needed it to start backing up as soon as the drive is plugged in. I needed it to find the next available drive letter. I had made a small robocopy file but you have to assign a drive letter to the destination folder, only thing every user has different drive mappings so I needed the script to assign the drive letter and start the copy using the robocopy cmd.

    Thx again,



    Quote Originally Posted by srochford View Post
    There's a lot of checking which I don't understand and just makes the logic harder to follow but I think you may have too many endifs :-)

    this works to find the drive letter:

    Code:
    For each drive in colDrives
      If objFSO.FileExists(drive.driveLetter & ":\Autobackup.cmd") Then
        drvBackup=drive.driveLetter
        exit for
      end if
    Next
    and the rest of the code seems fine

  6. #6


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,796
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Using a program like USB Detect and Launch might make it a bit easier since your script would just need to do the backup then.



SHARE:
+ Post New Thread

Similar Threads

  1. SIMs backup script after SQL 2005 migration failing...
    By mullet_man in forum MIS Systems
    Replies: 13
    Last Post: 23rd November 2007, 07:03 PM
  2. *nix Script needed for backup job
    By ICTNUT in forum *nix
    Replies: 2
    Last Post: 14th November 2007, 10:59 AM
  3. Backup PenDrive Script
    By SimpleSi in forum Scripts
    Replies: 9
    Last Post: 18th January 2007, 03:45 PM
  4. Backup Perl Script
    By ranj in forum Scripts
    Replies: 1
    Last Post: 30th April 2006, 09:02 PM
  5. Backup Script for NT backup and Robocopy
    By ChrisH in forum Scripts
    Replies: 12
    Last Post: 20th October 2005, 02:01 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •