{"id":13880152,"url":"https://github.com/basecamp/mysql_role_swap","last_synced_at":"2025-07-20T03:31:14.172Z","repository":{"id":5729722,"uuid":"6941558","full_name":"basecamp/mysql_role_swap","owner":"basecamp","description":"(Nearly) Zero interruption mysql maintenance script.","archived":false,"fork":false,"pushed_at":"2023-01-22T18:22:13.000Z","size":29,"stargazers_count":284,"open_issues_count":4,"forks_count":31,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-07-18T05:34:48.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basecamp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-30T15:56:57.000Z","updated_at":"2025-07-10T21:20:20.000Z","dependencies_parsed_at":"2023-02-12T17:30:20.233Z","dependency_job_id":null,"html_url":"https://github.com/basecamp/mysql_role_swap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/basecamp/mysql_role_swap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fmysql_role_swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fmysql_role_swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fmysql_role_swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fmysql_role_swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basecamp","download_url":"https://codeload.github.com/basecamp/mysql_role_swap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fmysql_role_swap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266063095,"owners_count":23870716,"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-08-06T08:02:49.178Z","updated_at":"2025-07-20T03:31:14.140Z","avatar_url":"https://github.com/basecamp.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# mysql\\_role\\_swap\n\n\nmysql_role_swap is a script written in Ruby to perform all of the tasks that we normally perform when promoting a slave database to master. It performs all of the necessary checks to be sure that the transition is as smooth as possible. It uses the mysql and activerecord libraries to perform these tasks.\n\n## Design Concepts:\nmysql_role_swap is based on a few key design concepts: The script should be easy to understand and troubleshoot. The script should handle errors gracefully and provide ample data for manual recovery in the event human intervention is needed. We should be deterministic about the state of each step of the failover process.\n\n## History:\nIn April 2011, after planning yet another manual database failover, Taylor shared the use of a statemachine and original design concept with John. One weekend later version one was born and reliably working on some test virtual machines. Since April 2011 John has shepherded the script through multiple rounds of testing in a staging environment. Taylor got the bright idea to add support for moving a virtual IP to the script, and since then the script has been used numerous times in production database environments without issue.\n\n## Improvements:\nWe've designed mysql_role_swap to do work reliably in our environment at [37signals](http://37signals.com) however we believe through wider adoption and contributions from other organizations this script can become even more efficient and reliable. Almost all of the configuration is done by our Chef recipes -- and thus things are a little environment specific right now. With your help we can make this a little less 37-specific.\n\n# Getting started\n### Installation\n#### Pre-requisites\n\nHow do I use it?\n\nThe script has been deployed on all of our database servers. And it is located at:\n\n    /usr/local/bin/mysql_role_swap\n\nWhen running the script you must specify at least one of the following options:\n\n* Database Instance Name (-d): The name of the MySQL instance that you are swapping roles on. (This is used to create the path to the cluster.yml file)\n* Full Config Path (-c): Full path to the cluster.yml file.\n\nOptional options:\n* Check (-s): The check option will only run the preflight checks on the database and will not attempt to fail over.\n* Force (-f): The force option will not prompt you before failing over the database. If there is a configuration problem the failover will not proceed. (use carefully)\n\n\nYou also need a cluster.yml file so the script can do all its magic correctly.\n\nHere's a sample cluster.yml:\n\n    floating_ip: 10.10.10.37\n    floating_ip_cidr: /32\n    master_ipmi_address: 10.10.99.137\n\n    database_one:\n      adapter: mysql\n      username: failover_user\n      password: iluvsql\n      primary_database: 37_production\n      host: 10.10.9.137\n      port: 3306\n      slave_password: iluvsql2\n\n    database_two:\n      adapter: mysql\n      username: failover_user\n      password: iluvsql\n      primary_database: 37_production\n      host: 10.10.9.138\n      port: 3306\n      slave_password: iluvsql2\n\nExample Usage:\n\nUsing the \"-d\" option:\n\n    mysql_role_swap -d failovertest\n    Current Cluster Configuration:\n\n    Floating IP: 10.10.3.160\n\n    Master: dbslave:3310\n    MySQL Replication Role: master\n    Floating IP Role: master\n    MySQL Version: [5.1.45-log]\n    Read-Only: false\n    Arping Path: /usr/bin/arping\n\n    Slave: shr-db-02:3307\n    MySQL Replication Role: slave\n    Floating IP Role: slave\n    MySQL Version: [5.1.45-log]\n    Read-Only: true\n    Arping Path: /usr/bin/arping\n\n\n# Getting help and contributing\n\n### Getting help with mysql_role_swap\nThe fastest way to get help is to send an email to mysqlroleswap@librelist.com. \nGithub issues and pull requests are checked regularly.\n\n### Contributing\nPull requests with passing tests are welcomed and appreciated.\n\n# License\n\n     Copyright (c) 2012 37signals (37signals.com)\n\n     Permission is hereby granted, free of charge, to any person obtaining\n     a copy of this software and associated documentation files (the\n     \"Software\"), to deal in the Software without restriction, including\n     without limitation the rights to use, copy, modify, merge, publish,\n     distribute, sublicense, and/or sell copies of the Software, and to\n     permit persons to whom the Software is furnished to do so, subject to\n     the following conditions:\n\n     The above copyright notice and this permission notice shall be\n     included in all copies or substantial portions of the Software.\n\n     THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n     LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n     OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n     WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasecamp%2Fmysql_role_swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasecamp%2Fmysql_role_swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasecamp%2Fmysql_role_swap/lists"}