How-To Backup Gmail with OfflineImap

Gmail’s content can be retrieved via IMAP, and we’ll use this way to backup all our mails thanks to OfflineImap, a generic IMAP synchronization utility.

Let’s start by creating a dedicated configuration file in your home directory. Its content is quite straight-forward, as you can see in my /home/kevin/.offlineimaprc, which backup two Gmail accounts:

[general]
accounts = gmail_account1, gmail_account2
maxsyncaccounts = 3
ui = Noninteractive.Basic

[Account gmail_account1]
localrepository = gmail_account1_local
remoterepository = gmail_account1_remote

[Repository gmail_account1_local]
type = Maildir
localfolders = ~/gmail-backup-account1

[Repository gmail_account1_remote]
type = IMAP
remotehost = imap.gmail.com
remoteport = 993
remoteuser = account1@gmail.com
remotepass = XXXXXXXX
ssl = yes
maxconnections = 1
realdelete = no
folderfilter = lambda foldername: foldername not in ['[Gmail]/%s' % f for f in ['All Mail', 'Trash', 'Spam', 'Starred', 'Important']]

[Account gmail_account2]
localrepository = gmail_account2_local
remoterepository = gmail_account2_remote

[Repository gmail_account2_local]
type = Maildir
localfolders = ~/gmail-backup-account2

[Repository gmail_account2_remote]
type = IMAP
remotehost = imap.gmail.com
remoteport = 993
remoteuser = account2@gmail.com
remotepass = XXXXXXXX
ssl = yes
maxconnections = 1
realdelete = no
folderfilter = lambda foldername: foldername not in ['[Gmail]/%s' % f for f in ['All Mail', 'Trash', 'Spam', 'Starred', 'Important']]

Notice how we use a Python lambda expressions to filter out some Gmail’s virtual folders.

Then all you have to do is to launch the offlineimap command-line itself with the right user, for example in a cron job:

00 20 * * * kevin offlineimap

A final warning: OfflineImap is fully bi-directional. This mean local deletion propagates to the remote server. This is can be quite dangerous so be careful not touching your local folders. If for any reason you’d like to reset your backups, stop OfflineImap processes first, then remove its cache folder (~/.offlineimap/) before removing the local folders themselves (~/gmail-backup-account*).

Also, intensively playing with OfflineImap to adjust its configuration may trigger the infamous Gmail’s “Temporary Error 500″. In this case don’t panic: it seems to be a common Gmail’s auto-immune response against suspect activity. It happened to me and in the end my account and mails were safe: I just had to wait a few hours to let it resume normal operations.

Check Point’s SNX client on Ubuntu 11.04

Last month I had no other alternative but to reach a server through a Check Point‘s VPN. Fortunately the editor provides a Linux client to access its proprietary stack.

The version I found to work on my Ubuntu 11.04 is the SSL Network Extender (SNX) R71 package that can be downloaded there (source).

Just for reference, the build working for me is numbered 800005013, and here is a copy of what to expect when the connection succeed:

$ snx -s vpn.example.net -u my_user
Check Point's Linux SNX
build 800005013
Please enter your password:

SNX - connected.

Session parameters:
===================
Office Mode IP      : 10.32.10.23
DNS Server          : 10.168.10.1
Secondary DNS Server: 10.168.10.2
Timeout             : 3 hours

I contributed $200 to Kdenlive and you should too !

I just donated $200 to the Kdenlive project, as they have just started a fundraising campaign to refactor its core and make it future-proof:

The amount of collected funds is currently at $3,041 from the $4,000 required to pay a developer to work full-time for 2 months. With only $959 remaining and 41 days left, you have no reason to not contribute to the best open-source video editor out there.

I started to play with Kdenlive several years ago with version 0.3. I even created some RPM packages back then. Kdenlive suffered from heavy instabilities in its early days.

But this was a long time ago and today it’s the most stable and practical video editing software available on Linux. It’s the best open-source tool for amateur DSLR shooters, and is worth a try even if your primary desktop manager is not KDE.

Today this software is the one I spend most of my time in at home (just after a web browser and a command-line terminal). And I’ve never felt as productive as the last 2 years: I edited about 2 hours of videos in that period.

Kdenlive must continue to grow. And because I want to use it in my future projects, it makes sense to make a donation. So what are you waiting for contributing too ? :)

Dump, backup and restore a PostgreSQL database

Between user rights, permissions, templates and encoding, believe me or not, but I had some troubles finding a consistent procedure to dump, backup and restore a PostgreSQL database. That’s expected as I’m new to this RDBMS.

So here is the sequence of commands I use to dump a database from a server and copy it to another:

postgres@source-server:~$ pg_dump my_db -v --format=c --file=./my_db_2011-11-23.dump
postgres@source-server:~$ scp ./my_db_2011-11-23.dump postgres@dest-server:~/

Before importing the dump to a new database:

postgres@dest-server:~$ createdb -E UTF8 -T template0 new_db
postgres@dest-server:~$ pg_restore -U my_user -d new_db ./my_db_2011-11-23.dump
postgres@dest-server:~$ psql --command "ALTER DATABASE new_db OWNER TO my_user;"

This hasn’t failed me yet, and I’ll update that post if it will.

Stabilizing Cute Baby Goats

Featured

Stabilizing WHAT ?!?

Baby goats. Cute baby goats. Yes, you’re reading it right. Look:

Yeah, I know, this is a naive video that belongs to /r/aww. But any excuse is good to me when its all about playing with video.

These kids (as baby goats are called) decided to come to this world the night I was around. In a hurry I grabbed my Canon 7D and filmed these newborns with a Sigma 30mm f/1.4 EX DC HSM to leverage its large aperture. And as expected, in the night, with no artificial light and no extra stabilization device, the resulting footage are extremely shaky.

I tried to stabilize the shots but was really disappointed by the results. The final version of the video you watched above only feature the original footage, without any stabilization. But for posterity, here are some notes about the tools I played with.

vid.stab

The first tool I tried was vid.stab, a Transcode plugin that is now part of Transcode itself. But the 1.1.5 version that is bundled with the current Ubuntu 11.10 is quite old.

I wanted to compile it from its sources. But the binary distribution available on the project website works out of the box. To save some effort, let’s install the latter:

$ wget http://public.hronopik.de/vid.stab/files/vid.stab-0.93-transcode-1.1-binary-x86_64.tgz
$ tar xvzf ./vid.stab-0.93-transcode-1.1-binary-x86_64.tgz
$ sudo mv ./vid.stab-0.93-transcode-1.1-binary-x84_64/filter_*.so /usr/lib/transcode/
$ rm -rf ./vid.stab-0.93-transcode-1.1-binary-x8*

Now, as explained in the documentation, you have to let transcode analyze the video:

$ transcode -J stabilize -i ./MVI_1714.MOV -y null,null -o dummy

Only after this first pass you can apply the stabilizing transformations:

$ transcode -J transform -i ./MVI_1714.MOV -y ffmpeg -F huffyuv -o ./MVI_1714-stabilized.MOV

If your not satisfied with the result, you can increase the area of tracking points with the shakiness parameter:

$ transcode -J stabilize=shakiness=8:show=1,preview -i ./MVI_1714.MOV -y null,null -o dummy

In the command line above we added the show=1,preview parameters, which have the nice effect of displaying a preview of the work done behind the scene:

And if you want to see the transformations applied in the final video, just deactivate the cropping and zooming mechanism:

$ transcode -J transform=crop=1:optzoom=0 -i ./MVI_1714.MOV -y ffmpeg -F huffyuv -o ./MVI_1714-stabilized.MOV

Finally, here are some command helpers to automate the stabilization process for a massive amount of video:

$ find ./ -name "*.MOV" -exec transcode -J stabilize -i "{}" -y null,null -o dummy \;
$ find ./ -name "*.MOV" -exec transcode -J transform -i "{}" -y ffmpeg -F huffyuv -o "{}.stabilized.avi" \;

Alternative tools

I told you I was disappointed by the results. For example, in the first shot of the video above, vid.stab will stabilize based on the movements of the head of the goat, not based on the background. All of this because tracking points are generated on hight-contrast area. Unfortunately in this first scene, the only high contrast area is the kid’s head.

Even in shots where the contrast is in our favor, software stabilization don’t always produce nice output. If by chance the tracking points are set on the right objects (those that should be considered motionless), the results may not be pleasing, as it may expose inappropriate skewed perspective, shifting motion-blur and spacial deformation.

While a little bit smarter, YouTube’s embedded stabilization effect still suffer from these same short-comings. If it tries to smooth out consecutive transformations better than vid.stab, it still fails to produce nice output devoid of unattractive artifacts.

Another tool worth trying is VirtualDub, which you can run under Wine and leverage its deshaker plugin. But I didn’t tested it.

Last but not least, Blender can be used to stabilize videos. Again I haven’t tried this yet, but I think it’s the best investment of you time, since the new tracking features make Blender a powerful tool for 3D integration.

Conclusion (tl;dr)

There is no silver bullet: don’t expect software stabilizer to save your shaky shots in post-production. If you want steady shots, plan them beforehand and use proper gear on site, be it a monopod, a tripod, a slider, a dolly, a crane or a steadicam. That’s the only way to eliminate the pain and deception when you hit the editing room.

How-to generate PDF from Markdown

Pandoc

The first tool you can use to convert a Markdown file to PDF is Pandoc.

To install Pandoc and all its dependencies on my Ubuntu 11.04, I used the following command:

$ aptitude install pandoc nbibtex texlive-latex-base texlive-latex-recommended texlive-latex-extra preview-latex-style dvipng texlive-fonts-recommended

Then I applied the PDF transformation on the README.md file from my openerp.buildout GitHub project:

$ wget https://raw.github.com/kdeldycke/openerp.buildout/master/README.md
$ markdown2pdf README.md -o readme-pandoc.pdf

The result is good, but not perfect. For example code blocks with long lines don’t break at the end of the page:

While trying to solve this issue, I stumble upon another tool…

Gimli

Gimli is an utility that was explicitly written with GitHub in mind.

Gimli is written in Ruby, so let’s install it the Ruby way:

$ aptitude install rubygems wkhtmltopdf
$ gem install gimli

Then we can convert our Markdown file to a PDF. The following will generate a README.pdf file in the current folder:

$ /var/lib/gems/1.8/bin/gimli -f ./README.md

The resulting PDF is really close to how GitHub renders Markdown content on its website. And it solve the bad code block style of Pandoc: