Tuesday, December 19, 2006

Backup script

I have been using the TiddlyWiki for a while now for keeping track of my notes, todo tasks, and other items. I am slowly migrating most items from here to MonkeyGTD to more closely use the GTD system. However, there is a built-in backup option that will save a copy of the file for every change. It's typical of wiki's to be able to have a per change rollback process and that's awesome, but my needs are different. I want a once a day option. I'm ok if I lose all of my changes for a day, as long as I can get back to where I was at the end of yesterday I'll feel comfortable. However, there is no option for that.

Instead what I did was turn off the backup option in tiddly wiki. It's my biggest annoyance saving the entire html file everytime I make a 1 character change. My file is currently 205 KB, but 160 KB are the javascript that is embedded to make the wiki work, so a majority of each of my backup files were the javascript. I wanted either only the data that I had, or a once a day copy. The javascript is way over my head, and at over 50,000 lines of it, I didn't have the time to learn it all and tweak the backup process. Instead what I did was build my own archive process.

I keep my wiki on a USB drive and when I plug it into my computer it is always drive E. So I built myself a startup.cmd file with the commands.

start backupwiki.vbs
cd \Program Files\Mozilla Firefox
start firefox.exe "e:\my wiki\MyTiddlyWiki.html"

And I build the backupwiki.vbs that creates my backup copy daily of my file, only if I need it.

Dim filename
filename = "MyTiddlyWiki.html"

Dim dtPart
Dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(filename) Then
Set mainfile = filesys.GetFile(filename)
modifiedDate = mainfile.DateLastModified
dtPart = FormatDate(mainfile.DateLastModified)

If modifiedDate < Date() Then
If Not filesys.FileExists("MyTiddlyWiki." & dtPart & ".html") Then
filesys.CopyFile filename, "MyTiddlyWiki." & dtPart & ".html"
End If
End If

End If

Function FormatDate(dateToFormat)
FormatDate = Year(dateToFormat) & Pd(Month(dateToFormat),2) & Pd(Day(dateToFormat),2)
End Function

Function pd(n, totalDigits)
if totalDigits > len(n) then
pd = String(totalDigits-len(n),"0") & n
pd = n
end if
End Function

Now when I am ready, I open my folder and just double click the startup.cmd file and it will open in Firefox for me and create the backup when needed. In about 30 minutes I wrote the scripts that will save me from some annoyances, but more importantly hold me to my daily backup. If I don't use it for a few days, the backup will still be before I make any new changes and won't hurt anything. It's great!

Do you have any repetitive tasks you do that could be automated somehow?

No comments: