Backup mongodb on Heroku and push it to S3 or FTP with cron task.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 37 commits behind alexkravets:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

heroku-mongo-backup — backup mongodb on Heroku and push it to S3 or FTP storage

heroku-mongo-backup does:

  1. Backup mongodb collections to one file;
  2. Compress backup file with gzip;
  3. Push backup to the specified S3 bucket or FTP server;

Why not mongodump command?

mongodump command is not available on Heroku side. If you don't want to setup third party backup service for every project heroku-mongo-backup may be helpful.


Add gem to the Gemfile: gem "heroku-mongo-backup"

For S3 support heroku-mongo-backup requires s3 or aws-s3 library. One of those should be in Gemfile, if any of those two is present add aws-s3.

Require for heroku_mongo_backup in config\application.rb:

  class Application < Rails::Application
   require 'heroku_mongo_backup'

Add backup task to /lib/tasks/cron.rake file:

desc "This task is called by the Heroku cron add-on"
task :cron => :environment do

Set Heroku environment variables:

heroku config:add S3_BACKUPS_BUCKET=_value_ S3_KEY_ID=_value_ S3_SECRET_KEY=_value_ MONGO_URL=_value_

First three are Amazon S3 auth settings and the last one should be copy of MONGOHQ_URI or MONGOLAB_URI depending on what heroku add-on is used for mongo. MONGO_URL is a variable which is used also for heroku-mongo-sync command.

For FTP set these variables:

heroku config:add UPLOAD_TYPE=ftp FTP_HOST=_host_ FTP_PASSWORD=_pass_ FTP_USERNAME=_user_

Rake Commands

  • heroku rake mongo:backup
  • heroku rake mongo:restore FILE=backup-file-name.gz


  1. alexkravets - S3 support
  2. matyi - FTP support