Dump local or remote MYSQL databases using Grunt.
IMPORTANT NOTE: the authors of this Plugin assume no responsibility for any actions which result from the usage of this script. Specifically, the integrity of the generated dumps cannot be guaranteed. Use this plugin 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. Make sure it generates dumps that match your requirements before relying on it as a backup solution.
This plugin requires Grunt
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-mysql-dump --save-dev
In your project's Gruntfile, add a section named
db_dump to the data object passed into
The task expects a series of
targets, one for each of the locations which you want to dump the database from.
The plugin makes one new task available via Grunt:
db_dump. The interface for this command is:
This will dump the database according to the options found in the
You can dump databases for all targets by simply calling
You must define targets as shown above. Each target defines the connection information to the targeted database and the destination file name of the generated dump:
"local":"options":"title": "Local DB""database": "db_name""user": "db_username""pass": "db_password""host": "db_host""backup_to": "/db/backups/local.sql"
You can also connect to a remote host using SSH by specifying a
ssh_host option in your target:
"production":"options":"title": "Production DB""database": "db_name""user": "db_username""pass": "db_password""host": "db_host""ssh_host": "db_ssh_host""backup_to": "/db/backups/production.sql"
The structure below represents a typical usage example for the task configuration. Obviously you should replace the placeholders with your own database/environment configurations.
Each target expects a series of configuration options to be provided to enable the task to function correctly. These are detailed below:
Description: A proper case name for the target. Used to describe the target to humans in console output whilst the task is running.
Description: the name of the database for this target.
Description: the database user with permissions to access the database
Default: (empty password)
Description: the password for the database user (above)
Description: the hostname for the location in which the database resides. Typically this will be
Description: the port the mysql server listens to
Description: ssh connection string in the format
SSH_USER@SSH_HOST. The task assumes you have ssh keys setup which allow you to remote into your server without requiring the input of a password. As this is an exhaustive topic we will not cover it here but you might like to start by reading Github's own advice.
"db/backups/<%= grunt.template.today('yyyy-mm-dd') %> - <%= grunt.task.current.target %>.sql"
Description: full destination file path of the generated dump. This option can include templates such as
<%= grunt.template.today('yyyy-mm-dd') %> or
<%= grunt.task.current.target %>.
No global option as of now
If you’re using MAMP, then mysql command line tools are not made available in your PATH automatically.
For this plugin to work, you must find out the path to these tools (On Mac OS: bundled in MAMP.app; on Windows/Linux: probably within the app's directory tree) and add that path to your PATH environment variable!
Contributions to this plugin are most welcome. This is very much a Alpha release and so if you find a problem please consider raising a pull request or creating a Issue which describes the problem you are having and proposes a solution.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
targetvia options, README doc fixes, pass host param to mysqldump.
This plugin is a stripped down and modified version of @getdave's plugin grunt-deployments It is released under the same MIT license, as found in the LICENSE-MIT file. Copyright (c) 2013 Digital Cuisine