Skip to content

Grunt plugin for dumping and archiving MySQL databases

License

Notifications You must be signed in to change notification settings

CodingPeak/grunt-mysqldump

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-mysqldump

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.

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-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');

The "mysqldump" task

Overview

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'
    ],
  },
},

Wildcard Usage

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'
    ],
  },
},

Arguments

user

The database user.

pass

The user's password.

host

The host of the database.

port

The port where the database is running, mostly 3306.

dest

The destination folder to write the dump to.

type

Type: String

Default: both

Required: false

The dump type. Currently supports both, data and schema.

Options

compress

Type: Boolean

Default: false

Required: false

Set to false for no compression. Will only perform a mysqldump of the target database files.

algorithm

Type: String

Default: zip

Required: false

Currently supports gzip, deflate, deflateRaw, tar, tgz and zip.

level

Type: Integer

Default: 1

Required: false

Sets the level of archive compression.

both

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.

ignore

Type: Array

An array of database names to ignore when exporting. Valid when using a wildcard.

Running

To run all tasks type grunt mysqldump

Running Specific Tasks

To target specific tasks register them at the bottom of the data object.

grunt.registerTask('backup', ['mysqldump:stuff']);

Running Verbose Mode

Specify the verbose mode parameter to log extra debugging information.

grunt mysqldump:all --verbose

Awesome Libraries Used

  • 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.

Todo

  • Replace shelljs with child_process.spawn
  • Add some tests.

If you want to be awesome.

  • Fork the project and contribute add tests!

Questions?

License

(The MIT License)

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.

About

Grunt plugin for dumping and archiving MySQL databases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%