Restore deleted tables
This document describes how to restore (or undelete ) a deleted table in BigQuery. You can restore a deleted table within the time travel window specified for the dataset, including explicit deletions and implicit deletions due to table expiration. You can also configure the time travel window .
For information about how to restore an entire deleted dataset or snapshot, see the following resources:
The time travel window can have a duration between two and seven days. After the time travel window has passed, BigQuery provides a fail-safe period where the deleted data is automatically retained for an additional seven days. Once the fail-safe period has passed, it isn't possible to restore a table using any method, including opening a support ticket.
Before you begin
Ensure that you have the necessary Identity and Access Management (IAM) permissions to restore a deleted table.
Required roles
To get the permissions that
      you need to restore a deleted table,
    
      ask your administrator to grant you the BigQuery User 
( roles/bigquery.user 
)
     IAM role on the project.
  
  
  
  
  For more information about granting roles, see Manage access to projects, folders, and organizations 
.
You might also be able to get the required permissions through custom roles or other predefined roles .
Restore a table
When you restore a table from historical data, tags from the source table aren't copied to the destination table.
You can restore a table that was deleted but is still within the time travel
window by copying the table to a new table, using the @<time> 
time decorator.
You can't query a deleted table, even if you use a time decorator. You must
restore it first.
To restore a table, select one of the following options:
Console
You can't undelete a table by using the Google Cloud console.
bq
-  In the Google Cloud console, activate Cloud Shell. At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize. 
-  To restore a table, first determine a UNIX timestamp of when the table existed (in milliseconds). You can use the Linux datecommand to generate the Unix timestamp from a regular timestamp value:date -d '2023-08-04 16:00:34.456789Z' +%s000 
-  Then, use the bq copycommand with the@<time>time travel decorator to perform the table copy operation.For example, enter the following command to copy the mydataset.mytabletable at the time1418864998000into a new tablemydataset.newtable.bq cp mydataset.mytable@1418864998000 mydataset.newtable (Optional) Supply the --locationflag and set the value to your location .You can also specify a relative offset. The following example copies the version of a table from one hour ago: bq cp mydataset.mytable@-3600000 mydataset.newtable For more information, see Restore a table from a point in time . 
Go
Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries . For more information, see the BigQuery Go API reference documentation .
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries . For more information, see the BigQuery Java API reference documentation .
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

