[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

windows backup on commit script (my donation)

From: Jeff Cave <jeff.cave_at_sunergon.com>
Date: 2004-06-04 23:13:44 CEST

I have a backup script that runs on post-commit. If anyone wants to use it here you go.

I know there are a couple of flavours of these but this is the one I made.

Details:
  wsf script (windows scripting file)
  does full backups every 10^n (can't think of a better way to describe this)
   - full @ 10, 100, 1000, 10000
  does incremental backups every commit
   - ten incremental backups at most
     eg 275 rev => pack.000-099.bak.gz (full)
                   pack.100-199.bak.gz (incremental)
                   pack.200-275.bak.gz (incremental)

Problem:
Ok, so it doesn't actually work yet. I was hoping someone would look at it and decide they want to use it and be able to tell me what I am doing wrong.

I've had the script in place for a while and can't get it to work. As the usage of the svn increases here, I am getting concerned about DB corruption (due to improper backup techniques).

I am working on a recovery script as well.

Jeff Cave
Sunergon Information Services, Inc.
(403) 247-1723

--------------------------------------------------------------------------------

batch file should contain something like:

cscript backup.wsf %1 %2 c:\svnback\repo

--------------------------------------------------------------------------------
<job id="backup">
 <runtime>
  <description>Creates a backup of the specified repository</description>
  <unnamed name="repopath" type="string" required="true" helpstring="Full local path to the repository to be backed up." />
  <unnamed name="rev" type="integer" required="true" helpstring="Last revision to backup." />
  <unnamed name="backpath" type="string" required="true" helpstring="Full path to the back up directory." />
  <example>Example: backup.wsf c:\svnrepo\repo1 45 c:\svnback\repo1</example>
 </runtime>
 <script language="VBScript" runat="Server">
   class SVNBackup
     private pPath
     public repo
     public sRev
     public eRev
     public comp
     
     public property get path()
       path = pPath
     end property
     
     public property let path(byval newPath)
       dim ch
       
       pPath = trim("" & newPath)
       if(len(pPath) > 0)then
         ch = right(pPath,1)
       end if
       if(ch <> "\")then
         pPath = pPath & "\"
       end if
     end property
     
     public property get fname()
       fname = _
         repo & "." & _
         sRev & "-" & _
         eRev & "." & _
         "bak"
         
       'if(comp)then
       ' fname = fname & ".gz"
       'end if
       
     end property
     
     public property let fname(byval newFname)
       dim arrVals
       dim arrRevs
       
       arrVals = split(newFname,".")
       repo = arrVals(0)
       arrRevs = split(arrVals(1),"-")
       if(ubound(arrvals) = 4)then
         if(arrvals(4) = "gz")then
           comp = true
         end if
       end if
       
       sRev = arrRevs(0)
       eRev = arrRevs(1)
     end property
     
   end class
 </script>
 
 
 <script language="VBScript">
  
  dim pathRepo
  dim pathBack
  dim lastrev
  dim lastbak
  
  '*** main *******************************************************************
  '* Comment this out for emailing.
  '*
  '* I honestly don't know if some mail apps will try to run this
  '****************************************************************************
  'Init
  'CreateBackup
  '*** main *******************************************************************
  
  
  
  '*** Init *******************************************************************
  '*
  '****************************************************************************
  private sub Init()
    dim args
    
    with WScript.Arguments
      pathRepo = "" & .Item(0)
      lastrev = "" & .Item(1)
      pathBack = "" & .Item(2)
    end with
    
    if(pathBack = "")then
      pathBack = pathRepo & "\backup"
    end if
    
    
    'just because this is our layout:
    pathback = replace(pathrepo, "svnrepo", "svnback")
  end sub
  '*** Init *******************************************************************
  
    
  
  '*** CreateBackup ***********************************************************
  '*
  '****************************************************************************
  private function CreateBackup()
    dim backup
    dim srev
    dim digits
    dim targ
    dim fso
    dim txt
    
    dim proc
    dim sh
    dim strEXE
    
    set fso = WSCript.CreateObject("Scripting.FileSystemObject")
    
    
    'make sure target exists
    CreateFolder pathBack
    
    'calculate start revision
    lastrev = cint(lastrev)
    digits = len("" & lastrev)
    digits = replace(space(digits-1), " ", "0")
    srev = "1" & digits
    srev = cint(srev)
    srev = "" & fix(lastrev/srev) & digits
    wscript.echo("srev: " & srev)
    
    'determine filename
    set backup = new SVNBackup
    with backup
      .path = pathBack
      .repo = "reeview"
      .erev = lastrev
      .srev = srev
      .comp = true
      
      'file to save as
      targ = .path & .fname
      
      'determine command line
      strEXE = ""
      if(.srev > 0)then
        strEXE = "-r <srev>:<erev> --incremental"
      end if
      strEXE = "svnadmin dump <repo> " & strEXE
      
      strEXE = replace(strEXE, "<repo>", pathRepo)
      strEXE = replace(strEXE, "<srev>", .srev)
      strEXE = replace(strEXE, "<erev>", .erev)
      strEXE = replace(strEXE, "<targ>", "")
      
      if(fso.FileExists(targ))then
        fso.DeleteFile(targ)
      end if
      set txt = fso.CreateTextFile(targ)
    
    end with
    
       
    'run dump
    WScript.Echo(strEXE)
    set sh = WScript.CreateObject("WScript.Shell")
    set proc = sh.Exec(strEXE)
    
    with proc
      while(proc.status = 0)
        WScript.Sleep(100)
        ' dump the stdout to file
        if(not proc.stdout.atendofstream)then
          txt.Write proc.stdout.readall
        end if
      wend
    end with
    
    txt.close
    
    if(backup.comp = true)then
      strEXE = "gzip -q9 " & targ
      WScript.Echo(strEXE)
      set proc = sh.Exec(strEXE)
      with proc
        while(proc.status = 0)
          wscript.sleep(100)
        wend
      end with
    end if
    
    set proc = nothing
    set txt = nothing
    set fso = nothing
    set sh = nothing
      
    set backup = nothing
  end function
  '*** CreateBackup ***********************************************************
  
  
  
  '*** LastBackup *************************************************************
  '*
  '****************************************************************************
  private function LastBackup()
    dim fso 'as Scripting.FileSystemObject
    dim dir 'as Scripting.Folder
    dim f 'as Scripting.File
    
    dim tmp
    dim last
    
    set LastBackup = nothing
    
    CreateFolder(path)
    
    set fso = new Scripting.FileSystemObject
    set dir = fso.GetFolder(path)
    
    if(dir.count = 0)then
      
    else
      set tmp = new SVNBackup
      set last = new SVNBackup
      
      set f = dir.items()(0)
      last.fname = f.name
      set f = nothing
      
      for each f in dir
        tmp.fname = f.name
        if(tmp.srev > last.srev)then
          last.fname = tmp.fname
        end if
      next
    end if
    
    set LastBackup = last
    
    set last = nothing
    set tmp = nothing
    
    set dir = nothing
    set fso = nothing
  end function
  '*** LastBackup *************************************************************
  
  
  
  '*** CreateFolder *************************************************************
  '*
  '******************************************************************************
  Public Sub CreateFolder(byval path)
    Dim fs 'As Scripting.FileSystemObject
    
    Dim folders 'As String
    Dim i 'As Long
    
    path = "" & path
    folders = Split(path, "\")
    
    Set fs = WScript.CreateObject("Scripting.FileSystemObject")
    
    path = folders(LBound(folders))
    For i = LBound(folders) + 1 To UBound(folders)
      path = path & "\" & folders(i)
      wscript.echo(path)
      If (Not fs.FolderExists(path)) Then
        fs.CreateFolder (path)
      End If
    Next
    
    Set fs = Nothing
  End Sub
  '*** CreateFolder *************************************************************
  
 </script>
</job>
--------------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Jun 4 23:15:00 2004

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.