{"id":18319745,"url":"https://github.com/redding/dumpdb","last_synced_at":"2025-10-29T06:54:19.538Z","repository":{"id":5121823,"uuid":"6286601","full_name":"redding/dumpdb","owner":"redding","description":"Dump and restore your databases.","archived":false,"fork":false,"pushed_at":"2018-04-04T21:32:31.000Z","size":46,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T20:46:11.754Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"atomicobject/heatshrink","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-18T22:40:14.000Z","updated_at":"2018-10-20T00:46:33.000Z","dependencies_parsed_at":"2022-08-30T20:41:15.416Z","dependency_job_id":null,"html_url":"https://github.com/redding/dumpdb","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redding%2Fdumpdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redding%2Fdumpdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redding%2Fdumpdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redding%2Fdumpdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redding","download_url":"https://codeload.github.com/redding/dumpdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054200,"owners_count":21039952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T18:14:08.823Z","updated_at":"2025-10-29T06:54:14.488Z","avatar_url":"https://github.com/redding.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dumpdb\n\nDump and restore your databases.\n\n## Usage\n\n```ruby\nrequire 'dumpdb'\n\nclass MysqlFullRestore\n  include Dumpdb\n\n  dump_file { \"dump.bz2\" }\n  source do\n    { :host        =\u003e 'production.example.com',\n      :port        =\u003e 1234,\n      :user        =\u003e 'admin',\n      :pw          =\u003e 'secret',\n      :db          =\u003e 'myapp_db',\n      :output_root =\u003e '/some/source/dir'\n    }\n  end\n  target do\n    { :host        =\u003e 'localhost',\n      :user        =\u003e 'admin',\n      :db          =\u003e 'myapp_db',\n      :output_root =\u003e '/some/target/dir'\n    }\n  end\n\n  dump    { \"mysqldump -u :user -p\\\":pw\\\" :db | bzip2 \u003e :dump_file\" }\n  restore { \"mysqladmin -u :user -p\\\":pw\\\" -f -b DROP :db; true\" }\n  restore { \"mysqladmin -u :user -p\\\":pw\\\" -f CREATE :db\" }\n  restore { \"bunzip2 -c :dump_file | mysql -u :user -p\\\":pw\\\" :db\" }\n\nend\n```\n\nDumpdb provides a framework for scripting database backups and restores.  You configure your source and target db settings.  You define the set of commands needed for your script to dump the (local or remote) source database and optionally restore the dump to the (local) target database.\n\n### Running\n\nOnce you have created an instance of your script with its database settings you can run it.\n\n```ruby\nMysqlFullRestore.new.run\n```\n\nDumpdb runs the dump commands using source settings and runs the restore commands using target settings.  By default, Dumpdb assumes both the dump and restore commands are to be run on the local system.\n\n### Runner Callbacks\n\nDumpdb supports defining callbacks for your script.  These get fired as the script is being run.\n\n```ruby\nclass MysqlFullRestore\n  include Dumpdb\n\n  # ...\n\n  def after_dump\n    # this will be called after the dump commands have been run\n  end\n\nend\n```\n\nAvailable callbacks:\n\n* `{before|after}_run` - called before/after any commands have been executed\n* `{before|after}_setup` - called before/after the runner sets up the script run\n* `{before|after}_dump` - called before/after the dump cmds are executed\n* `{before|after}_copy_dump` - called before/after the dump file is copied from source to target\n* `{before|after}_restore` - called before/after the restore cmds are executed\n* `{before|after}_teardown` - called before/after the runner tears down the script run\n* `{before|after}_cmd_run` - called before/after each cmd is run, passes the cmd obj being run\n\nPhases occur in this order: setup, dump, copy_dump, restore, teardown\n\n### Remote dumps\n\nTo run your dump commands on a remote server, specify the optional `ssh` setting.\n\n```ruby\nclass MysqlFullRestore\n  include Dumpdb\n\n  ssh { 'user@host' }\n\n  # ...\nend\n```\n\nThis tells Dumpdb to run the dump commands using ssh on a remote host and to download the dump file using sftp.\n\n## Define your script\n\nEvery Dumpdb script assumes there are two types of commands involved: dump commands that run using source settings and restore commands that run using target settings.  The dump commands should produce a single \"dump file\" (typically a compressed file or tar).  The restore commands restore the local db from the dump file.\n\n### The Dump File\n\nYou specify the name of the dump file using the `dump_file` setting\n\n```ruby\n# ...\ndump_file { \"dump.bz2\" }\n#...\n```\n\nThis tells Dumpdb what file is being generated by the dump and will be used in the restore.  The dump commands should produce it.  The restore commands should use it.\n\n### Dump commands\n\nDump commands are system commands that should produce the dump file.\n\n```ruby\n# ...\ndump { \"mysqldump -u :user -p :pw :db | bzip2 \u003e :dump_file\" }\n#...\n```\n\n### Restore commands\n\nRestore commands are system commands that should restore the local db from the dump file.\n\n```ruby\n# ...\nrestore { \"mysqladmin -u :user :pw -f -b DROP :db; true\" }   # drop the local db, whether it exists or not\nrestore { \"mysqladmin -u :user :pw -f CREATE :db\" }          # recreate the local db\nrestore { \"bunzip2 -c :dump_file | mysql -u :user :pw :db\" } # unzip the dump file and apply it to the db\n#...\n```\n\n### Command Placeholders\n\nDump and restore commands are templated.  You define the command with placeholders and appropriate setting values are substituted in when the script is run.\n\nCommand placeholders should correspond with keys in the source or target settings.  Dump commands use the source settings and restore commands use the target settings.\n\n### Special Placeholders\n\nThere are two special placeholders that are added to the source and target settings automatically:\n\n* `:output_dir`\ndir the dump file is written to or read from (depending on whether dumping or restoring).  This is generated by the script instance.  By default, no specific root value is used - pass in a `:output_root` value to the source and target to specify one.\n\n* `:dump_file`\npath of the dump file - uses the :output_dir setting\n\nYou should at least use the `:dump_file` placeholder in your dump and restore commands to ensure proper dump handling and usage.\n\n```ruby\ndump_file { \"dump.bz2\" }\n\ndump    { \"mysqldump :db | bzip2 \u003e :dump_file\" }\nrestore { \"bunzip2 -c :dump_file | mysql :db\" }\n```\n\n## Source / Target settings\n\nA Dumpdb script needs to be told about its source and target settings.  You tell it these when you define your script:\n\n```ruby\nclass MysqlFullRestore\n  include Dumpdb\n\n  source do\n    { :user      =\u003e 'something',\n      :pw        =\u003e 'secret',\n      :db        =\u003e 'something_production',\n      :something =\u003e 'else'\n    }\n  end\n\n  target do\n    { :user =\u003e 'root',\n      :pw   =\u003e 'supersecret',\n      :db   =\u003e 'something_development'\n    }\n  end\n\n  # ...\nend\n```\n\nAny settings keys can be used as command placeholders in dump and restore commands.\n\n### Building Commands\n\nAs you may have noticed, the script DSL settings methods all take a proc as their argument.  This is because the procs are lazy-eval'd in the scope of the script instance.  This allows you to use interpolation to help build commands with dynamic data.\n\nTake this example where you want your dump script to honor ignored tables.\n\n```ruby\nrequire 'dumpdb'\n\nclass MysqlIgnoredTablesRestore\n  include Dumpdb\n\n  # ...\n  dump { \"mysqldump -u :user -p :pw :db #{ignored_tables} | bzip2 \u003e :dump_file\" }\n  # ...\n\n  def initialize(opts={})\n    opts[:ignored_tables] ||= []\n    @opts = opts\n  end\n\n  def ignored_tables\n    @opts[:ignored_tables].map{ |t| \"--ignore-table=#{source.db}.#{t}\" }.join(' ')\n  end\nend\n```\n\n## Examples\n\nSee `examples/` dir. (TODO)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'dumpdb'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install dumpdb\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredding%2Fdumpdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredding%2Fdumpdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredding%2Fdumpdb/lists"}