Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article contains information about the backup concept and technical configuration as well as the procedure for switching to backup during a primary server failure.

This is an optional step if redundancy is required for your database server.

This article applies to MySQL 5.5 & +

Operational Summary

About Backup Servers

Your BL Backup server is designed to provide safety against data loss and on-air downtime in the event of drive or other hardware failure on your Primary server.  When setup and running using the instructions below the Primary server will synchronize your data changes with the Backup server. Your Backup data will never be more than a couple seconds behind the Primary when replication is running.

During Normal Operation

All the parsers, readers, and Flow are setup on the Backup server but the parsers and readers are not running and Flow should not be accessed. No changes should be made to the data on the Backup server as it will conflict with the incoming replication changes from the Primary server.

Note

Do not start or run parsers, readers or log in to Flow on the Backup server while the Primary is active

During a Primary Server Failure

During a Primary server failure, your on-air output is the most important component to have up and running. In the preferences of your player, switch the IP of the database from your Primary to your Backup. BL players have data caching which will keep the graphics on air for several minutes. After the player has been switched to the Backup database server, log in to the Backup server and start any readers and parsers. Continue to access Flow by using the Backup server IP in the same manner as you would your Primary server. When a new Primary server is obtained or the current Primary fixed, it will become the Backup and your current Backup which you have been running will be your Primary.

In the event of a full primary database server failure the easiest way to switch several players to point to the backup server is to:

  1. Set the backup server IP to the primary server's IP.

If this is not an option in your environment the second option is to:

  1. Set your player database IP to that of the Backup server.

Proceed with the remainder of the recovery steps:

  1. Start all parsers and readers on the Backup server.

  2. Start up the backup website using the instructions below and sign in to Flow on Backup server IP and continue work.

Starting Your Backup Flow Web Server

The Flow webserver is paused on your backup server to prevent causing synch issues with the backups. This can happen when a user signs in on the backup Flow and it creates an audit record that is not from the primary. The backup Flow can be tested on install, but after replication is setup, it will be paused to prevent data conflicts.

To restart your backup Flow web server follow the steps below.

  1. Launch Internet Information Services (IIS) Manager. This can be found in the Administration section of the Control Panel or search for IIS in the Start Bar

  2. Roll out the tree until the Default Web Site is visible and click on it to bring up the properties pane.

  3. On the right of the pane will be controls for stopping, starting and restarting the website under the Manage Website heading.

  4. Click on Start

  5. You can now access your backup Flow though a web browser. 

Replication Backup

Initial Preparation For Replication Backups

Both your servers must have the same MySQL version installed. 

Create a Backup/Replication user

This user will be used on the backup to connect to the primary/source database to access the changes so it can apply them too. This user will be used on the primary/source by DMan to check the status of the backup server and report in to the Agent Status tool in Flow.  Ideally having the same user on BOTH the Source and Backup system. 

You can use the default blbackup user. See Configuring MySQL Users and look for the section on replication user.

Server Configuration

Binary logging must be enabled on the servers because the binary log is the basis for sending data changes from the source to its backups. If binary logging is not enabled, replication will not be possible.

Unless you have made changes to your MySQL setup, binary logging is enabled by default.

Adding Server ID to the INI file

Each server within a replication group must be configured with a unique server ID. This ID is used to identify individual servers within the group.

Find the my.ini configuration file in the C:\ProgramData\MySQL\MySQL Server 5.6 folder and edit it adding the following section under the mysqld section.  

server-id =1 is a common ID for the primary

server-id=2 is a common ID for the backup

For the Primary

Code Block
languagesql
[mysqld]
server-id=1
log-bin=mysql-bin

 
# Alternatively to store log files on another drive with lots of space:
# log-bin=d:/MySQL/Logs/mysql-bin 

For the Backup

Code Block
[mysqld]
server-id=2

Additional server settings

Confirm the following entries are already present and if not add the additional entries as follows:

NOTE: If there is a # symbol in front of it - that makes it a comment and you need to remove the # to make the setting active.

Code Block
languagesql
# binlog_format=mixed  # deprecated in version 8.0.34 
binlog_format=row 
binlog_row_image=minimal

# For the greatest possible durability and consistency in a replication setup that uses InnoDB with transactions, use these settings: 
#   https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_sync_binlog 
sync_binlog=1
innodb_flush_log_at_trx_commit=1

Recommended: Use an entry to control how soon binary logs expire

Code Block
Code Block
languagesql
# MySQL 5.7 to automatically remove log files after 30 days to prevent running out of drive space. 
# this option name is removed in MySQL 8.2 - use the one below instead
expire_logs_days=30  

# MySQL 8.0 The default binary log expiration period is 2592000 seconds, which equals 30 days (30*24*60*60 seconds). 
binlog_expire_logs_seconds=2592000

Restart mysql services

Restart the mysql service by either opening services, finding mysql and restarting it or by using the Oracle MySQL task bar services control option to stop and start the service.

A restart of the service is needed for configuration changes to take effect.

If this server had been used as a backup previously don`t forget to issue the STOP SLAVE command or restarting the service will fail after adding the log-bin line in your my.ini

Obtain the IP address of your source server as it will be needed during the configuration of the Backup server

You will need to create a replication user if you haven't already done so. You can use the default blbackup user. See Configuring MySQL Users and look for the section on replication user.

Both the source and the server require this user to be created.

Making a Copy of the Primary Database

The backup server needs to have a recent snapshot of the primary database in order to start replication. 

Do not make any changes to the backup database or tables, even if you think it might be a laugh. They must be atomically identical to the source export for the replication to begin.

Attach the Backup to the Source

The source password is stored in clear text in the backup database table so if your systems are not disconnected from cloud access it is strongly recommended to create a replication specific user on the source and use that account for replication access.

Replication only access can be granted to this user prohibiting any other type of source database access if the password and account name were to be accessed.

If you fall under this scenario, please contact BL Support for assistance in creating a replication user account for use in your backups.

Backup Configuration

On the Backup server using MySQL Workbench open a Query window and enter the following :

Default Source_User is blbackup

Code Block
languagesql
STOP SLAVE;
RESET SLAVE;

CHANGE MASTER TO
MASTER_HOST='[SOURCE IP HERE]', 
MASTER_USER='[USER NAME HERE]', 
MASTER_PASSWORD='[USER PASSWORD HERE]';

-- For MySQL 8 use a similar statement with one addition:
CHANGE MASTER TO
MASTER_HOST='[SOURCE IP HERE]', 
MASTER_USER='[USER NAME HERE]', 
MASTERE_PASSWORD='[USER PASSWORD HERE]',
GET_MASTER_PUBLIC_KEY = 1;

Use the lightning bolt icon to process the query

Watch for the result to be a success.

Create A Source Backup

You need to create a source dump of the data on the source/primary database server.

The best way to do this is with a batch/command line process. Once you setup the necessary files you can easily re-use them without going through all the setup parts - just run the commands.

You can get copies of the sample/template files online: 

Possible location is: D:\Bannister Lake\MySqlBackups\source and the file structure will look like this:

Info

📁 source

📄 dump_source_options.cnf
📄 dump_source.bat

Edit Source Dump Config file

You will need a configuration file named 📄 dump_source_options.cnf as follows. (This is a plain text file - saved with the cnf extension.)

Edit it with a text editor to define the correct password for the mysql backup user.

Code Block
languagesql
# These settings control how the mysqldump.exe will run
# https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html
# https://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html
# https://dev.mysql.com/doc/refman/5.6/en/option-files.html

[client]

# This user should have been created for backups and replication
user=blbackup
password=the_secret_password

# these settings are unlikely to need to be changed
max_allowed_packet=100MB
default-character-set=utf8mb4

# these settings are not expected to need changing at all
protocol=tcp

[mysqldump]
quote-names
single-transaction
triggers
routines
quick
source-data=1
all-databases

[mysql]
skip-column-names

Edit Source Dump Command BAT file

Prepare the following command customized to your environment to create a dump file. 

Code Block
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe" --defaults-file=dump_source_options.cnf --host=IP/Name --port=3306 --log-error="C:\temp\db_dump_source_errors.txt" -r "c:\temp\db_source_dump.sql"

The easiest way to do this is to have a batch file that you can run with this command in it: 📄 dump_source.bat

Edit this batch file with a text editor to define the correct

  • mysql server bin folder location

  • host ip address or name (localhost is recommended default value)

  • location for the dump file and error log file

    • this should be a drive with enough space to hold the dump file - it doesn't have to be the c:\ 

    • if you remove the drive and folder from the file name it will save it to the same folder as the batch file is in

Before running the source dump

Run this sql command on the primary server database by using Workbench or even the MySQL command line.

Code Block
languagesql
RESET MASTER; 

-- NOTE: requires the RELOAD privilege

To start MySQL on the command line open a command prompt and enter: (you can do this from the backup even)

Code Block
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" --host=sourceIP --port=3306 --user=blbackup --password

Then you'll see the mysql>  prompt

Code Block
languagesql
mysql>

enter the RESET SOURCE statement and press enter to execute.

Code Block
languagesql
mysql> RESET MASTER; 

Run the source dump bat file

Now Run the dump batch file - double click or use a command window:

  1. open a command prompt (type cmd in the start menu to find it) 

  2. change your drive and directory to be the one your source dump batch file is in

  3. type dump_source.bat and press enter

  4. if everything is setup correctly your batch file will run and create the source dump file

Import Dump

If you haven't already done so based on the instructions in the step before creating the source dump - stop and reset the backup now.

Execute the following command in a MySQL query on the backup:

Code Block
languagesql
STOP SLAVE;
RESET SLAVE;

Copy the new data file onto your backup server and import the data.

Run the following command customized to your environment to import the dump file.

Code Block
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" --user=root --password=your_password --host=localhost --port=3306 < "c:\temp\db_source_dump.sql" > "c:\temp\source_dump_import_log.txt"

The easiest way to do this is to have a batch file that you can run with this command in it: 📄 import_source.bat

Edit this batch file with a text editor to define the correct

  • mysql server bin folder location

  • password

  • host name/ip

  • import file location  (copied from source server)

  • import result log file (a text file)

Run this batch file using a command prompt window like above or just double-click the batch file to run it. 

Start Backup Processing

Now that the Source data has been restored onto the backup server, it is time to start the backup process. Execute the following command in a MySQL query on the backup:

Code Block
languagesql
START SLAVE;

Verifying That Your Backup Is Running

Verify the Backup server is connecting to the source by entering the following command in the query window on the backup server

Code Block
SHOW SLAVE STATUS;

The status returned will either be "Waiting for Source Event" or "Consuming Source Binary Logs". Both of these indicate successful setup of backup replication however be sure to then also scroll through the columns and check for Last_SQL_Error and Last_IO_Error and make sure both these are blank (i.e. no error). IF there is an error - then the replication is not actively working.

Replication Status Monitoring

There is an automatic check of the replication status that displays in Flow in the Agent Status widget along with the other automated reader and data management apps. It will also indicate if these error messages have been triggered. Note that this does require that the necessary configuration is done on the primary and backup servers. For more info see: Replication and Backup Status Monitor

Note

Do not sign into flow on the backup server as this will create sign in audit records that will make the backup server be out of synch with the source server.

Congratulations you have setup your backup server.

Limiting Replication To Certain Databases or Tables

If you want to limit the database or tables that are replicated use the replicate_wild_table_do setting in the BACKUP my.ini by defining database.table combinations. Wild cards are supported using %.

The following is an example of filtering on only the elector municipal database, grabbing only the data tables.

Code Block
replicate-wild-do-table=elector_municipal.rme%

To limit replication to a certain database use 

Code Block
replicate-do-db=superticker

Table of Contents
minLevel1
maxLevel6
outlinefalse
typelist
printablefalse