# Restoring Live into Test

Quite a common requirement is to move **Live** Script and (other data, e.g. Users & History) into a **Test** (or Training) environment.\
\
Assuming you have a Test database (and a Test instance of Inter•View) installed, this is a relatively simple task which requires an SQL Backup of the Live database and a restore of this backup over a Test database. This can be done as part of a scheduled **Maintenance Plan** (for general information and useful links describing about Database backups and Maintenance Plans, [click here](http://help.keyfax.biz/Keyfax%20General%20Help%20and%20Technical%20Data%20HC%206/page.aspx?pageid=keyfax%20administrator%20tools%2041xx%20hc6:backup)). \
\
An example below describes how to restore **KF\_Example\_40\_Live** over **KF\_Example\_40\_Test**.

{% hint style="info" %}
**NOTE** When running Keyfax against a copy of Live data, any email addresses held on the database will be used as if Live. You should protect against erroneously raising emails.
{% endhint %}

This example takes a simple approach of running a backup then a restore; this could be improved by pointing at **the most recent live backup media** and simply running the restore from there.&#x20;

1. Start SQL Server Business Intelligence Development Studio (BIDS)
2. Start a new project using the '**Integration Services Project**'  Template and provide a suitable name:

<figure><img src="/files/GdrLRIK5e7KgO4Xkenyx" alt=""><figcaption></figcaption></figure>

3. Unless already visible, display the **Toolbox pane** and drag the **Back Up Database Task** from the Maintenance Plan Tasks onto the Workflow design area:

<figure><img src="/files/M1l2Sncsi1eSuXWd2pEA" alt=""><figcaption></figcaption></figure>

4. Right click the **Back Up Database Task** and select **Edit**. Fill in the contents as per the following example, adjusting paths to suit:

<figure><img src="/files/H2fXeypHXSRxSPwAkfan" alt=""><figcaption></figcaption></figure>

5. As there is no equivalent of the Backup Task in the Toolbox, you will need to craft a **T-SQL** command to perform the restore. Drag and drop an **Execute T-SQL Statement Task** onto the Workflow design pane and connect to the previous backup Task

<figure><img src="/files/R1ZkRAgxYltPcda5ZbQO" alt=""><figcaption></figcaption></figure>

6. Right click this Task and enter a command as below,adjusting names and paths to suit:

<figure><img src="/files/4cTJqW3YkjUk3Zcm7cFJ" alt=""><figcaption></figcaption></figure>

7. When you are happy all names and paths are correct try debug the job by hitting F5 (you can run the job without debugging by hitting CTRL+F5). If both steps complete successfully, the tasks should turn green. If either task has failed, the reason will be displayed in the Progress tab and the task item(s) will appear in red:

<figure><img src="/files/kTzx1x7GsO5OFkb9r8gp" alt=""><figcaption></figcaption></figure>

8. Once  the Tasks are running successfully, you may want to schedule these to run daily, say, at 2am every morning. This is done within **SQL Enterprise Manager** by adding a **New Job** under the **SQL Server Agent**. When you define a Step, select the package just created (I have assumed you saved the package to *disk*):

<figure><img src="/files/uDa9uZaSKn1ev8wP2QEl" alt=""><figcaption></figcaption></figure>

9. Specify a schedule, in this example the job will run at 2am every day:

<figure><img src="/files/SydVR8v9S4YcMrjf9yeC" alt=""><figcaption></figcaption></figure>

10. It should be noted that if a restore takes place on a different SQL Server to where the backup was run, it will be necessary to run the following stored procedure on the newly restored database before it will become available:

```
utAutoFixKeyfaxUserLogins
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keyfax.biz/technical/sql-server/restoring-live-into-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
