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

Installation Instructions

To install this plugin, copy the command above to your terminal.

Reviews

This plugin doesn't have any reviews.

Active Installs
11
Version
0.10.1.3
License
MIT
Compatibility
Craft 3
Last release
June 11, 2021
Activity (30 days)
0
Closed Issues
0
Open Issues
0
Merged PRs
0
Open PRs