Synchronizing Dev/prod Environment With Sulu

When we started using Sulu as CMS for our customer’s websites, we soon found out that we need a way to copy contents (such as pages, snippets and images) between different Sulu installations. We solved that problem with, a very simple but highly effective Symfony Bundle. It’s small, it’s nothing special but it already saved us hours of work and it could do the same for you.

The problem

The client starts creating a lot of contents in Sulu - pages, snippets, photos and such. The developers usually don’t have realistic content, but only example texts and images. If the client encounters a problem, the developers might not be able to reproduce the problem, since they don’t have the same contents in their local Sulu installation.

The live system has a lot of contet, that the developer system doesn't

Normally the developers have two options:

Option 1: The developer could ssh into the live system, export and download the MySQL database & PHPCR repository, download all the uploaded photos and import the data into his local installation.

This is not a good option. The developer would need ssh access to a productive system. We believe that as a developer, it shouldn’t be necessary to connect to the productive system at all during development. If you have to do that, your continuous integration is not good enough. Apart from that, this procedure needs a lot of time.

Option 2: The developer could create the contents manually. This involves a lot of clicking and needs even more time.

This is where our bundle comes into play!

How it works

The bundle contains two commands: ImportCommand & ExportCommand.

ExportCommand exports all the important data of the Sulu application (i.e. uploads, MySQL Database & PHPCR Repository). It creates 3 files in the web folder. Your application’s secret from parameters.yml is used as the filename.

ImportCommand is used by developers to import the live system’s data. It downloads the files generated from ExportCommand from a given host and imports them. It’s also possible to skip the download of uploads, since those can take some time to download. Of course developers need to have the same secret as the application in the live system.

How we use it

On every push to our project’s master branch, a build is triggered. At the very end of our build process, ExportCommand is executed. That means that on every build, the CMS data is saved. Life can be so simple!

Check out the code on GitHub.