As I’ve started storing all of my project work and GTD notes in my Wiki program, I thought it might be a good idea to take regular backups of the text files it uses for data. And being a geek, I thought I’d automate it.
@ECHO OFF REM this makes the batch file less noisy - dont REM output commands to screen
REM limit scope for environment variables created here REM to within this batch file only SETLOCAL
REM make a note of where the current directory is REM so we can go back there afterwards REM (useful when running this batch file manually) set DIR_TO_RESTORE=%CD%
REM run the 'date /t' command REM this outputs in the format: REM 19/11/2006 REM (probably different for people with non-UK regional REM settings)
REM Using for to look at bits of date individually... REM FOR /F ["options"] %variable IN ('command1') DO command REM options - REM tokens - identify which bits of the date output I want REM (3 tokens - day month year), REM delimiters - how they are separated ('/') REM (users with non-UK regional settings might REM need to change this - e.g. for '-') REM command - REM 1) date /t - show date without prompting to change it REM 2) set - set environment variables to store each token FOR /f "tokens=1-3 delims=/ " %%G IN ('date /t') DO ( REM set environment variables to store individual date values REM (assumes date/month/year - users with non-UK regional REM settings might want to switch date and month) set dd=%%G set mm=%%H set yy=%%I)
REM this gives us a numeric date - in the format yyyyMMdd REM which is useful in filenames for sorting set TODAY=%yy%%mm%%dd%
REM go to first directory containing something to backup REM tar it up, and move it to a backups directory cd "C:\\Documents And Settings\\Administrator\\My Documents\\bLADE My Documents\\" "C:\\cygwin\\bin\\tar.exe" -cvf %TODAY%_gtd.tar WM_Wiki_Pages move %TODAY%_gtd.tar "..\\My Personal\\WMWiki Backups\\."
REM repeat as required cd "C:\\Documents and Settings\\Administrator\\My Documents\\My Personal\\" "C:\\cygwin\\bin\\tar.exe" -cvf %TODAY%_ref.tar "My WM Wikis" move %TODAY%_ref.tar "..\\My Personal\\WMWiki Backups\\."
REM finished! go back to where we started cd %DIR_TO_RESTORE%
REM end scope for environment variables ENDLOCAL
Okay, so I’ve cheated… I’m using ‘tar’ from cygwin to package up and compress the backed-up files. But I couldn’t find a command-line way to access Windows zip, and I prefer tar files anyway.
Apart from that minor revealing of my UNIX roots, I think it’s quite a nice Windows solution for a free automated backup. I’ve saved this file to C:\bin\backupwikis.bat and have set up Windows Scheduled Tasks (go to Control Panel -> Scheduled Tasks) to run it at 11am every day.