You can use point-in-time-recovery (PITR) to restore your primary Cloud SQL
instances whether the instance is live, or is deleted. PITR lets you restore
the instance to a specific point-in-time. A point-in-time recovery always creates
a new instance; you cannot perform a PITR to an existing instance.

Cloud SQL provides the following options to restore your instance
using PITR:

- [Perform a PITR on a live instance](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform-pitr)
- [Perform a PITR using the backup vault](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#backup-vault-pitr)

<!-- -->

- [Perform a PITR on an unavailable instance](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform-pitr-unavailable-instance)

<!-- -->

- [Perform a PITR on a deleted instance](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform-pitr-deleted-instance)

<!-- -->

- [Perform a PITR using binary log event positions](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform_pitr_by_using_binary_log_positions)

For performing a PITR on an unavailable or deleted instance, you'll need to
find the
[latest and earliest recovery time](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#get-the-latest-recovery-time).

## Perform a PITR by a using timestamp

Using a timestamp is the recommended approach for performing
a PITR.
Cloud SQL uses the `mysqlbinlog` utility to restore
instances up to a specific time. For more information about the `mysqlbinlog`
utility, see the [MySQL reference documentation](https://dev.mysql.com/doc/refman/5.7/en/mysqlbinlog.html#option_mysqlbinlog_stop-datetime).

To complete the following task, you must have the following:

- Binary logging and backups enabled for the instance, with continuous binary logs since the last backup before the event from which you want to recover. For more information, see [Enable binary logging](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/configure-pitr.md.txt#enablingpitr).
- A timestamp to define the recovery point. The events that occur at and after this timestamp aren't reflected in the new instance.

### Console

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Open the more actions menu ![More actions icon.](https://docs.cloud.google.com/static/sql/images/more-actions.png) for the instance you want to recover and click **Create clone**.
3. Optionally, on the **Create a clone** page, update the ID of the new clone.
4. Select **Clone from an earlier point in time**.
5. Enter a PITR time.
6. Click **Create clone**.

### gcloud

Create a clone using PITR.

Replace the following:

- <var translate="no">SOURCE_INSTANCE_NAME</var> - Name of the instance you're restoring from.
- <var translate="no">NEW_INSTANCE_NAME</var> - Name for the clone.
- <var translate="no">TIMESTAMP</var> - UTC timezone for the source instance in RFC 3339 format. For example, 2012-11-15T16:19:00.094Z.

```bash
gcloud sql instances clone SOURCE_INSTANCE_NAME \
NEW_INSTANCE_NAME \
--point-in-time 'TIMESTAMP'
```

### REST v1


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: The project ID
- <var translate="no">target-instance-id</var>: The target instance ID
- <var translate="no">source-instance-id</var>: The source instance ID
- <var translate="no">restore-timestamp</var> The point-in-time to restore up to


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "kind": "sql#cloneContext",
    "destinationInstanceName": "target-instance-id",
    "pointInTime": "restore-timestamp"
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CREATE",
  "name": "operation-id",
  "targetId": "target-instance-id",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
```

### REST v1beta4


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: The project ID
- <var translate="no">target-instance-id</var>: The target instance ID
- <var translate="no">source-instance-id</var>: The source instance ID
- <var translate="no">restore-timestamp</var> The point-in-time to restore up to


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "kind": "sql#cloneContext",
    "destinationInstanceName": "target-instance-id",
    "pointInTime": "restore-timestamp"
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CREATE",
  "name": "operation-id",
  "targetId": "target-instance-id",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
```

## Perform a PITR using the backup vault

If your Cloud SQL instance is enabled to use
[enhanced backups](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/backups.md.txt#enhanced-backups),
then you can perform point-in-time-recovery for your instance using the
backup vault.

> [!NOTE]
> **Note:** If your backup vault is in a different region than your instance, then you can perform PITR only to a new instance in the same region as the source instance. For more information, see [Cross-region backups](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/backup-options.md.txt#eb-cross-region).

> [!NOTE]
> **Note:** If you're using Terraform or the Cloud SQL API to perform PITR and your instance uses enhanced backups, then Cloud SQL uses the PITR settings from the instance's associated backup plan.

### Console

1.

   In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)

   <br />

2. Open the more actions menu ![More actions icon.](https://docs.cloud.google.com/static/sql/images/more-actions.png) for the instance you
   want to recover and click **Create clone**.

3. Select **Clone from an earlier point in time**.

4. Enter a PITR time.

5. Click **Create clone**.

### gcloud

To perform a PITR on an instance from the backup vault, you'll need to find the
`data-source` for the backup that is nearest to the time you want to perform
the PITR. To find the backup, see
[List all the backups in the backup vault for an instance](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/backing-up#list-backup-vault). Once you've identified the backup, run the following command to perform the PITR:

    gcloud sql instances point-in-time-restore DATA_SOURCE \
        TARGET_INSTANCE_NAME \
        'PITR_TIMESTAMP' \
        --project=TARGET_PROJECT \
        --region=REGION

Replace the following:

- `DATA_SOURCE`: the path of the `data-source` for the source instance that is closest to the PITR timestamp you want to recover to.
- `TARGET_INSTANCE_NAME`: the name for the new instance that is created by the PITR operation.
- `PITR_TIMESTAMP`: the UTC timestamp for the source instance PITR log you want to restore your instance to, in [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) format. For example, 2025-11-15T16:19:00.094Z.
- `TARGET_PROJECT`: the project ID for the new instance.
- `REGION`: the region of the target instance. This field is required if the data source of the source instance is located in a multi-region or in a different region than the source instance. The target instance region must be the same as the region of the source instance.

### REST v1

To perform point-in-time recovery using a data source from the backup vault, use the
[`instances.pointInTimeRestore`](https://docs.cloud.google.com/sql/docs/mysql/admin-api/rest/v1/instances/pointInTimeRestore.md.txt) method with a POST request.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the ID of the project where you want to create the new instance.
- <var translate="no">DATASOURCE</var>: the Backup and DR data source you want the service to use for the point-in-time restore operation.
- <var translate="no">PITR_TIMESTAMP</var>: the UTC timestamp for the source instance PITR log you want to restore your instance to, in [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) format. For example, 2012-11-15T16:19:00.094Z.
- <var translate="no">TARGET_INSTANCE_NAME</var>: the name of the instance created by the PITR operation.
- <var translate="no">REGION</var>: the region of the target instance. This field is required if the data source of source instance is located in a multi-region. The target instance region must be the same as the region of the source instance.


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID:pointInTimeRestore
```


Request JSON body:

```
{
  "datasource": "DATASOURCE",
  "pointInTime": "PITR_TIMESTAMP",
  "targetInstanceName": "TARGET_INSTANCE_NAME",
  "region": "REGION"
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID:pointInTimeRestore"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID:pointInTimeRestore" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_NAME",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CLONE",
  "name": "OPERATION_ID",
  "targetId": "TARGET_INSTANCE_NAME",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

<br />

### REST v1beta4

To perform point-in-time recovery using a data source from the backup vault, use the
[`instances.pointInTimeRestore`](https://docs.cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances/pointInTimeRestore.md.txt) method with a POST request.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the ID of the project where you want to create the new instance.
- <var translate="no">DATASOURCE</var>: the Backup and DR data source you want the service to use for the point-in-time restore operation.
- <var translate="no">PITR_TIMESTAMP</var>: the UTC timestamp for the source instance PITR log you want to restore your instance to, in [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) format. For example, 2012-11-15T16:19:00.094Z.
- <var translate="no">TARGET_INSTANCE_NAME</var>: the name of the instance created by the PITR operation.
- <var translate="no">REGION</var>: the region of the target instance. This field is required if the data source of source instance is located in a multi-region. The target instance region must be the same as the region of the source instance.


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID:pointInTimeRestore
```


Request JSON body:

```
{
  "datasource": "DATASOURCE",
  "pointInTime": "PITR_TIMESTAMP",
  "targetInstanceName": "TARGET_INSTANCE_NAME",
  "region": "REGION"
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID:pointInTimeRestore"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID:pointInTimeRestore" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_NAME",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CLONE",
  "name": "OPERATION_ID",
  "targetId": "TARGET_INSTANCE_NAME",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID"
}
```

<br />

### Perform a cross-project PITR

With enhanced backups, you can restore a Cloud SQL instance to a
project other than the one where either the source instance or backup vault is
located.

Cross-project PITR is supported only through the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) and REST APIs.

To perform a cross-project PITR, do one of the following:

- If you're using the gcloud CLI, set the `--project` flag to the
  project where you want to create the target instance.

- If you're using REST APIs, set the `PROJECT_ID` field to the project where
  you want to create the target instance.

## Perform PITR on an unavailable instance

### Console

You might want to recover an
[instance that isn't available](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#pitr-instance-not-available)
to a different zone because of the following reasons:

- The zone in which the instance is configured isn't accessible. This instance has a `FAILED` state.
- The instance is undergoing maintenance. This instance has a `MAINTENANCE` state.

To recover an unavailable instance, complete the following steps:

1. In the Google Cloud console, go to the **Cloud SQL Instances** page.

   [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)
2. Find the row of the instance to clone.
3. In the **Actions** column, click the **More Actions** menu.
4. Click **Create clone**.
5. On the **Create a clone** page, complete the following actions:
   1. In the **Instance ID** field, update the instance ID, if needed.
   2. Click **Clone from an earlier point in time**.
   3. In the **Point in time** field, select a date and time from which you want to clone data. This recovers the state of the instance from that point in time.
   4. Click **Create clone**.
6. While the clone initializes, you're returned to the instance listing page.

### gcloud

You might want to recover an
[instance that isn't available](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#pitr-instance-not-available)
to a different zone because the zone in which the instance is configured
isn't accessible.

```bash
gcloud sql instances clone SOURCE_INSTANCE_NAME TARGET_INSTANCE_NAME \
--point-in-time DATE_AND_TIME_STAMP \
--preferred-zone ZONE_NAME \
--preferred-secondary-zone SECONDARY_ZONE_NAME
```

The user or service account that's running the `gcloud sql instances clone`
command must have the `cloudsql.instances.clone` and `cloudsql.instances.create` permissions. For more
information about required permissions to run [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) commands, see
[Cloud SQL permissions](https://docs.cloud.google.com/sql/docs/mysql/iam-permissions.md.txt).

### REST v1

You might want to recover an [instance that isn't available](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#pitr-instance-not-available) to a different zone because the zone in which the instance is configured isn't accessible.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the project ID
- <var translate="no">SOURCE_INSTANCE_ID</var>: the source instance ID
- <var translate="no">TARGET_INSTANCE_ID</var>: the target instance ID


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/SOURCE_INSTANCE_NAME/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "destinationInstanceName": "TARGET_INSTANCE_ID"
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/SOURCE_INSTANCE_NAME/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/SOURCE_INSTANCE_NAME/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_NAME",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CLONE",
  "name": "OPERATION_ID",
  "targetId": "TARGET_INSTANCE_NAME",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID",
  "instanceUid": "INSTANCE_ID"
}
```

The user or service account that's using the [`instances.clone`](https://docs.cloud.google.com/sql/docs/mysql/admin-api/rest/v1/instances/clone.md.txt) API method must have the `cloudsql.instances.clone` and `cloudsql.instances.create` permissions. For more information about required permissions to use API methods, see [Cloud SQL permissions](https://docs.cloud.google.com/sql/docs/mysql/iam-permissions.md.txt).

### REST v1beta4

You might want to recover an [instance that isn't available](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#pitr-instance-not-available) to a different zone because the zone in which the instance is configured isn't accessible.


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the project ID
- <var translate="no">SOURCE_INSTANCE_ID</var>: the source instance ID
- <var translate="no">TARGET_INSTANCE_ID</var>: the target instance ID


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/SOURCE_INSTANCE_NAME/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "destinationInstanceName": "TARGET_INSTANCE_ID"
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/SOURCE_INSTANCE_NAME/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/SOURCE_INSTANCE_NAME/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_NAME",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CLONE",
  "name": "OPERATION_ID",
  "targetId": "TARGET_INSTANCE_ID",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",
  "targetProject": "PROJECT_ID",
  "instanceUid": "INSTANCE_ID"
}
```

The user or service account that's using the [`instances.clone`](https://docs.cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances/clone.md.txt) API method must have the `cloudsql.instances.clone` and `cloudsql.instances.create` permissions. For more information about required permissions to use API methods, see [Cloud SQL permissions](https://docs.cloud.google.com/sql/docs/mysql/iam-permissions.md.txt).

If you try to create a PITR clone at a time after the latest recoverable time,
then the following error message is given:

```bash
The timestamp for point-in-time recovery is after the latest recovery time of
Timestamp of latest recovery time. Clone the instance with a time
that's earlier than this recovery time.
```

## Perform PITR on a deleted instance

To use PITR to restore a deleted instance, you'll need:

- the PITR timestamp (`timestamp`) you want to restore your instance to
- the target instance name
- the time the source instance was deleted (`source-instance-deletion-time`)

You can use
PITR on a deleted instance using gcloud CLI or the Cloud SQL
API only. For more information, see
[Restore a deleted instance using a PITR](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#deleted-instance).

### gcloud

### Standard backup

**Find your PITR window**

To find your deleted instance's PITR window, get the
[earliest and latest recovery time](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#get-the-latest-recovery-time)
for your instance. You can select anytime timestamp in this window to
perform a PITR.

**Find source instance deletion**

The `source-instance-deletion-time` and `log-retention-days` for the
deleted instance are stored with the retained backups for your instance after
deletion. To find a list of all available backups for your deleted instance, see
[List retained backups](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/manage-retained-backups#gcloud_1).

Once you identify the backup you want to use, use the
[gcloud sql backups describe](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/describe)
command to get the `source-instance-deletion-time`.

**Restore using a PITR**

To restore your deleted instance using a PITR, run the following command:

    gcloud sql instances clone SOURCE_INSTANCE_NAME \
    NEW_INSTANCE_NAME \
    --point-in-time='PITR_TIMESTAMP' \
    --source-instance-deletion-time=SOURCE_INSTANCE_DELETION_TIMESTAMP

Replace the following:

- `SOURCE_INSTANCE_NAME`: the name of the source instance that you want to restore.
- `NEW_INSTANCE_NAME`: the name of the new instance.
- `PITR_TIMESTAMP`: the UTC timestamp for the source instance PITR log you want to restore your instance to, in [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) format. For example, 2012-11-15T16:19:00.094Z.
- `SOURCE_INSTANCE_DELETION_TIMESTAMP`: the UTC timestamp for the time that the source instance was deleted, in RFC 3339 format. For example, 2012-11-15T16:19:00.094Z.

### Enhanced backup

**Find your PITR window**

To find your deleted instance's PITR window, get the
[earliest and latest recovery time](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#get-the-latest-recovery-time)
for your instance. You can select anytime timestamp in this window to
perform a PITR.

**Find the data source**

The data source for the
deleted instance are stored with the retained backups for your instance after
deletion. To find these values for your deleted instance, see
[List all the backups in the backup vault for your instance](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/manage-enhanced-backups.md.txt#list-backups).

**Restore using a PITR**

To restore your deleted instance using a PITR, run the following command:

    gcloud sql instances point-in-time-restore DATA_SOURCE \
        TARGET_INSTANCE_NAME \
        'PITR_TIMESTAMP' \
        --project=TARGET_PROJECT \
        --region=REGION

Replace the following:

- `DATA_SOURCE`: the path of the `data-source` for the backup that is closest to the PITR timestamp you want to recover to.
- `TARGET_INSTANCE_NAME`: the name for the new instance that is created by the PITR operation.
- `PITR_TIMESTAMP`: the UTC timestamp for the source instance PITR log you want to restore your instance to, in [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) format. For example, 2025-11-15T16:19:00.094Z.
- `TARGET_PROJECT`: the project ID for the new instance.
- `REGION`: the region of the target instance. This field is required if the data source of the source instance is located in a multi-region. The target instance region must be the same as the region of the source instance.

### REST v1

**Find your PITR window**

To find your deleted instance's PITR window, get the
[earliest and latest recovery time](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#get-the-latest-recovery-time)
for your instance. You can select anytime timestamp in this window to
perform a PITR.

**Find source instance deletion time and log retention days**

The `source-instance-deletion-time` and `log-retention-days` for the
deleted instance are stored with the retained backups for your instance after
deletion. To find these values for your deleted instance, see
[List retained backups](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/manage-retained-backups#rest-v1).

**Restore using a PITR**


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: the project ID
- <var translate="no">target-instance-id</var>: the target instance ID
- <var translate="no">source-instance-id</var>: the source instance ID
- <var translate="no">source-instance-deletion-time</var>: the deletion time of the source instance
- <var translate="no">restore-timestamp</var> the point-in-time which you want to restore the instance


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "kind": "sql#cloneContext",
    "destinationInstanceName": "target-instance-id",
    "sourceInstanceDeletionTime: "source-instance-deletion-time",
    "pointInTime": "restore-timestamp"
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CLONE",
  "name": "operation-id",
  "targetId": "target-instance-id",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
```

<br />

### REST v1beta4

**Find your PITR window**

To find your deleted instance's PITR window, get the
[earliest and latest recovery time](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#get-the-latest-recovery-time)
for your instance. You can select anytime timestamp in this window to
perform PITR.

**Find source instance deletion time and log retention days**

The `source-instance-deletion-time` and `log-retention-days` for the
deleted instance are stored with the retained backups for your instance after
deletion. To find these values for your deleted instance, see
[List retained backups](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/manage-retained-backups#rest-v1beta4).

**Restore using PITR**


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: the project ID
- <var translate="no">target-instance-id</var>: the target instance ID
- <var translate="no">source-instance-id</var>: the source instance ID
- <var translate="no">source-instance-deletion-time</var>: the deletion time of the source instance
- <var translate="no">restore-timestamp</var> the point-in-time which you want to restore the instance


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "kind": "sql#cloneContext",
    "destinationInstanceName": "target-instance-id",
    "sourceInstanceDeletionTime: "source-instance-deletion-time",
    "pointInTime": "restore-timestamp"
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CREATE",
  "name": "operation-id",
  "targetId": "target-instance-id",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
```

<br />

## Perform a PITR by using binary log positions

While we recommend that you perform PITR using timestamps, as
described in [Perform PITR by using a timestamp](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform-pitr), you can also
perform PITR by providing a specific binary log position, or event position, in
a binary log file.

For more information about PITR using binary log positions, see
[PITR Using the Binary Log](https://dev.mysql.com/doc/refman/8.0/en/point-in-time-recovery-positions.html).

### Before you begin

Before completing this task, you must have:

- Binary logging and backups enabled for the instance, with continuous binary
  logs since the last backup before the event you want to recover from.
  For more information, see [Enable binary logging](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/configure-pitr.md.txt#enablingpitr).

- The binary logs must be available on disk for you to
  browse them for events. To check the retention length of your binary logs on
  disk, see [Set transaction log retention](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/configure-pitr.md.txt#set-retention).
  For more information, see [Log retention period](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#log-retention-period).
  You can't browse binary logs that are stored in Cloud Storage with the
  `mysqlbinlog` utility.

- A binary log filename and the position of the event you want to
  recover from (that event and all events that came
  after it aren't reflected in the new instance).
  For more information, see [Identify the binary log position](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#coordinates).

  After identifying the binary log filename and position,
  [perform the PITR using binary log event positions](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform-pitr-binlog).

### Identify the recovery position

1. Use the MySQL client to connect to the instance you want to restore to.

   To do so, use the Cloud Shell or your local client machine.
   For more information, see
   [Connection options for external applications](https://docs.cloud.google.com/sql/docs/mysql/external-connection-methods).
2. Show the binary log files for the instance:

   ```sql
   SHOW BINARY LOGS;
   ```
3. Display the first 100 events in the most recent binary log file:

   ```sql
   SHOW BINLOG EVENTS IN '<BINARY_LOG_FILE>' LIMIT 100;
   ```

   You can adjust the number of rows to show, but don't show all of
   the events in the file until you know how large the file is. Displaying a
   large number of events can affect system performance.
4. If the event you're looking for isn't displayed, use the last position
   displayed as the starting point to search the next set of events:

   ```sql
   SHOW BINLOG EVENTS IN '<BINARY_LOG_FILE>' FROM <POSITION> LIMIT 100;
   ```
5. When you find the event that marks the point in time you want to restore up
   to, record the position (shown as `Pos`) and the name of the binary log file.

   The binary log filename and the position are the values you use for the
   PITR.

The following is a sample output from the `SHOW BINLOG EVENTS` command:

```
+---+---+---+---+---+---+
| Log_name         | Pos | Event_type  | Server_id | End_log_pos | Info                                                |
+---+---+---+---+---+---+
| mysql-bin.000011 |   4 | Format_desc |  88955285 |         120 | Server ver: 5.6.30-log, Binlog ver: 4               |
| mysql-bin.000011 | 120 | Query       |  88955285 |         211 | create database db1                                 |
| mysql-bin.000011 | 211 | Query       |  88955285 |         310 | use `db1`; CREATE TABLE t (c CHAR(20))              |
| mysql-bin.000011 | 310 | Query       |  88955285 |         381 | BEGIN                                               |
| mysql-bin.000011 | 381 | Table_map   |  88955285 |         426 | table_id: 18 (db1.t)                                |
| mysql-bin.000011 | 310 | Query       |  88955285 |         381 | BEGIN                                               |

| mysql-bin.000011 | 426 | Write_rows  |  88955285 |         464 | table_id: 18 flags: STMT_END_F                      |
| mysql-bin.000011 | 464 | Xid         |  88955285 |         495 | COMMIT /* xid=56 */                                 |
| mysql-bin.000011 | 495 | Query       |  88955285 |         566 | BEGIN                                               |
| mysql-bin.000011 | 566 | Table_map   |  88955285 |         611 | table_id: 18 (db1.t)                                |
| mysql-bin.000011 | 611 | Write_rows  |  88955285 |         649 | table_id: 18 flags: STMT_END_F                      |
| mysql-bin.000011 | 649 | Xid         |  88955285 |         680 | COMMIT /* xid=57 */                                 |
| mysql-bin.000011 | 680 | Query       |  88955285 |         751 | BEGIN                                               |
| mysql-bin.000011 | 751 | Table_map   |  88955285 |         796 | table_id: 18 (db1.t)                                |
| mysql-bin.000011 | 796 | Write_rows  |  88955285 |         834 | table_id: 18 flags: STMT_END_F                      |
| mysql-bin.000011 | 834 | Xid         |  88955285 |         865 | COMMIT /* xid=58 */                                 |
| mysql-bin.000011 | 865 | Query       |  88955285 |         977 | use `db1`; DROP TABLE `t` /* generated by server */ |
+---+---+---+---+---+---+
16 rows in set (0.04 sec)

```

To restore up to the `DROP TABLE` statement, bolded in the previous
sample, you would use `865` in `mysql-bin.000011` as the
recovery position. The `DROP TABLE` statement and all operations after
it are not reflected in the new instance.

> [!NOTE]
> **Note:** MySQL provides a more sophisticated tool for examining binary logs called `mysqlbinlog`. It's available with the MySQL Server software. If you have the MySQL Server installed, you can use it to determine the recovery position you want to use. For more information, see the [MySQL documentation for mysqlbinlog](https://docs.cloud.google.com/https://dev.mysql.com/doc/refman/8.4/en/mysqlbinlog).

### Perform PITR using binary log event positions

### gcloud

Use the [`gcloud sql instances clone`](https://docs.cloud.google.com/sdk/gcloud/reference/sql/instances/clone) command with the
`--bin-log-file-name` and `--bin-log-position`
flags.

1. Create the new instance using the binary log filename and recovery
   position.

   Replace the following:
   - <var translate="no">SOURCE_INSTANCE_NAME</var>: Name of the instance you're restoring from.
   - <var translate="no">NEW_INSTANCE_NAME</var>: Name for the clone.
   - <var translate="no">BINLOG_FILE_NAME</var>: Name for the binary log, such as `mysql-bin.187288`.
   - <var translate="no">POSITION</var>: The position in the binary log to restore up to, such as `50001356`.

   ```bash
   gcloud sql instances clone SOURCE_INSTANCE_NAME \
   NEW_INSTANCE_NAME \
   --bin-log-file-name="BINLOG_FILE_NAME" \
   --bin-log-position=POSITION
   ```

   For example, a `gcloud sql instances clone` command might look
   similar to the following:

   ```bash
   gcloud sql instances clone instance1 \
   instance1-clone \
   --bin-log-file-name=mysql-bin.0000031 \
   --bin-log-position=107
   ```
2. Use the operation ID returned from the `clone` command to check the status of the restore operation.

   ```
   gcloud sql operations describe OPERATION_ID
   ```

   When the operation is in progress, a state of `RUNNING` is
   returned. When the operation is complete, a state of `DONE`
   is returned.

### REST v1

Create the new instance using the binary log filename and recovery
position you have identified:


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: The project ID
- <var translate="no">target-instance-id</var>: The target instance ID
- <var translate="no">source-instance-id</var>: The source instance ID
- <var translate="no">binary-log-file-name</var> The name of the binary log file
- <var translate="no">binary-log-position</var> The position within the binary log file


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "kind": "sql#cloneContext",
    "destinationInstanceName": "target-instance-id",
    "binLogCoordinates":
    {
      "kind": "sql#binLogCoordinates",
      "binLogFileName": "binary-log-file-name",
      "binLogPosition": "binary-log-position"
    }
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CREATE",
  "name": "operation-id",
  "targetId": "target-instance-id",
  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
```

### REST v1beta4

Create the new instance using the binary log filename and
recovery position you have identified:


Before using any of the request data,
make the following replacements:

- <var translate="no">project-id</var>: The project ID
- <var translate="no">target-instance-id</var>: The target instance ID
- <var translate="no">source-instance-id</var>: The source instance ID
- <var translate="no">binary-log-file-name</var> The name of the binary log file
- <var translate="no">binary-log-position</var> The position within the binary log file


HTTP method and URL:

```
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone
```


Request JSON body:

```
{
  "cloneContext":
  {
    "kind": "sql#cloneContext",
    "destinationInstanceName": "target-instance-id",
    "binLogCoordinates":
    {
      "kind": "sql#binLogCoordinates",
      "binLogFileName": "binary-log-file-name",
      "binLogPosition": "binary-log-position"
    }
  }
}
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/source-instance-id/clone" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

#### Response

```
{
  "kind": "sql#operation",
  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id",
  "status": "PENDING",
  "user": "user@example.com",
  "insertTime": "2020-01-21T22:43:37.981Z",
  "operationType": "CREATE",
  "name": "operation-id",
  "targetId": "target-instance-id",
  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",
  "targetProject": "project-id"
}
```

## Get the earliest and latest recovery time

For an available instance, you can perform a PITR to any timestamp in the
instance's PITR window. The PITR window starts a the earliest recovery time
and ends at the latest recovery time. If the
instance is unavailable and the instance logs are stored in [Cloud Storage](https://docs.cloud.google.com/storage/docs.md.txt),
or the instance was deleted and had
[PITR retention enabled](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/restore.md.txt#deleted-instance),
then you can retrieve the earliest and latest recovery time, and perform the
PITR to any timestamp in that window.
In all cases, you can [restore the instance to a different primary or secondary zone](https://docs.cloud.google.com/sql/docs/mysql/backup-recovery/pitr.md.txt#perform-PITR-unavailable-instance)
by providing values for the preferred zones.

### gcloud

**Unavailable instance**

To get the earliest and latest time to which you can recover a
Cloud SQL instance that's not available, run the following command:

    gcloud sql instances get-latest-recovery-time INSTANCE_NAME

Replace the following:

- `INSTANCE_NAME`: the name of the instance you want to find the latest recovery time for.

**Deleted instance**

To get the earliest and latest time to which you can recover a
Cloud SQL deleted instance to, run the following command:

    gcloud sql instances get-latest-recovery-time INSTANCE_NAME \
        --source-instance-deletion-time='SOURCE_INSTANCE_DELETION_TIMESTAMP'

Replace the following:

- `INSTANCE_NAME`: the name of the instance you want to find the latest recovery time for.
- `SOURCE_INSTANCE_DELETION_TIMESTAMP`: the UTC timestamp for the time that the source instance was deleted, in RFC 3339 format. For example, 2012-11-15T16:19:00.094Z.

### REST v1

**Unavailable instance**


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the project ID
- <var translate="no">INSTANCE_NAME</var>: the name of the instance for which you're querying for the latest recovery time


HTTP method and URL:

```
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#getLatestRecoveryTime",
  "earliestRecoveryTime": "2023-06-10T17:23:59.648821586Z",
  "latestRecoveryTime": "2023-06-20T17:23:59.648821586Z"
}
```

<br />

**Deleted instance**


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the project ID
- <var translate="no">INSTANCE_NAME</var>: the name of the source instance for which you're querying for the latest recovery time
- <var translate="no">SOURCE_INSTANCE_DELETION_TIME</var>: the time that the source instance was deleted


HTTP method and URL:

```
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#getLatestRecoveryTime",
  "earliestRecoveryTime": "2023-06-10T17:23:59.648821586Z",
  "latestRecoveryTime": "2023-06-20T17:23:59.648821586Z"
}
```

<br />

### REST v1beta4

**Unavailable instance**


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the project ID
- <var translate="no">INSTANCE_NAME</var>: the name of the instance for which you're querying for the latest recovery time


HTTP method and URL:

```
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#getLatestRecoveryTime",
  "earliestRecoveryTime": "2023-06-10T17:23:59.648821586Z",
  "latestRecoveryTime": "2023-06-20T17:23:59.648821586Z"
}
```

<br />

**Deleted instance**


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: the project ID
- <var translate="no">INSTANCE_NAME</var>: the name of the source instance for which you're querying for the latest recovery time
- <var translate="no">SOURCE_INSTANCE_DELETION_TIME</var>: the time that the source instance was deleted


HTTP method and URL:

```
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_NAME/getLatestRecoveryTime" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "kind": "sql#getLatestRecoveryTime",
  "earliestRecoveryTime": "2023-06-10T17:23:59.648821586Z",
  "latestRecoveryTime": "2023-06-20T17:23:59.648821586Z"
}
```

<br />

## Troubleshoot

| Issue | Troubleshooting |
|---|---|
| `argument --point-in-time: Failed to parse date/time: Unknown string format: 2021-0928T30:54:03.094; received: 2021-0928T30:54:03.094Z` OR `Invalid value at 'body.clone_context.point_in_time' (type.googleapis.com/google.protobuf.Timestamp), Field 'pointInTime', Invalid time format: Failed to parse input,` | The timestamp you provided is invalid. |
| `HTTP Error 400: Successful backup required for carrying out the operation was not found.` OR `Successful backup required for carrying out the operation was not found. or Time where no backups can be found.` | The timestamp that you provided is for a time where backups or when binlog coordinates could not be found. |

## What's next

- [Configure flags](https://docs.cloud.google.com/sql/docs/mysql/flags.md.txt) on your clone