项目作者: vielhuber

项目描述 :
🔥 Sync databases between two servers. 🔥
高级语言: PHP
项目地址: git://github.com/vielhuber/syncdb.git
创建时间: 2016-06-19T18:40:24Z
项目社区:https://github.com/vielhuber/syncdb

开源协议:

下载


🔥 syncdb 🔥

syncdb syncs databases between two servers.

Features

  • Most common use case: Sync your production database to your local environment
  • You also can sync between any servers, even from remote to remote (without local)
  • Works with direct database connections or via ssh tunnels
  • Currently supports mysql, postgresql support will be added soon
  • Has also a fast mode where the sql file is zipped (you also can choose the compression level)
  • Does include a search/replace mechanism called magicreplace
  • (Remote) commands like mysqldump, mysql, zip, e.g. can be overwritten manually to fit any environment
  • Works on Linux, Mac and Windows (with WSL)
  • Supports parallel execution of multiple syncs
  • Uses optimization techniques for a faster restore
  • Also supports ssh connections to servers without the support for public keys
  • Shows live restore progress

Requirements

Mac

Install Homebrew and then coreutils:

  1. brew install coreutils

Windows

Choose one of the two following options:

  • Install WSL2
  • Install Cygwin:
    • Install all default packages + unzip
    • Add C:\cygwin64\bin to your environment PATH (high priority, but below php)

Installation

Mac / Windows (WSL2) / Linux

  1. mkdir ~/.syncdb
  2. cd ~/.syncdb
  3. composer require vielhuber/syncdb
  4. chmod +x vendor/vielhuber/syncdb/src/syncdb

Now add ~/.syncdb/vendor/vielhuber/syncdb/src/ to your path environment.

Windows (CMD)

  1. mkdir "%USERPROFILE%/.syncdb"
  2. cd "%USERPROFILE%/.syncdb"
  3. composer require vielhuber/syncdb

Now add C:\Users\xxx\.syncdb\vendor\vielhuber\syncdb\src\ to your path environment.

Update

Mac / Windows (WSL2) / Linux

  1. cd ~/.syncdb
  2. composer update
  3. chmod +x vendor/vielhuber/syncdb/src/syncdb

Windows (CMD)

  1. cd "%USERPROFILE%/.syncdb"
  2. composer update

Usage

  1. syncdb profile-name

Configuration

Simply put your desired configuration files in ~/.syncdb/profiles/profile-name.json:

  1. mkdir ~/.syncdb/profiles
  2. cd ~/.syncdb/profiles
  3. nano example.json
  1. {
  2. "engine": "mysql",
  3. "source": {
  4. "host": "200.10.10.10",
  5. "port": "3307",
  6. "database": "EXAMPLE",
  7. "username": "EXAMPLE",
  8. "password": "EXAMPLE",
  9. "cmd": "mysqldump",
  10. "ssh": false
  11. },
  12. "target": {
  13. "host": "localhost",
  14. "port": "3306",
  15. "database": "EXAMPLE",
  16. "username": "EXAMPLE",
  17. "password": "EXAMPLE",
  18. "cmd": "mysql",
  19. "ssh": false
  20. },
  21. "replace": {
  22. "https://www.example.com": "http://www.example.local",
  23. "www.example.com": "www.example.local"
  24. }
  25. }

You can find more examples in the profiles folder in this git repo.

Excluding table data

Sometimes it is useful to exclude certain table data (e.g. logs, cache, …), while preserving the structure.
Database engines don’t provide a good way to do this.
Therefore you can use the ignore_table_data-directive in your json-config:

  1. {
  2. "ignore_table_data": ["table1", "table2", "table3"]
  3. }

Privileges

Since MySQL 5.7 and MySQL 8.0.21 accessing the INFORMATION_SCHEMA.FILES table now requires the PROCESS privilege. Most providers don’t have this option available. This results in the error message:

Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces

syncdb automatically adds --no-tablespaces to your mysqldump-commands. You can turn off this behaviour by adding "tablespaces": true to your configuration.