Define the Backup Policy when deploying MySQL Database Service in OCI

Let’s continue the discovery of the MySQL Database Resource when deploying on Oracle Cloud Infrastructure using Terraform.

Last week, we saw how to create custom configurations and define user variables. Today we will see how we can define a backup policy and a maintenance window.

Backup Policy

In the oci_mysql_mysql_db_system resource, we will add a new section called backup_policy like this:

backup_policy {
       is_enabled        = "true"
       retention_in_days = "3"
       window_start_time = "01:00-00:00"
       freeform_tags = {"backup_defined_by"="Terraform"}
       pitr_policy {
            is_enabled = "true"

This part of code (you can see in a working Terraform architecture sample), enables backup, sets the retention days to 3. It also defines the starting time and set a free form tag.

In this section, we can include another section about pitr_policy to enable or disable point-in-time recovery capabilities for our MySQL instance.

All the settings are documented in Terraform’s registry: oci_mysql_mysql_backup.

This is what we can see in Oracle Cloud’s console

Maintenance Window

In the oci_mysql_mysql_db_system resource, we can also add a section to specify the maintenance window of the instance.

During maintenance, Oracle patches the underlying operating system, update versions (-u*) of the MySQL Server, and any underlying hardware. For more details check the manual.

This is how we define the maintenance window in our Terraform code:

 maintenance {
      window_start_time = "sun 01:00"

In Oracle Cloud’s console, we can easily see it:


Once again, you can see that it’s very easy to deploy instances of MySQL DBaaS in OCI using Terraform.

We started with the deployment of an instance in my first articles on the MySQL and Terraform database service, now we’ll go into a little more detail and we can see that there are multiple aspects of the service that we can easily define using the OCI API.

You can find the full code example of the MySQL Database Service resource here.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

As MySQL Community Manager, I am an employee of Oracle and the views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

You can find articles I wrote on Oracle’s blog.