I found a great command line tool for backing up and restoring Gmail.

https://github.com/jay0lee/got-your-back