DumpTruck
Ruby wrapper for the mysqldump executable
Requirements
- Ruby 1.9.3 or higher
- mysqldump executable
Installation
gem 'dumptruck'
or install the gem manually
gem install dumptruck
Usage
The purpose of this gem is make mysqldump
be as simple as possible. The mysqldump
command can be pretty tricky and more than likely, if you're attempting a pretty elaborate dump, you'll have to run the command more than once. Thats what this gem attempts to automate. The gem will run multiple interations of mysqldump
to an output file and directory you choose. To start, create a truck object:
truck = Dumptruck::Truck.new({
username: "username",
password: "password",
host: "127.0.0.1", #localhost is default
port: 3306, #default
output_dir: "/tmp", #where the dump files go
filename: "output", #default, can be changed
mysqldump_bin: "/path/to/bin/"
})
You don't need to know or specify where the mysqldump
executable is as long as it can be found in your environment PATH
. Otherwise you can specify it in the params hash. If you don't specifiy it and an executable isn't found, an error will be raised.
Once you have the truck object created you can load it with your configuration.
truck.load({
database: 'db', #required for now, raises an error if not set
ignored_tables: ['table1','table2','table3'], # optional
options: ['--single-transaction', '--quick'], # default values
})
Or you can create the load object independently and pass it to the truck.load
method separately.
load = Dumptruck::Load.new({
database: 'db',
ignored_tables: ['table1','table2','table3'], # optional
options: ['--single-transaction', '--quick'] # default values
})
truck.load(load)
You can add as many loads as needed in order to get the output file you want. When you have everything set just call truck.dump
and it will run the mysqldump
command and create a single gzipped output file. The truck.dump
method returns a hash of the time (in seconds) it took to run and the output files location.
{
time: 8.0992,
file: #<File:/Users/drew.delianides/Desktop/output_01-01-02-1534.sql.gz>
}
Contribution
Please do. This is my first 'real' gem and probably could use some refactoring. So any help is appreciated.