Quick and Dirty PC Backups
It’s that time again, when I like to burn a backup CD/DVD of all my important files and put it away somewhere safe.
Side note: Since I have three PCs and a server in the house, I don’t use a structured backup process. All my data files are on my server in Subversion and I pull regular updates down to each PC. This, in effect, creates four mirrored copies of my data.
My yearly backup to CD/DVD let’s me prune old data files from my collection and let’s me know that I’m protected from anything short of a total-loss house fire.
In previous years, I’ve used data CDs as my backup media. I would burn a block of files to a CD, label it, and move to the next folder(s). Each CD would be anywhere from 50-99% full. I’ve avoided backup software because I never know what machine I’ll use later to read the data and a proprietary formatted disk that I can’t read in five years would be very bad.
This year I’ve decided to try compressing each file and maybe save a few CD/DVDs. To that end, I’ve written a quick and dirty VBS script that should run on any modern Windows PC. The script is very basic and works something like this:
- Prompt for a source folder.
- Prompt for a destination folder.
- Make a compressed copy of each file in the source folder and place it in the destination folder, recursing each sub-folder.
The major drawback is that separately compressed files are usually larger than a single .ZIP file with multiple similar files. The major benefit is that the compressed files has the exact same name as the original, with .ZIP (or .7Z) appended, which makes finding a file on the backup disk dead simple.
Here’s the full program listing.
Dim objFSO, objFolder, colFiles, objSubFolder, objSubFile
Dim result, strFolder, strTar
result = InputBox("Enter the root directory to back up", _
"Source Directory", "C:\Temp", 100, 100)
strFolder = result
If result <> "" Then
result = MsgBox("Please confirm that you'd like to back up " + _
strFolder, 4, "Confirm Directory")
If result <> 6 Then
MsgBox("Aborted")
strFolder = ""
End If
End If
result = InputBox("Enter the destination directory for the back up", _
"Destination Directory", "C:\BackUp\" + Replace(CStr(Date), "/", "-") + _
"\", 100, 100)
strTar = result
If result <> "" Then
result = MsgBox("Please confirm that you'd like to back up to " + _
strTar, 4, "Confirm Output Directory")
If result <> 6 Then
MsgBox("Aborted")
strTar = ""
End If
End If
If strFolder <> "" And strTar <> "" Then
RunBackup strFolder, strTar
End If
Sub RunBackup(strFolder, strTar)
Dim objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
If Not objFSO.FolderExists(strTar) Then
objFSO.CreateFolder(strTar)
End If
For Each File in colFiles
set objFile = objFSO.GetFile(strFolder & _
"\" & File.Name)
HandleFile objFile, strTar
Next
ScanSubFolders objFolder, strTar
End Sub
Sub HandleFile(objFile, strTar)
Dim fullName, strCommand
fullName = objFile.ParentFolder + "\" + objFile.Name
target = strTar + "\" + objFile.Name + ".7z"
strCommand = "7z a -t7z -mx9 """ + target _
+ """ """ + fullName + """"
set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run(strCommand, , True)
End Sub
Sub ScanSubFolders(objFolder, strTar)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
Set colFiles = objSubFolder.Files
For Each objFile in Colfiles
HandleFile objFile, strTar + objSubFolder.Name + "\"
Next
ScanSubFolders objSubFolder, strTar
Next
End Sub