SyncDb


Craft 3 plugin to sync database across environments.

Craft SyncDb uses unionco/syncdb to perform database synchronization across your different environments. Both MySQL and PostgreSQL databases are supported.

Craft SyncDB

Overview

Craft 3 plugin to sync database across environments

Craft SyncDb uses unionco/syncdb to perform database synchronization across your different environments. Both MySQL and PostgreSQL databases are supported.

Source code is available on Github

Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require unionco/craft-sync-db
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for craft-sync-db.

Configuration

Configuration of remote servers is done via config file <CRAFT_ROOT>/config/syncdb.php. This file should be copied into your config/ directory automatically. If it is deleted, you can copy it from vendor/unionco/craft-sync-db/config/default.php.

There are several properties needed for each environment. Given the example config:

<?php

use Symfony\Component\Console\Output\Output;
use unionco\craftsyncdb\services\CpService;

/**
 *  This is the default configuration that will be copied into your Craft
 *  config path, if it does not exist. Any changes to this file will be
 *  overwritten
 **/

 return [
    'globals' => [
        // Array of tables to ignore in dump (currently only supported for MySQL)
        'ignoredTables' => [
            'craft_templatecaches',
            'craft_templatecachequeries',
            'craft_templatecacheelements',
        ],
    ],
    'remotes' => [
        'production' => [
            'username' => 'user',
            'host' => 'example.com',
            'root' => '/home/user/Sites/craft-project/',
            'backupDirectory' => '/home/user/Sites/craft-project/storage/backups/databases/',
            'port' => 22,
            'phpPath' => '/usr/bin/php',
            'dbDumpClientPath' => '/usr/bin/mysqldump', // Use pg_dump for Postgres
            'verbosity' => Output::VERBOSITY_DEBUG, // See Symfony\Component\Console\Output\Output for verbosity options
            'environment' => CpService::ENV_PRODUCTION,
        ],
        // 'staging' => [
        // ...
        // ],
    ],
];

Each environment requires the following properties:

propertydescription
usernameSSH/server username
hostSSH/server hostname or IP
rootPath of the Craft installation on the server
backupDirectoryPath where database backups will be created on the remote server
portSSH port
phpPathPath to php executable
dbDumpClientPathPath to mysqldump or pg_dump executable
verbosityLog level
environmentDetermines the environment, e.g. dev, staging, production. Used so that lower environments are never synced into higher environments

Usage

NOTE: craft-sync-db plugin must be installed on the project on the remote server as well.

As of version v0.5.0, craft-sync-db provides a CP user interface.

To use craft-sync-db on the command line: php craft sync-db/sync <remote_key> [log_level], where <remote_key> is an array key in your configuration file and [log_level] (optional) is one of: verbose, normal, or quiet .

Brought to you by Union


Free

Package Name

To install this plugin, search for its package name on the Plugin Store and click “Install”.


Information

  • Version v0.7.3
  • Last Update 10/17/2019
  • Active Installs 239
  • Compatibility Craft 3
  • License MIT
  • Categories Utilities, Development

Report an issue