In Source environment, select the environment version of the site to duplicate.
If you used the Environment Overview in Step 3, this field is pre-selected.
Duplication without cache rebuild execution can break the interface theme. To ensure that a duplicated site reflects the most recent data and configurations, you must clear or rebuild caches and then clear Varnish cache through the UI to complete the duplication process. To rebuild the cache, add a post-site-instance-duplicate script to the codebase.
The hook script triggers after the site instance is active and the corresponding file system and database are provisioned. For additional file system and database provisioning details, check the task logs on the customer codebase overview page.
To add the duplicate site hook:
/hooks directory at the root level.Create the hook script: In the local codebase, create a new script file at the following path, hooks/common/post-site-instance-duplicate.
To execute post-site-instance-duplicate on specific MEO environments, use the following path, hooks/<environment name>/post-site-instance-duplicate.
Add the Drush command Add the cache-rebuild Drush command to ensure the new site is current.
Drush cr (Cache Rebuild): Use for Drupal 8, 9, 10, and 11.
The following is an example of hook script:
#!/bin/bash
set -ev
# Factory Hook: post-site-instance-duplicate (simplified)
# Usage: post-site-instance-duplicate.sh [optional parameters]
echo $*
# Resolve runtime env from execution user; this is the environment where hook runs.
runtime_account="$(whoami)"
runtime_site=""
runtime_env=""
internal_subdomain="$3"
duplicate_param="$4"
echo "Internal subdomain: $internal_subdomain"
echo "Duplicate parameter: $duplicate_param"
if [[ -z "$internal_subdomain" ]]; then
echo "Error: internal_subdomain parameter not provided."
exit 1
fi
if [[ "$runtime_account" == *.* ]]; then
runtime_site="${runtime_account%%.*}"
runtime_env="${runtime_account#*.}"
fi
if [[ -z "$runtime_site" || -z "$runtime_env" ]]; then
echo "Unable to resolve runtime site/environment from account: $runtime_account"
exit 1
fi
echo "Runtime sitegroup: $runtime_site"
echo "Runtime environment: $runtime_env"
destination_domain="$internal_subdomain"
echo "Destination domain: $destination_domain"
# Drush executable:
drush="/mnt/www/html/$runtime_site.$runtime_env/vendor/bin/drush"
# Rebuild all caches (Drupal 8+ recommended)
$drush -r "/mnt/www/html/$runtime_site.$runtime_env/docroot" -l "$destination_domain" cache:rebuild
exit 0
chmod +x hooks/common/post-site-instance-duplicate.Commit and push the script: Add, commit, and push the script to the codebase repository. The hook triggers after the duplicated site is active.
git add.
git commit -m "Add post-site-instance-duplicate hook to clear caches"
git push
If this content did not answer your questions, try searching or contacting our support team for further assistance.
If this content did not answer your questions, try searching or contacting our support team for further assistance.