Grunt plugin for dumping and archiving MySQL databases. Supports exporting and archiving multiple databases in a single operation. Runs asynchronously and extremely fast. Outputs export and compression information as each operation completes. Tested on moderate to large size databases without any problems.
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-mysqldump --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-mysqldump');
In your project's Gruntfile, add a section named mysqldump
to the data object passed into grunt.initConfig()
.
db: grunt.file.readJSON('config/database.json'),
mysqldump: {
dist: {
user: '<%= db.local.user %>',
pass: '<%= db.local.pass %>',
host: '<%= db.local.host %>',
port: '<%= db.local.port %>',
dest: 'backup/',
options: {
compress: 'gzip'
},
databases: [
'my_forum',
'my_blog',
'employees',
'sakila'
],
},
},
To dump all available databases simply use an asterisk aka wildcard. When using the wildcard flag you have the option to ignore specific databases by creating an ignore array.
db: grunt.file.readJSON('config/database.json'),
mysqldump: {
dist: {
user: '<%= db.local.user %>',
pass: '<%= db.local.pass %>',
host: '<%= db.local.host %>',
port: '<%= db.local.port %>',
dest: 'backup/',
options: {
compress: true,
algorithm: 'zip',
level: 5,
both: true
},
databases: [
'*'
],
ignore: [
'information_schema',
'performance_schema',
'phpmyadmin',
'mysql',
'sys'
],
},
},
The database user.
The user's password.
The host of the database.
The port where the database is running, mostly 3306.
The destination folder to write the dump to.
Type: String
Default: both
Required: false
The dump type. Currently supports both
, data
and schema
.
Type: Boolean
Default: false
Required: false
Set to false for no compression. Will only perform a mysqldump of the target database files.
Type: String
Default: zip
Required: false
Currently supports gzip
, deflate
, deflateRaw
, tar
, tgz
and zip
.
Type: Integer
Default: 1
Required: false
Sets the level of archive compression.
Type: Boolean
Default: false
Required: false
You have the option of saving both the sql dump file and the compressed file. Only relevant when archiving.
Type: Array
An array of database names to ignore when exporting. Valid when using a wildcard.
To run all tasks type grunt mysqldump
To target specific tasks register them at the bottom of the data object.
grunt.registerTask('backup', ['mysqldump:stuff']);
Specify the verbose mode parameter to log extra debugging information.
grunt mysqldump:all --verbose
- shelljs - Portable Unix shell commands for Node.js.
- node-archiver - A streaming interface for archive generation.
- each-async - Async concurrent iterator (async forEach).
- bytes.js - Node byte string parser.
- mysql - A pure node.js JavaScript Client implementing the MySql protocol.
- Replace shelljs with child_process.spawn
- Add some tests.
- Fork the project and contribute add tests!
- Email: tom@urlrider.com
Copyright © 2014 tom@urlrider.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.