Wednesday, January 12, 2005

Swiki Backup

Wrote a little VB script this morning to back up my Wiki server. I typically use a Comanche Swiki which is written in Squeak.



There is a newer swiki implementation for Squeak called SmallWiki - but Comanche is prepackaged and I havent found the time to look deeper into SmallWiki.


Since the windows version of the Squeak VM is able to run as an NT service my script has to shut down the swiki service first, then make a zip of the swiki files and then start the service again. I use the freeware zip.exe from Info-Zip.
Here is the final script:


'****************************************
'* Backup the Swiki Server
'****************************************

Const pathToSwiki = "ComSwiki\swiki"
Const zipProgram = "C:\tools\zip.exe"
Const serviceName = "Swiki"
Const backupFolder = "C:\backups\"

Set shell = CreateObject("WScript.Shell")
Set fileSystem = CreateObject("Scripting.FileSystemObject")

stopServiceCommand = "net stop " & serviceName
startServiceCommand = "net start " & serviceName

currentTime = Time
zipDate = Date()
zipTime = DatePart("h",currentTime) & DatePart("n",currentTime) & DatePart("s",currentTime)
zipFilename = "swikiBackup" & zipDate & "." & zipTime & ".zip"
backupCommand = zipProgram & " -r -9 " & zipFilename & " " & pathToSwiki

'Stop the service, zip and start the service
shell.Run stopServiceCommand,0,true
shell.Run backupCommand,0,true
shell.Run startServiceCommand,0,true

'Move the backup to a common backup folder
If fileSystem.FileExists(zipFilename) Then
fileSystem.CopyFile zipFilename, backupFolder
fileSystem.DeleteFile zipFilename
End If


Using the Task Scheduler I'm able to run the script automatically. I like automating common tasks...

No comments: