Kentico Environment Sync

By Ansel Pineiro On April 09, 2020

Kentico Environment Sync
Your Production Kentico environment has so much more content than your Development environment that it’s impossible to test this new feature you need to design. So what do you do? You sync the environments, of course!

Separate Kentico Environments

In general, it is always a good idea to have a Kentico environment for development that is separate from your production environment. Primarily this keeps your public-facing website stable and online while doing development and testing on an isolated environment.

While processes can vary, typically content is added to the production Kentico environment and over time the differences between environments can become significant.

Syncing Kentico Environments

Kentico has a built-in staging module which is good for deploying content and objects from one Kentico Environment to the other. Staging is normally a one-way linear process in that it goes the direction of a non-production environment up a chain of environments until it reaches production.

typical chain of environments

An environment sync, by contrast, is from an upper environment such as prod down to nonproduction environments. This is a manual process that involves copying the production database and media files and overwriting the non-production database/media files with what’s on production.

environment sync chain

Steps in the Environment Sync Process

While specific steps may vary for different sites and environments, the following are steps that can apply to just about any Kentico environment.

1. Deploy all changes to production. 
Before performing a sync from production, all active development work should be completed, tested and deployed to production. A freeze on further development should be in place until the sync is complete.

2. Make a copy of the production database. 
While staging is the best way to deploy content up to production, the most efficient way to sync content down to non-production environments is to bring down a copy of your production database. All content, data and Kentico objects currently on production would be in that database copy.

For SQL Server the way to do this is to create a full backup and bring the .bak file down to the non-production SQL Server. Later you will delete the existing non-production database and restore this backup in its place.

In Azure SQL the first step would be to export the production database into a .bacpac file and make that available on the non-production environment. Later you will delete the non-production database and create a new database by importing this .bacpac file.

3. Make a copy of the production media files directory
If the production database is the bread of the environment sync, the media files directory is the butter. To have a complete sync you need the media files in addition to the database. Otherwise, your synced environment could have a lot of missing images.

4. Backup non-production database and media files.
Environment syncs involve overwriting the non-production database with the production database. As a precaution in case something you should make a backup of both your non-production database as well as the media files.

5. Have Staging Info ready
Since your non-production database will be overwritten, there is some information that you should note when it comes to Staging Servers and Staging Servers settings.

Staging Servers

Target Servers:
Target Servers screen capture

Target Server Name, URL, and Credentials:
Target Server Name, URL, and Credentials screen capture

Staging Server settings and credentials for non-production site as Staging Target:
Staging Server settings and credentials for non-production site as Staging Target

6. Bring non-production site offline
Before you overwrite your non-production database you should stop the non-production site offline to prevent it from interfering with the process. The simplest way to do this is to create an app_offline.htm file in the root of the CMS directory.

7. Overwrite non-production database
After the database backup is made and the site is brought offline, it is time to delete the non-production database and replace it with the production copy.

8. Replace non-production Media Files
The non-production media files should all be replaced with the media files from production in order to ensure that the site appears as it should.

9. Post-Sync Cleanup (total suggestion - do with it as you will)
Now the sync is (almost) complete. Our non-production environment is an exact copy of production. The only problem is we don’t want an exact copy as that could cause some issues so there is a little cleanup that needs to take place.

10. Disable emails and scheduled tasks
Kentico has powerful email marketing tools and a lot of production sites take advantage of that. That feature should be disabled on non-production sites to prevent potential duplicate emails from being sent, as well as preventing emails from being sent when developing or testing email-related features.

While emails and scheduled tasks can be disabled from the Kentico Admin interface under the settings, it is really better to disable it on SQL before the site starts up so we can be certain that nothing will get sent upon the site starting. The following SQL Script disables Emails and Scheduled tasks.
UPDATE CMS_SettingsKey
SET KeyValue = 'False'
WHERE KeyName IN ('CMSEmailsEnabled', 'CMSSchedulerTasksEnabled')
11. Bring site online
Now that the database and media files have been synced down with emails and scheduled tasks disabled, it is time to start the site back up. If you brought this offline by creating an app_offline.htm file, you can bring it back online by simply deleting it.

12. Verify User Credentials and Privileges
Often privileges are downgraded or completely denied on production environments for security….etc. A double-check on this would be good.

13. Add Kentico License and Site Domain Alias
If the production site already had the non-production Kentico License and domain alias, this step can be skipped. If not, it will be necessary to re-add them.

To add a license, click where it says “Licenses” and login to the Kentico Admin Interface.

"Licenses" on Kentico Admin Interface

After logging in you will be brought to the Licenses Module. Click “New License”

"New License” button

Save button

To add a domain alias go to the Sites Module

Sites Module

Click the edit pin on the site

edit pin location
New domain alias button

Add the domain alias and save



14. Verify Emails and Scheduled tasks are disabled

Settings -> System -> Email -> Email processing -> Enable emails checkbox

"enable emails" check box

Settings -> System -> Scheduler -> Scheduled tasks enabled checkbox

"schedule tasks enabled" checkbox

15. Add back Kentico Staging Servers and Credentials
The Kentico Staging Servers and credentials that were noted earlier should be added back now to ensure that staging can work after this. Also, make sure the “Log Changes” checkboxes are checked so you will have staging items ready upon making changes.

Kentico Staging Servers and Credentials screen captures

Conclusion

No two Kentico sites are the same so exact steps can vary. This blog post is meant to serve as a guide with general steps that can apply to any Kentico site.

Share This Post:

Twitter Pinterest Facebook Google+
Click here to read more Kentico posts
Start a Project with Us
Photo of the author, Ansel Pineiro

About the author

Ansel is the Hotfixer. Whenever a site needs to be hotfixed or upgraded, he gets it done lightning fast. He always seeks to find the right balance between performance and readability in all the code he writes. Between code writing and hotfixes, he makes the office a more enjoyable place to work by finding new music and desktop wallpapers for everyone to enjoy. Some think he’s crazy, but Bizstream knows him as The Hotfixer!

View other posts by Ansel

Subscribe to Updates

Stay up to date on what BizStream is doing and keep in the loop on the latest with Kentico.