Skip to content

Commit

Permalink
Added more details, added missing steps for getting gtid, and grants.
Browse files Browse the repository at this point in the history
  • Loading branch information
krishdpi authored Aug 12, 2024
1 parent 2009666 commit ded8311
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions docs/High Availability, DR/Setup Global Replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ In a real world scenario, the Primary service will contain data which will need
!!! Note
Depending on the size of your databases, backing up a service can take substantial time. Creating a new backup is not necessary if you already have an existing full backup of your service.

1\. Use the following API to list backups associated with the Primary service. Replcate {id} with the id of the Primary service.
1\. Use the following API to list backups associated with the Primary service. Replace {id} with the database id of the Primary service.

```bash
curl --location --request GET https://api.skysql.com/skybackup/v1/backups?service_id={id} \
Expand All @@ -77,43 +77,67 @@ OR

```bash
curl --location --request POST https://api.skysql.com/skybackup/v1/backups/schedules \
--header "X-API-Key: ${SKYSQL_API_KEY}" --header "Content-type: application/json" \
--header "X-API-Key: ${API_KEY}" --header "Content-type: application/json" \
--data '{
"backup_type": "full",
"schedule": "once",
"service_id": "{id}"
}'
```

2\. Each backup also has a unique identified. Make note of the identifier shown in the API response. Now use the following API to restore the backup to the Secondary service. Please note that restoring the backup on a SkySQL service will stop the service if it is running and will wipe out all existing data. Replcate {backup-id} with the backup id that you want to restore and {service-id} with the id of the Secondary service.
2\. Each backup also has a unique identifier. Make note of the identifier shown in the API response. Now use the following API to restore the backup to the Secondary service. Please note that restoring the backup on a SkySQL service will stop the service if it is running and will wipe out all existing data. Replace {backup-id} with the backup id that you want to restore and {service-id} with the id of the Secondary service.

```bash
curl --location --request POST https://api.skysql.com/skybackup/v1/restores \
--header "X-API-Key: ${SKYSQL_API_KEY}" --header "Content-type: application/json" \
--header "X-API-Key: ${API_KEY}" --header "Content-type: application/json" \
--data '{
"id": "{backup-id}}",
"service_id": "{service-id}"
}'
```

3\. Once the restore is complete, the default username and password associated with the Secondary service will not work. You will have to use Primary service's username and password to connect to the Secondary service.
3\. IMPORTANT NOTE: Once the restore is complete, the default username and password displayed in "connect" window of the Secondary service will not work. Restore overwrites this information with the username and password of the Primary service. Hence, you will have to use Primary service's username and password to connect to the Secondary service.
### **Step 4: Set up Replication between the Primary and the Secondary**
1\. Since we want to set up replication between the two SkySQL services, the Secondary service should be able to connect to the Primary service. Add the Outbound IP address of the Secondary service to the Allowlist of the Primary service. (TODO - Add APIs for retrieving outbound IP and adding it to allowlist)
1\. Since we want to set up replication between the two SkySQL services, the Secondary service should be able to connect to the Primary service. Add the Outbound IP address of the Secondary service to the Allowlist of the Primary service. Outbound IP can be obtained from "Service Details" page in the SkySQL portal. Please add this IP to the allow list of Primary service in the portal.
2\. Next, obtain the GTID position from which to start the replication and configure it on the Secondary service by calling the following stored procedures. Replace 'host' and 'port' with the Primary service's hostname and port. Replace 'gtid' with the GTID position from which to start replication. Use true/false for whether to use SSL.
2\. Next, obtain the GTID position from which to start the replication by using the following API. Please replace {service_id} with the service id of the primary service.
```bash
curl --location --request GET "https://api.skysql.com/skybackup/v1/backups?service_id={service_id}" --header "X-API-Key: ${API_KEY}" --header "Content-type: application/json" | jq
```
Make note of the gtid position ("binlog_gtid_position") in the API response output.
3\. Now configure the Secondary service by calling the following stored procedure. Replace 'host' and 'port' with the Primary service's hostname and port. Replace 'gtid' with the GTID position obtained from the previous setp. Use true/false for whether to use SSL.

```bash
CALL sky.gtid_status();
CALL sky.change_external_primary_gtid(host,port,gtid,use_ssl_encryption);
```
Alternatively, the above command can be used with "binlog_file" and "binlog_position" output from step #2 above.

```bash
CALL sky.change_external_primary('dbpwfxxxx.sysp0000.db1.skysql.com', 3306, 'mariadb-bin.000007', xxxxx, true);
```


If successfull, you should see an output similar to below.

```bash
+-----------------------------------------------------------------------------------------------------------------------------------------+
| Run_this_grant_on_your_external_primary |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO 'skysql_replication_dbpwxxxxx'@'174.x.x.x' IDENTIFIED BY 'xxxxxxxxxx'; |
+-----------------------------------------------------------------------------------------------------------------------------------------+
```

Please copy the "GRANT REPLICATION..." command from the output and run in the primary service.

3\. Start replication and check status on the Secondary service using the following procedures:
4\. Start replication and check status on the Secondary service using the following procedures:

```bash
CALL sky.start_replication();
CALL sky.replication_status();
```

4\. Once the replication is setup, verify the status of the new database service in the SkySQL console. Ensure that the service is replicating for your use case for global replication.
5\. Once the replication is setup, verify the status of the new database service in the SkySQL console. Ensure that the service is replicating for your use case for global replication.

0 comments on commit ded8311

Please sign in to comment.