Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Restaurar snapshots da tabela
Neste documento, você verá como criar uma tabela gravável a partir de um
snapshot de tabela usando o Console do Google Cloud, uma consulta CREATE TABLE CLONE, um
comando bq cp ou a API jobs.insert.
Ele é destinado a usuários familiarizados com
os snapshots da tabela.
O conjunto de dados que contém a tabela de destino
Restaurar um snapshot da tabela
Para criar uma tabela gravável a partir de um snapshot, especifique a tabela que você
quer copiar e a tabela de destino. A tabela de destino pode ser uma nova
tabela ou é possível substituir uma tabela atual pelo snapshot da tabela.
Restaurar para uma nova tabela
É possível restaurar um snapshot da tabela em uma nova tabela usando uma das seguintes opções:
Console
No Console do Google Cloud, acesse a página BigQuery.
SNAPSHOT_PROJECT_ID: o ID do projeto que contém o snapshot do qual você está restaurando.
SNAPSHOT_DATASET_NAME: o nome do conjunto de dados
que contém o snapshot do qual você está restaurando.
SNAPSHOT_NAME: o nome do snapshot
do qual você está restaurando.
TABLE_PROJECT_ID: o ID do projeto em que a nova tabela será criada.
TABLE_DATASET_NAME: o nome do conjunto de dados
em que a nova tabela será criada.
NEW_TABLE_NAME: o nome da nova
tabela.
Se uma validade não for especificada, a tabela de destino expirará após o
prazo de validade padrão da tabela do conjunto de dados que contém a tabela
de destino.
Substituir uma tabela atual
É possível substituir uma tabela por um snapshot usando uma das
seguintes opções:
Console
No Console do Google Cloud, acesse a página BigQuery.
SNAPSHOT_PROJECT_ID: o ID do projeto que contém o snapshot do qual você está restaurando.
SNAPSHOT_DATASET_NAME: o nome do conjunto de dados
que contém o snapshot do qual você está restaurando.
SNAPSHOT_NAME: o nome do snapshot
do qual você está restaurando.
TABLE_PROJECT_ID: o ID do projeto em que a nova tabela será criada.
TABLE_DATASET_NAME: o nome do conjunto de dados
que contém a tabela que você está substituindo.
TABLE_NAME: o nome da tabela que você
está substituindo.
Se uma validade não for especificada, a tabela de destino expirará após o
prazo de validade padrão da tabela do conjunto de dados que contém a tabela
de destino.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-03-04 UTC."],[[["\u003cp\u003eThis document details the process of creating a writeable table from a table snapshot in Google Cloud, providing guidance for users familiar with table snapshots.\u003c/p\u003e\n"],["\u003cp\u003eCreating a writeable table from a snapshot requires specific IAM permissions such as \u003ccode\u003ebigquery.tables.get\u003c/code\u003e, \u003ccode\u003ebigquery.tables.getData\u003c/code\u003e, \u003ccode\u003ebigquery.tables.restoreSnapshot\u003c/code\u003e, and \u003ccode\u003ebigquery.tables.create\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can restore a table snapshot to either a new table or overwrite an existing one using the Google Cloud console, SQL's \u003ccode\u003eCREATE TABLE CLONE\u003c/code\u003e statement, \u003ccode\u003ebq cp\u003c/code\u003e command, or the \u003ccode\u003ejobs.insert\u003c/code\u003e API.\u003c/p\u003e\n"],["\u003cp\u003eTo overwrite an existing table, ensure you use \u003ccode\u003eCREATE OR REPLACE TABLE\u003c/code\u003e in SQL or include the \u003ccode\u003e--force\u003c/code\u003e flag in the \u003ccode\u003ebq cp\u003c/code\u003e command, or use \u003ccode\u003e"writeDisposition": "WRITE_TRUNCATE"\u003c/code\u003e in the API call.\u003c/p\u003e\n"],["\u003cp\u003eThe user needs the appropriate predefined roles in order to copy the table snapshot, such as \u003ccode\u003ebigquery.dataEditor\u003c/code\u003e, \u003ccode\u003ebigquery.dataOwner\u003c/code\u003e, or \u003ccode\u003ebigquery.admin\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Restore table snapshots\n=======================\n\nThis document describes how to create a writeable table from a\ntable snapshot by using the Google Cloud console, a `CREATE TABLE CLONE` query, a\n`bq cp` command, or the `jobs.insert` API.\nIt is intended for users who are familiar with\n[table snapshots](/bigquery/docs/table-snapshots-intro).\n\nPermissions and roles\n---------------------\n\nThis section describes the\n[Identity and Access Management (IAM) permissions](/bigquery/docs/access-control#bq-permissions)\nthat you need to create a writeable table from a table snapshot, and the\n[predefined IAM roles](/bigquery/docs/access-control#bigquery)\nthat grant those permissions.\n\n### Permissions\n\nTo create a writeable table from a table snapshot, you need the following\npermissions:\n\n### Roles\n\nThe predefined BigQuery roles that provide the required\npermissions are as follows:\n\nRestore a table snapshot\n------------------------\n\nTo create a writeable table from a snapshot, specify the table snapshot that you\nwant to copy and the destination table. The destination table can be a new\ntable, or you can overwrite an existing table with the table snapshot.\n\n### Restore to a new table\n\nYou can restore a table snapshot into a new table by using one of the following options: \n\n### Console\n\n1. In the Google Cloud console, go to the **BigQuery** page.\n\n [Go to BigQuery](https://console.cloud.google.com/bigquery)\n2. In the **Explorer** pane, expand the project and dataset nodes of the\n table snapshot you want to restore from.\n\n3. Click the name of the table snapshot.\n\n4. In the table snapshot pane that appears, click **Restore**.\n\n5. In the **Restore snapshot** pane that appears, enter the **Project** ,\n **Dataset** , and **Table** information for the new table.\n\n6. Click **Save**.\n\n### SQL\n\nUse the\n[`CREATE TABLE CLONE` DDL statement](/bigquery/docs/reference/standard-sql/data-definition-language#create_table_clone_statement):\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n1. In the Google Cloud console, go to the **BigQuery** page.\n\n [Go to BigQuery](https://console.cloud.google.com/bigquery)\n2. In the query editor, enter the following statement:\n\n ```googlesql\n CREATE TABLE TABLE_PROJECT_ID.TABLE_DATASET_NAME.NEW_TABLE_NAME\n CLONE SNAPSHOT_PROJECT_ID.SNAPSHOT_DATASET_NAME.SNAPSHOT_NAME;\n ```\n\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eTABLE_PROJECT_ID\u003c/var\u003e: the project ID of the project in which to create the new table.\n - \u003cvar translate=\"no\"\u003eTABLE_DATASET_NAME\u003c/var\u003e: the name of the dataset in which to create the new table.\n - \u003cvar translate=\"no\"\u003eNEW_TABLE_NAME\u003c/var\u003e: the name of the new table.\n - \u003cvar translate=\"no\"\u003eSNAPSHOT_PROJECT_ID\u003c/var\u003e: the project ID of the project that contains the snapshot you are restoring from.\n - \u003cvar translate=\"no\"\u003eSNAPSHOT_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the snapshot you are restoring from.\n - \u003cvar translate=\"no\"\u003eSNAPSHOT_NAME\u003c/var\u003e: the name of the snapshot you are restoring from.\n\n \u003cbr /\u003e\n\n3. Click play_circle **Run**.\n\n \u003cbr /\u003e\n\nFor more information about how to run queries, see [Run an interactive query](/bigquery/docs/running-queries#queries).\n\n### bq\n\nEnter the following command in the Cloud Shell:\n\n[Go to Cloud Shell](https://console.cloud.google.com/bigquery?cloudshell=true) \n\n```bash\nbq cp \\\n--restore \\\n--no_clobber \\\nSNAPSHOT_PROJECT_ID:SNAPSHOT_DATASET_NAME.SNAPSHOT_NAME \\\nTABLE_PROJECT_ID:TABLE_DATASET_NAME.NEW_TABLE_NAME\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_PROJECT_ID\u003c/var\u003e: the project ID of the project that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_NAME\u003c/var\u003e: the name of the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eTABLE_PROJECT_ID\u003c/var\u003e: the project ID of the project in which to create the new table.\n- \u003cvar translate=\"no\"\u003eTABLE_DATASET_NAME\u003c/var\u003e: the name of the dataset in which to create the new table.\n- \u003cvar translate=\"no\"\u003eNEW_TABLE_NAME\u003c/var\u003e: the name of the new table.\n\n\u003cbr /\u003e\n\nThe `--no_clobber` flag instructs the command to fail if the destination table\nalready exists.\n\n### API\n\nCall the\n[`jobs.insert`](/bigquery/docs/reference/rest/v2/jobs/insert)\nmethod with the following parameters:\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_PROJECT_ID\u003c/var\u003e: the project ID of the project that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_NAME\u003c/var\u003e: the name of the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eTABLE_PROJECT_ID\u003c/var\u003e: the project ID of the project in which to create the new table.\n- \u003cvar translate=\"no\"\u003eTABLE_DATASET_NAME\u003c/var\u003e: the name of the dataset in which to create the new table.\n- \u003cvar translate=\"no\"\u003eNEW_TABLE_NAME\u003c/var\u003e: the name of the new table.\n\n\u003cbr /\u003e\n\nIf an expiration is not specified, then the destination table expires after the\ndefault table expiration time for the dataset that contains the destination\ntable.\n\n### Overwrite an existing table\n\nYou can overwrite an existing table with a table snapshot by using one of the\nfollowing options: \n\n### Console\n\n1. In the Google Cloud console, go to the **BigQuery** page.\n\n [Go to BigQuery](https://console.cloud.google.com/bigquery)\n2. In the **Explorer** pane, expand the project and dataset nodes of the\n table snapshot you want to restore from.\n\n3. Click the name of the table snapshot.\n\n4. In the table snapshot pane that appears, click **Restore**.\n\n5. In the **Restore snapshot** pane that appears, enter the **Project** ,\n **Dataset** , and **Table** information for the existing table.\n\n6. Select **Overwrite table if it exists**.\n\n7. Click **Save**.\n\n### SQL\n\nUse the\n[`CREATE TABLE CLONE` DDL statement](/bigquery/docs/reference/standard-sql/data-definition-language#create_table_clone_statement):\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n1. In the Google Cloud console, go to the **BigQuery** page.\n\n [Go to BigQuery](https://console.cloud.google.com/bigquery)\n2. In the query editor, enter the following statement:\n\n ```googlesql\n CREATE OR REPLACE TABLE TABLE_PROJECT_ID.TABLE_DATASET_NAME.TABLE_NAME\n CLONE SNAPSHOT_PROJECT_ID.SNAPSHOT_DATASET_NAME.SNAPSHOT_NAME;\n ```\n\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eTABLE_PROJECT_ID\u003c/var\u003e: the project ID of the project in which to create the new table.\n - \u003cvar translate=\"no\"\u003eTABLE_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the table you are overwriting.\n - \u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e: the name of the table you are overwriting.\n - \u003cvar translate=\"no\"\u003eSNAPSHOT_PROJECT_ID\u003c/var\u003e: the project ID of the project that contains the snapshot you are restoring from.\n - \u003cvar translate=\"no\"\u003eSNAPSHOT_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the snapshot you are restoring from.\n - \u003cvar translate=\"no\"\u003eSNAPSHOT_NAME\u003c/var\u003e: the name of the snapshot you are restoring from.\n\n \u003cbr /\u003e\n\n3. Click play_circle **Run**.\n\n \u003cbr /\u003e\n\nFor more information about how to run queries, see [Run an interactive query](/bigquery/docs/running-queries#queries).\n\n### bq\n\nEnter the following command in the Cloud Shell:\n\n[Go to Cloud Shell](https://console.cloud.google.com/bigquery?cloudshell=true) \n\n```bash\nbq cp \\\n--restore \\\n--force \\\nSNAPSHOT_PROJECT_ID:SNAPSHOT_DATASET_NAME.SNAPSHOT_NAME \\\nTABLE_PROJECT_ID:TABLE_DATASET_NAME.TABLE_NAME\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_PROJECT_ID\u003c/var\u003e: the project ID of the project that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_NAME\u003c/var\u003e: the name of the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eTABLE_PROJECT_ID\u003c/var\u003e: the project ID of the project in which to create the new table.\n- \u003cvar translate=\"no\"\u003eTABLE_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the table you are overwriting.\n- \u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e: the name of the table you are overwriting.\n\n\u003cbr /\u003e\n\n### API\n\nCall the\n[`jobs.insert`](/bigquery/docs/reference/rest/v2/jobs/insert)\nmethod with the following parameters:\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_PROJECT_ID\u003c/var\u003e: the project ID of the project that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eSNAPSHOT_NAME\u003c/var\u003e: the name of the snapshot you are restoring from.\n- \u003cvar translate=\"no\"\u003eTABLE_PROJECT_ID\u003c/var\u003e: the project ID of the project in which to create the new table.\n- \u003cvar translate=\"no\"\u003eTABLE_DATASET_NAME\u003c/var\u003e: the name of the dataset that contains the table you are overwriting.\n- \u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e: the name of the table you are overwriting.\n\n\u003cbr /\u003e\n\nIf an expiration is not specified, then the destination table expires after the\ndefault table expiration time for the dataset that contains the destination\ntable.\n\nWhat's next\n-----------\n\n- [List the table snapshots of a specified base table](/bigquery/docs/table-snapshots-list#list_the_table_snapshots_of_a_specified_base_table)."]]