Schedule database synchronization

You can schedule or automate a comparison or synchronization with the help of Schema Compare and Windows Task Scheduler.

Scheduling database synchronization includes the following steps:

Create a .bat file via dbForge Schema Compare

First, you need to create a file with the .bat extension for comparing or synchronizing the databases.

To create the .bat file, do the following:

1. On the standard toolbar, click New Schema Comparison. The Schema Synchronizaton Wizard window opens.

2. On the Source and Target tab, select the source and target connections and databases for comparison and click Next.

3. On the Options tab, select the options for schema comparison and then click Next.

For more information about options, refer to Configure comparison options.

4. Optional: On the Schema Mapping tab, edit schema mapping settings for schema comparison and then click Next.

Note

By default, Schema Compare automatically maps objects with the same name and schema. For more information about mapping settings, refer to Map schemas.

5. Optional: On the Table Mapping tab, verify the objects to be compared or change the mapping of tables and columns, and then click Compare to run the comparison process.

Note

By default, Schema Compare automatically maps tables and columns having the same name in the source and target data sources. For more information about mapping tables and columns with different names, refer to Map tables and columns.

6. In the Schema Compare window, select the objects you want to synchronize and click Synchronize objects to the target database button in Schema Compare Synchronize objects to the target database.

7. In the Schema Synchronization Wizard that opens, set the synchronization options and then click Save Command Line.

Save Command Line button in the Schema Synchronization wizard

8. In the Command line execution file settings window that opens, verify and configure the settings to manage the *.bat file text.

Command line file settings

Command-line file settings

Name Default State Description
Comparison Project No Load command-line settings from the previously created comparison project file with the .scomp extension.
Source Yes Specify the source options: a server, a database, a connection, a snapshot, a backup, and a scripts folder.
Target Yes Specify the target options: a server, a database, a connection, a snapshot, a backup, and a scripts folder.
Comparison Options No Set options to manage the comparison process.
Report No Generate a schema comparison report file.
Report Format No Specify the format of the file comparison report: HTML (selected by default), XML, XMLFOREXCEL. If not specified, the format of the file comparison report takes the extension of the report file.
Include Objects No Specify the objects to be included in the report:
All (selected by default) - all objects
Filtered - filtered objects
Diff - objects with differences
SelectForSync - objects selected for the synchronization.
Log File No Generate a comparison log file in the specified directory.
Synchronization Yes Start database synchronization. If an output file is specified, only synchronization script will be generated.
Synchronization Options No Set options to manage the synchronization script.
Synchronization File Yes Specify a path to the database synchronization script file.
Execute No Execute the file received in the result of the previous commands execution.
Error Code No Enable the processing of error levels.
Arguments File No Specify a command-line arguments file. If a path to the arguments file is specified, a separate command-line file will be generated.
Echo OFF No Disable echoing all commands in the batch file. All the text in the batch file is enclosed in the @Echo OFF … @Echo ON command.
Keep opened No Set a pause command at the end of the batch file text. The command window will be opened.
PowerShell No Generate the & symbol at the beginning of the batch file text. This makes the batch file compatible with PowerShell.

9. Optional: To verify that the command line settings are valid, click Validate.

10. To save the script as a *.bat file, click Save.

Create a synchronization task using Windows Task Scheduler

After the batch file for database synchronization has been created, we can proceed with the creation of a synchronization task using the Windows Task Scheduler so that the computer can carry out the task automatically.

To create a Windows synchronization task, do the following:

1. Open the Control Panel > Administrative Tools and select Task Scheduler.

2. In the Task Scheduler window that opens, navigate to the Actions pane and click Create Basic Task to create a scheduled task.

Note

For quick access to the Task Scheduler, just start typing task in the Windows 10 search bar. Once you see the Task Scheduler in the list, click it to open.

Click Create Basic Task in Windows Task Scheduler

3. In the Create Basic Task Wizard window that opens, specify the name and description of the task and click Next.

Specify the name and description

4. On the Trigger tab, choose when to launch the task and then click Next.

  • Schedule based on the calendar: Daily, Weekly, Monthly, or One time. For this, specify the schedule you want to use.
  • Schedule based on common recurring events: When the computer starts or When I log on.
  • Schedule based on specific events: When a specific event is logged. For this, specify the event log, source, and even ID using the drop-down lists.

Select the time period for the task to be started

5. On the Action tab, click Start a program to schedule a program to start automatically and then click Next.

Schedule a program to start automatically

6. On the Start a Program subtab, click Browse to select the .bat file you have created in the Schema Synchronization Wizard and then click Next.

There are optional fields that you can set:

  • Add arguments: Specify the arguments to run the task with specific instructions.
  • Start in: Specify the folder in which the program will start.

Start a program

7. On the Finish tab, verify the settings and click Finish.

The task will be displayed in the Active Tasks section.

View the created task in the Active Tasks section of Task Scheduler

See also:

Helpful materials

How to Automatically Synchronize Schema Changes in Two SQL Server Databases on a Schedule

Explore how to automate and schedule the synchronization process of two SQL Server databases.1

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Schema Compare for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Schema Compare in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Schema Compare for your business, request a demo to see it in action.
Ready to start using dbForge Schema Compare for SQL Server?