Craft Sync plugin for Craft CMS 3.x
Craft Sync lets you sync and backup your database and volume assets across environments from the comfort of the Craft Control Panel.
This plugin is in beta so please be careful (and forgiving
- Craft CMS 3 or later on Linux or MacOS (untested on Windows as of yet)
awscliinstalled in all environments you want to make use of the plugin
- A private AWS S3 bucket for backups
To install the plugin, follow these instructions.
Make sure you have
awscliinstalled in any environment you want to use the plugin
# MacOS $ brew install awscli # Ubuntu $ sudo apt-get install awscli
Open your terminal and go to your Craft project:
$ cd /path/to/project
Then tell Composer to load the plugin:
$ composer require weareferal/sync
In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft Sync.
Craft Sync Overview
Craft Sync is a plugin that makes it possible to sync your database and volume assets across numerous environments from the comfort of the Craft Control Panel. This makes it much easier to move your site from local development to staging and onto production.
This plugin uses AWS S3 (more providers to come soon) as the "single source of truth" for all site DB/volume asset backups. It provides an easy-to-configure settings page as well as an interface in Craft's "utilties" section to:
- Back up DB/volume assets locally
- Push backups to S3
- Pull backups from S3
- Restore backups
For more information read our blog post on "Syncing your DB and assets across environments in Craft 3" or get in touch at email@example.com
This plugin is inspired by who also has a great blog post on syncing you DB and assets in Craft.
Configuring Craft Sync
Configuration is done through the dedicated "Sync" settings panel. The details entered here correspond to your AWS S3 account and bucket that you want to use for backups. It's recommended to set up a new IAM user that has programmatic access (meaning via a acces/secret key) to a private S3 bucket.
Once you have set this bucket up, you can either enter your AWS S3 details directly into the setting page, or you can use environment variables via your
.env file (this is the recommended approach as seen in the screenshot above). This latter approach is more portable and secure as it prevents any private access/secret key values being included in files that you might commit to Github. Furthermore is means these variables can be reused in other plugins etc.
Here is an example portion of a
... AWS_ACCESS_KEY = AWS_SECRET_KEY = AWS_REGION = "us-west-2" AWS_BUCKET_NAME = "feral-backups" AWS_BUCKET_PREFIX = "craft-backups/my-site"
Using Craft Sync
Once you have entered your settings variables you should be able to use the "sync" tab on the "utilities" section of the control panel.
There are two broad sections: one for the database and one for volume assets. Each section has four options to create a local backup, push that local backup to S3, pull all remote backups from S3 and finally to restore a particular backup.
All local backups are stored in the existing
storage/backups folder that Craft uses for its own database backup script.
For database backups and restorations we use the existing Craft scripts - they are just included in our dashboard as an easier consolodated interface.
For volume assets backups, we simply create a versioned zip file containing the handles of all volume assets currently saved in the system. Bear in mind if you have a large number of assets this process may take some time and take up a significant amount of storage.
In each case we use
awscli to handle the syncing of our local folders with S3.
Craft Sync Roadmap
Some things to do, and ideas for potential features:
- Add a "test details" button in the settings page to immediately test S3 connection
- Add more providers
Brought to you by Feral