Jump to content

Vssadmin cmd line in Server 2003 to shadow copy a single file


Recommended Posts

Hello,

New to the forums and just signed up. Not a lot of experience with forums, but here goes (Read: Sorry in Advance!):

I am a Site Admin working at a plant that needs backups of certain folders. The off site backup is less than perfect, and so my boss decided we should make local backups. So,I am writing a script that copies a folder on the server, compresses it, then renames it so that a user can restore their own backups w/o my intervention. Everything has been running smoothly, however there is one "locked/open" file which I cannot copy when the script runs. It is always locked/open 24/7 as the file is for a timecard(payroll) system for our plant which runs continuously.

So, I was going to give up and use NTBackup as I found it could create a shadow copy of the file. However, the rest of the program stinks! So, I tried using 'vssadmin.exe' cmd in my script but nowhere on the internet can I find how to set it up to so it will copy only one file instead of a volume. How can I create a (simple) DOS command for autoit to make a shadow copy for a single file w/o activating it for all shares?

Thanks!

P.S. I am not in charge of the server, and so cannot turn on Volume shadow Service for the entire volume. And I can't keep VSS on for the file itself permanently. This has to be a quick get in/ get out without affecting other files/volume.

Link to comment
Share on other sites

Download Hobocopy, extract zip and try this:

;coded by UEZ 2011
$Hobocopy = @ScriptDir & "\x64\HoboCopy.exe "
If Not FileExists($Hobocopy) Then Exit MsgBox(16, "Error", $Hobocopy & " not found!")
If WMI_CheckService_StartMode("swprv") = "Disabled" Or WMI_CheckService_StartMode("VSS") = "Disabled" Then Exit MsgBox(16, "Error", "Microsoft Software Shadow Copy Provider service and/or" & @LF & "Volume Shadow Copy service is/are  disabled!")
$LockedFilePath = FileOpenDialog("Select a locked file", "", "All (*.*)", 1)
If @error Then Exit MsgBox(48, "Information", "Aborted")
$LockedFile = StringRegExpReplace($LockedFilePath, ".*\\(.*)\z", "$1")
$LockedFilePath = StringRegExpReplace($LockedFilePath, "(.*)\\.*\z", "$1") & "\"
$DestFolder = FileSelectFolder("Select destination folder", "") & "\"
If @error Then Exit MsgBox(48, "Information", "Aborted")
$pid = RunWait(@ComSpec & " /c " & $Hobocopy & " " & $LockedFilePath & " " & $DestFolder & " " & $LockedFile, @ScriptDir, @SW_SHOW)
ShellExecute($DestFolder)
MsgBox(64 + 262144, "Information", "Done")

Func WMI_CheckService_StartMode($name)
    If Not IsString($name) Then Return SetError(1, 0, 0)
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
    If @error Then Return SetError(2, 0, 0)
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name='" & $name & "'", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $obj =  $objItem.StartMode
        Next
        If $obj = "" Then SetError(3, 0, 0)
        Return $obj
    Else
        Return SetError(4, 0, 0)
    EndIf
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hobocopy worked! Thank you UEZ! I had originally dismissed it because I didn't want to leave any programs on the server. (Forgot about FileInstall then deleting it in my script when I was done) All I had to add to my script to get it to work were these lines:

Installs Hobocopy to the temp directory:

$HoboCopy = FileInstall("[source]\Hobocopy.exe", "[Destination]\Hobocopy.exe", 1)

Runs Hobocopy on the file I need:

;Hobocopy needs double quotes in it's syntax when sending source/destination information or it won't work.

Runwait(@ComSpec & ' /c [Where you put installed to]\Hobocopy.exe "[Location of file you want to copy]" "[Where you want to copy file to]" [File]')

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...