---
title: "post-staging-update hook in Site Factory"
date: "2024-02-14T06:18:38+00:00"
summary: "Streamline your Site Factory workflow with the post-staging-update hook. Learn how to synchronize data, execute custom scripts, and troubleshoot database updates after staging your production websites to non-production environments."
image:
type: "page"
url: "/site-factory/post-staging-update-hook-site-factory"
id: "b73881a4-7089-42a3-9fa3-688ad47f5b73"
---

After you [stage your production websites](/site-factory/workflow/staging) to a non-production environment, you must run commands on your newly staged websites to synchronize them with your source environment’s data structure.

You can synchronize data with the `post-staging-update` [hook](/site-factory/extend/hooks) for your environment. If you don’t create a `post-staging-update` hook script, Site Factory will instead execute the default `drush updatedb` command.

Note

The `post-staging-update` hook executes only if the non-production and production environments aren’t running the same code.

For information on hook arguments, see [Hook arguments](/site-factory/extend/hooks#acsf-hook-arguments).

Using the post-staging-update hook
----------------------------------

Like several of the other [hooks in use](/site-factory/extend/hooks) by Site Factory, you will create a script file following [best practices for hook scripts](/site-factory/hooks-site-factory "Hooks in Site Factory"). Place the script in a particular directory. Scripts in that directory are run in alphabetical order after the data copying process for each website being staged.

To use the `post-staging-update` hook:

1.  Create a script file including the commands to run after a staging deployment. You can create more than one script file for use with this hook, but the scripts will run in alphabetical order.
2.  Create a directory called `factory-hooks` in the root of your code repository, if it doesn’t already exist.
    
    Note
    
    The `factory-hooks` and [docroot](/definitions/docroot) directories are separate directories at the same level in your code repository.
    
3.  Create a `post-staging-update` directory in the `factory-hooks` directory, if it doesn’t already exist.
4.  In the `/factory-hooks/post-staging-update` directory, add the script file or files you created for this procedure.
5.  Examine the files you created to ensure they have the executable flag. Failing to set the [executable flag](/acquia-cloud-platform/automating-cloud-hooks "Automating with Cloud Hooks") for scripts can prevent Site Factory from executing the files.

After executing a staging deployment, review the newly staged website, as well as any logging output created by your hook script, to check if your hook script executed successfully.

Troubleshooting database update hooks
-------------------------------------

If a script in the `post-staging-update` directory ends with an error (a non-zero exit code), no additional scripts will run in the directory, and the [task logs](/site-factory/monitor/tasklog) will display error messages in `SynchronizeSingleSite` tasks.

Example scripts
---------------

Change the following script to meet your needs:

    #!/usr/bin/env bash
    SITEGROUP="$1"
    ENVIRONMENT="$2"
    DB_ROLE="$3"
    DOMAIN="$4"
    
    echo "sitegroup: $SITEGROUP"
    echo "env: $ENVIRONMENT"
    echo "db role: $DB_ROLE"
    echo "domain: $DOMAIN"
    
    \drush8 -r /var/www/html/$SITEGROUP.$ENVIRONMENT/docroot -l $DOMAIN ev 'echo "Hello world";'