← Overriding built-in MS Access functions: giving the MsgBox a default title | Jekyll dynamic tree menu: show the whole menu at once →

Executing wunderlist-backup with Portable Jekyll's Ruby version

| tags: backupjekyllruby

Just a few months ago, I posted the last part of my “backup” series. At the bottom I mentioned that I’m evaluating Wunderlist and that I need to take backups of it, should I really use it.

In the meantime I actually did start using it, so here’s how I’m backing it up.

Enter wunderlist-backup

I already mentioned in the linked post that I found a nice backup script: wunderlist-backup.

It’s written in Ruby. I’m on Windows, and I already happen to have a Ruby version on my machine because I’m using Jekyll (which is written in Ruby) to build websites including this one.

On my last computer, I installed my Ruby version using Ruby Installer, but when I bought my current computer, I decided to switch to Portable Jekyll.
The idea was that with a portable (and copyable) solution, it’s easier to keep the two computers in sync so I can work on the same project on both, with the exact same Ruby and Jekyll versions.

Now with wunderlist-backup, I had a new problem: how to get it to work with the Ruby version that comes with Portable Jekyll?

Patching Portable Jekyll

At the time when I was evaluating this, Portable Jekyll’s “default” mode consisted of a batch file named setpath.cmd, which opened a command prompt via cmd /k.

It’s no problem to execute Ruby scripts from that prompt by typing ruby foo.rb, but my problem was that the /k switch causes the command window to stay open.

However, I needed it to execute a script and then terminate, so I could call it from another batch file.
So I submitted a pull request for it. As of now, it has not been merged to the main Portable Jekyll repository yet, though.

With my change, it’s now possible to call setpath.cmd from, say, a batch file and pass a command to it:

"c:\PathToPortableJekyll\setpath.cmd" "jekyll serve"

For example, I can now create a batch file with that content in the main folder of a Jekyll site and run jekyll serve (using Portable Jekyll’s Ruby version) by double-clicking the batch file.

Or a batch file which executes a Ruby script:

"c:\PathToPortableJekyll\" "ruby hello.rb"

With this prerequisite, calling wunderlist-backup in an automated backup script becomes possible.

Automating wunderlist-backup

The actual usage instructions on GitHub are quite simple - create an application in Wunderlist, set two environment variables and call ruby wunderlist-backup.rb > wunderlist-backup.json.

My batch file is a bit longer, because I wanted to put each backup file in a new time-stamped subfolder.

Here it is:

@echo off
echo Executing Wunderlist Backup...

rem actual backup folder with current date/time
set backupfolder=c:\backup\wunderlist\%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%

md "%backupfolder%"

set backupfile=%backupfolder%\%folder%\christian.json

set WUNDERLIST_ACCESS_TOKEN=xxxxxxxxxxxxxxxx

set command=ruby wunderlist-backup.rb
call "c:\PathToPortableJekyll\setpath.cmd" "%command%" > "%backupfile%"

I think the %date:~6,4%-%date:~3,2%... part needs some explanation:

%date% and %time% return the current date/time.
We can then use substrings to extract parts of it.

This depends on your machine’s date and time format though, which depends on the language settings.

The date and time format of my machine is dd.mm.yyyy and hh:mm:ss.
%date:~6,4% skips the first 6 characters and returns the next four, so for today (Sep 15, 2016) it would return 2016.

This way, we can build a folder name like 2016-09-15-21-56-09 as follows:

set folder=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%


As already mentioned at the bottom of the last post of my “backup” series, I’m running a backup script (a batch file) in regular intervals anyway.

The batch file shown in this post is just executed as a part of running the “main” backup batch file:

cd %~dp0\wunderlist-backup\
call wunderlist-backup.bat

← Overriding built-in MS Access functions: giving the MsgBox a default title | Jekyll dynamic tree menu: show the whole menu at once →