Hacker news and computer knowledge

19 Dec 2014

How to Automatically Back Up and Purge Your Gmail Every 30 Days



If the Sony hack has taught us anything, it's that keeping incriminating emails in your inbox is a terrible idea. Even if you aren't doing anything particularly bad, if someone gets into you email, everything you've ever said could be out in the open. Here's how to make sure that doesn't happen by automatically backing up and deleting everything in your Gmail account on a schedule.

How to Automatically Clear Out 30 Day Old Messages

How to Automatically Back Up and Purge Your Gmail Every 30 Days
If you want to clear out your Gmail every so often, you'll need a Google Script. We're going to use this one from Digital Inspiration. You can do this with a lot of email clients, but we're going to focus on Gmail. If you'd prefer, here are guides for Outlook and Thunderbird. Google Apps owners can also just change the retention period for emails. That said, here's how to set it up on regular old freebie Gmail account:
  1. Click here to make a copy of the Google Auto-Purge Script
  2. The script deletes emails based on label, so you'll need to enter the labels you want here. For a catch-all, use "Inbox," for the var GMAIL_LABEL = " "; line. Unfortunately, you'll need to do this for each label, but it will also pull messages you've archived.
  3. Enter in the number of days you want to schedule the purging for under var PURGE_AFTER = "1"; for our purposes we chose 30. Any message older than 30 days old gets sent to the trash
  4. Click Run > Initialize and follow the prompts to add permissions
  5. Click Run > Install to install the script.
Now, your Gmail account will clear out any message older than 30 days. If your Gmail account is filled to the brim with email, you might want to go through and delete everything manually at first. It's worth noting that this moves your messages to Gmail's trash, which takes 30 more days to completely delete. If you're worried about that, set a reminder to pop into your trash and manually delete everything.

How to Back Up and Encrypt Your Gmail Account on a Schedule

How to Automatically Back Up and Purge Your Gmail Every 30 Days
Deleting your email is pretty easy, but once it's gone, you can't search through old emails anymore. That sucks. So, you might consider making an encrypted, local backup of your email. This way, you can search through it when you need to, but your emails won't be stored on anyone's servers, ripe for hackers.
You have a lot of options for this (including some if you're not using Gmail), but we're going to use the open source software GMVault to download a backup of the Gmail account.


  1. Download and install GMVault for your operating system
  2. Open the app, you'll get a command line interface
  3. Head back to GMVault and type in gmvault sync -e account@gmail.comreplacing account@gmail.com with your email address
  4. You'll be asked to log in and allow GMVault access to your account in your default browser. Click "Allow Access"
  5. Head back to GMVault and press Enter. It'll back up all of your email and encrypt it (your encryption key is saved on your hard drive under /users/name/gmvault-db/.info/.storage_key.sec). It takes a while, so let it do its thing.
That's your first backup and it'll probably take a while before it's finished up. Restoring your email depends on how you want to view them. GMVault has a guide for various restore optionsdepending on when you want. Once the GMVault backup is done, you'll want to set up a system to back up your email once a week. How you do this depends on whether you're on Windows or OS X.
If you're not using Gmail, you can create a backup of your email using just about any desktop email client. Here are guides for some of the more popular apps:
When you finish backing up your email, you can then go ahead and encrypt those files locally if you want.