How to automate GMVault in OSX with Cron

Having just made the switch to OSX, I was clueless about how to triggerĀ GMVault to make a quick daily backup of my GMail account. Fast forward a few google searches and I’ve got it working, but 100% the way I want it to work. In Windows, it would’ve been easy. Open Task Scheduler, find the executable you want to call, set the frequency of the task, and you’re done. Windows also provides logging for each task that you schedule, which is great.

In OSX, you apparently have a few different ways of doing it, none which I found easy or intuitive.

Automator was not helpful. GMVault is not a .app per se, so using the “Launch Application” option of a workflow wouldn’t let me select the GMVault binary. I gave up on that. I read that Launchd replaced Cron. But, Launchd appears to be XML based. I hate manually editing XML files, so Launchd is out of the question. Then there’s cron. Syntax seems fairly simple. I had trouble with Vim being the default editor for crontab. I hate Vim. So after a lot of googling, here are the steps I used.

1. crontab -l > mycron (to create a text filed called “mycron” which contains existing cron jobs)
2. echo “30 22 * * * path/to/gmvault sync -t quick > ~/gmvault.log 2> ~/gmvault-error.log” >> mycron (this added this new cron job to the mycron file, which contained pre-existing tasks, if any).
3. crontab -r (to delete all existing crontab jobs, since they will be added when adding the mycron file)
4. crontab mycron (load the previously existing cron jobs, plus the new GMVault one).
5. rm mycron

That’s it. The things I didn’t like about cron is that it doesn’t provide any job-specific logging by default. Not even when there were errors when executing the job. The other thing was that even though one logfile is for success and the other one for error (at least that’s what I got from the articles I read), running the crob job creates both files, regardless of if the job was run successfully or not. Other than that, the syntax is fairly simple. Another thing I did not like is that I have no easy way of knowing if a job executed a given day. I tried modifying the bash command to make the log filename be date-based, but haven’t been able to get it there. I’ve tried a couple of variations of the $date function but haven’t been able to get it working yet.

These are all the pages I used in reference:

Anyways. Hope this helps someone.

2 Responses to How to automate GMVault in OSX with Cron
  1. Robert

    Thanks for this article. Exactly what I was looking for. I have a few remarks:

    * Looks like you swapped the hour and minutes in the echo statement that builds the cron command. The minutes go first. Then the hour.

    * I copy/pasted from your article, but the double quotes are screwed, so I needed to first copy to a teksteditor, fix the quotes and then copy to the terminal. I could have just typed the whole thing, but where is the fun in that šŸ™‚

    Robert šŸ™‚

  2. Gabriel

    Robert, you are completely right, thanks for letting me know. I will update the post to correct the minute/hour order.

    About the quotes, that’s weird. I haven’t tried copy/pasting it, but on the post it looks correct. I’ll give it a try and update it if needed. Glad it helped you.

Leave a Reply

Your email address will not be published. Please enter your name, email and a comment.