node package manager


Migrate your databases simply using Grunt

Grunt Database Migrations

push/pull databases from one location to another using Grunt. Inspired by At first planned as fork, but later I understand what I want something more than push/pull only mysql databases.

IMPORTANT NOTE: the authors of this Plugin assume no responsibility for any actions which result from the usage of this script. You use it entirely at your own risk. It is strongly recommended that you test the script in a non-critical environment prior to rolling out for production use. Always manually backup your local and remote databases before using the script for the first time. No support can be provided for critical situations.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-migrations --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:


This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.

migrations task

Run this task with the grunt migrations[:sub-task] command.



Type: String - path to "backups" folder, relative to grunt task target folder for local environment or relative to your "user home" for remote environments. Also, it can be absolute system path.


Type: Object - environments settings


Type: REQUIRED:Object - settings of local environment (means environment, where grunt runs)


Type: Object - environment meta name, e.g. local, dev, stage, prod etc.


Type: String - environment title, e.g. localhost, development, staging, production etc. Will be used as folder name for databse backups folder for specific environment, e.g. ~/db_backup/<title>/<database_backup>.sql


Type: Object - database settings


Type: String - database host, e.g. localhost, etc.


Type: String - database name


Type: String - database username


Type: String - database password


Type: String - database type mysql, postgree, mongo etc.

IMPORTANT NOTE: currently support only mysql


Type: Object - ssh settings


Type: String - shh host


Type: OPTIONAL:String - shh port


Type: String - ssh username



Type: Object - sub-task config


Type: String:[push|pull] - push/pull source database, where source is config option described below. pull - backup database, push - apply backup from source to target


Type: String - source environment name from options migrations.environments.<environment_name>


Type: String - target environment name from options migrations.environments.<environment_name>

Usage Example

migrations: {
  options: {
    backups: 'db_backup',
    environments: {
      local: {
        title: 'localhost',
        db: {
          host: '',
          name: '<local_db_name>',
          user: '<local_db_user>',
          pass: '<local_db_pass>',
          type: 'mysql'
      dev: {
        title: 'development',
        db: {
          host: 'localhost',
          name: '<dev_db_name>',
          user: '<dev_db_user>',
          pass: '<dev_db_pass>',
          type: 'mysql'
        ssh: {
          host: '<dev_environment_host_or_IP>',
          user: '<dev_ssh_username>'
  'pull-dev': { action: 'pull', source: 'dev' },
  'pull-local': { action: 'pull', source: 'local' },
  'push-dev-to-local': { action: 'push', source: 'dev', target: 'local' },
  'push-local-to-dev': { action: 'push', source: 'local', target: 'dev' }

and run tasks from bash:

> grunt migrations:pull-dev
> Running "migrations:pull-dev" (migrations) task
>> grunt-migrations: execute command START 'ssh -p 22 <dev_ssh_username>@<dev_environment_host_or_IP> \ mkdir -p db_backup/development'
>> grunt-migrations: execute command SUCCESS 'ssh -p 22 <dev_ssh_username>@<dev_environment_host_or_IP> \ mkdir -p db_backup/development
>> grunt-migrations: execute command START 'ssh -p 22 <dev_ssh_username>@<dev_environment_host_or_IP> \ mysqldump -h localhost -u<dev_db_user> -p<dev_db_pass> <dev_db_name> --result-file=db_backup/development/2013-12-18_20-27-56.sql'
>> grunt-migrations: execute command SUCCESS 'ssh -p 22 <dev_ssh_username>@<dev_environment_host_or_IP> \ mysqldump -h localhost -u<dev_db_user> -p<dev_db_pass> <dev_db_name> --result-file=db_backup/development/2013-12-18_20-27-56.sql'
>> grunt-migrations: execute command START 'mkdir -p db_backup/development'
>> grunt-migrations: execute command SUCCESS 'mkdir -p db_backup/development'
>> grunt-migrations: execute command START 'scp -P 22 <dev_ssh_username>@<dev_environment_host_or_IP>:db_backup/development/2013-12-18_20-27-56.sql db_backup/development/2013-12-18_20-27-56.sql'
>> grunt-migrations: execute command SUCCESS 'scp -P 22 <dev_ssh_username>@<dev_environment_host_or_IP>:db_backup/development/2013-12-18_20-27-56.sql db_backup/development/2013-12-18_20-27-56.sql'
Done, without errors.

Release History

  • 2013-12-21 v0.1.0 Added DOC
  • 2013-12-15 v0.0.1 Initial release