SHOW BACKUP lists the contents of a backup created with the statement.
The
SHOW BACKUP syntax without the IN keyword is deprecated as of v22.1 and will be removed in a future release.We recommend using SHOW BACKUP FROM {subdirectory} IN {collectionURI} to view backups in a subdirectory at a collection’s URI.For guidance on the syntax for SHOW BACKUP FROM, see the examples.Required privileges
SHOW BACKUP requires read permissions to its target destination.
You can grant a user the EXTERNALIOIMPLICITACCESS to interact with external resources that require implicit access.
Either the EXTERNALIOIMPLICITACCESS or the role is required for the following scenarios:
- Interacting with a cloud storage resource using .
- Using a custom endpoint on S3.
- Using the command.
- Interacting with an Amazon S3 and Google Cloud Storage resource using
SPECIFIEDcredentials. Azure Storage is alwaysSPECIFIEDby default. - Using storage.
Synopsis
Parameters
| Parameter | Description |
|---|---|
SHOW BACKUPS IN collectionURI | List the backup paths in the given . See the example. |
SHOW BACKUP FROM subdirectory IN collectionURI | Show the details of backups in the subdirectory at the given . Also, use FROM LATEST in collectionURI to show the most recent backup. See the example. |
SHOW BACKUP SCHEMAS FROM subdirectory IN collectionURI | Show the schema details of the backup in the given . See the example. |
collectionURI | The URI for the . Note that SHOW BACKUP does not support listing backups if the storage location is a symlink. Cockroach Labs recommends using remote storage for backups. |
kv_option_list | Control the behavior of SHOW BACKUP with a comma-separated list of these options. |
Options
| Option | Value | Description |
|---|---|---|
as_json | N/A | Display the backup’s internal metadata as JSON in the response. |
check_files | N/A | Validate that all files belonging to a backup are in the expected location in storage. See Validate a backup’s files for an example. |
debug_ids | N/A | Display descriptor IDs of every object in the backup, including the object’s database and parent schema. |
encryption_passphrase | The passphrase used to that the BACKUP statement generates (the data files and its manifest, containing the backup’s metadata). | |
kms | The URI of the cryptographic key stored in a key management service (KMS), or a comma-separated list of key URIs, used to . Refer to . | |
incremental_location | List the details of an incremental backup taken with the . | |
privileges | N/A | List which users and roles had which privileges on each table in the backup. Displays original ownership of the backup. |
Response
The following fields are returned:| Field | Description |
|---|---|
database_name | The database name. |
parent_schema_name | The name of the parent schema. |
object_name | The name of the , , , or schema. |
object_type | The type of object: , , , or schema. |
backup_type | The type of backup: or . |
start_time | The time of the earliest data encapsulated in the backup. Note that this only displays for incremental backups. For a full backup, this is NULL. |
end_time | The time to which data can be restored. This is equivalent to the of the backup. If the backup was not taken with , the end_time is the only time the data can be restored to. If the backup was taken with revision history, the end_time is the latest time the data can be restored to. |
size_bytes | The size of the backup objects, in bytes. Note that size_bytes indicates the logical size of the table objects, which is computed as the sum of the size of each key value pair. See file_bytes in this table for more detail. |
rows | Number of rows in tables that are part of the backup. |
create_statement | The CREATE statement used to create , , or that are stored within the backup. This displays when SHOW BACKUP SCHEMAS is used. Note that tables with references to will only display foreign key constraints if the table to which the constraint relates to is also included in the backup. |
is_full_cluster | Whether the backup is of a full cluster or not. |
regions | The statement(s) used to configure the database with , if they exist. If the database is a part of a single region cluster configuration, NULL will show. |
file_bytes | (With the check_files option only) The estimated bytes in external storage for a particular table object. This is the physical bytes that a given table object is taking up. For example, when the files are written to disk in storage they could be compressed. If you total all file bytes, the result is the physical bytes in your storage location. Note that for smaller tables the byte size in file_bytes may be larger than size_bytes because of the overhead required to create an SST file. |
path | The list of the ’s subdirectories. This field is returned for SHOW BACKUPS IN collectionURI only. The path format is <year/<month/<day-<timestamp. |
WITH debug_ids option is specified.
Examples
The examples in this section use one of the following storage URIs:- External connections, which allow you to represent an external storage or sink URI. You can then specify the external connection’s name in statements rather than the provider-specific URI. For detail on using external connections, see the page.
- Amazon S3 connection strings with the default
AUTH=specifiedparameter. For guidance on usingAUTH=implicitauthentication with Amazon S3 buckets instead, read .
View a list of the available full backup subdirectories
To view a list of the available subdirectories, use the following command:<year/<month/<day-<timestamp.
Show the most recent backup
To view the most recent backup, use theLATEST syntax:
View a list of the full and incremental backups in a specific full backup subdirectory
To view a list of the and backups in a specific subdirectory, use the following command:Show a backup taken with the incremental location option
To view an incremental backup that was taken with theincremental_location option, run SHOW BACKUP with the full backup and incremental backup location following the original BACKUP statement.
You can use the option to show the most recent backup where incremental_location has stored the backup:
Show locality-aware backups
New in v23.1:
SHOW BACKUP is able to display metadata using check_files for locality-aware backups taken with the option.default location with COCKROACH_LOCALITY=default:
SHOW BACKUP:
Show a backup with schemas
Show a backup with privileges
Use theWITH privileges option to view a list of which users and roles had which privileges on each database and table in the backup. This parameter also displays the original owner of objects in the backup:
SHOW BACKUP. It is necessary to run SHOW BACKUP with the specific backup directory rather than the backup collection’s top-level directory. Use SHOW BACKUPS IN with your storage location to list the backup directories it contains, which can then be run with SHOW BACKUP to inspect the metadata.
Show details for scheduled backups
When a , it is stored within a collection of backups in the given collection URI. To view details for a backup created by a schedule, you can use the following:SHOW BACKUPS IN collectionURIstatement to view a list of the available full backup subdirectories.SHOW BACKUP FROM subdirectory IN collectionURIstatement to view a list of the full and incremental backups that are stored in a specific full backup’s subdirectory.
Show an encrypted backup
Depending on how the backup was , use the and the same passphrase that was used to create the backup:kms option and the same KMS URI that was used to create the backup:
Show a backup with descriptor IDs
UseWITH debug_ids to display the descriptor IDs related to each object in the backup:
Validate a backup’s files
-
Use
SHOW BACKUP ... check_fileswith a backup for validation:This will return the following output after validating that the backup files are correct and present:The output will returnfile_bytesalong with the columns you receive fromSHOW BACKUPwithoutcheck_files. Thefile_bytescolumn indicates the estimated bytes in external storage for a particular table object. For more detail on the output columns, see theSHOW BACKUPtable. -
If
SHOW BACKUP ... check_filescannot read from a file, it will return an error message similar to the following:SHOW BACKUP ... check_fileswill return up to ten file paths for incorrect or missing files.
Show a backup’s internal metadata
Use theWITH as_json option to output a backup’s internal metadata, contained in its manifest file, as a JSON value:
manifest column with the file’s contents as the JSON value. Use to query particular data or edit the format of the response.
The response returned from
SHOW BACKUP FROM ... WITH as_json is a backup’s internal metadata. This content is subject to change from version to version of CockroachDB and does not offer the same stability guarantees as the other SHOW BACKUP options and their responses. As a result, as_json should only be used for debugging or general inspection purposes.
