I have accidently deleted a dataset.

Hello Team,

I have accidently deleted a dataset on Big query . I want to restore it now.

0 1 86
1 REPLY 1

Unfortunately, once a dataset is deleted in BigQuery, it cannot be directly recovered in its entirety. However, you still have several options to potentially retrieve tables and views individually:

For Tables:

  • Time Travel: BigQuery's Time Travel feature is your primary tool for table recovery. If the deletion occurred within the last 7 days, this feature allows you to access and query past versions of a table. For detailed steps on how to restore a table using Time Travel, refer to the official BigQuery documentation.

  • Snapshots: If you had the foresight to create snapshots of your tables before deletion, these could be invaluable for recovery. You can restore your tables from these snapshots, which is particularly useful as it extends beyond the 7-day window offered by the Time Travel feature. The BigQuery documentation provides detailed instructions on how to restore table snapshots.

  • Backups: Regularly exporting your dataset or individual tables to GCS or another backup solution is a crucial practice for data loss prevention. If you have such backups, you can restore your data from these.

For Views:

  • Query History: To recover views, utilize the BigQuery Logs Viewer to search for "CREATE VIEW" or "CREATE OR REPLACE VIEW" queries executed before the deletion. This can help you find the SQL queries needed to recreate your views in a new dataset.

  • Code Repositories: If your views were defined in scripts or notebooks, check your version control systems or code repositories. Executing these scripts again can recreate the views.

Important Notes:

  • Dataset Recreation Limitation: It's important to note that you cannot recreate a deleted dataset with the same name for 24 hours following its deletion. This limitation could affect your recovery strategy.

  • Knowledge of Names: Having the exact names of the tables and views you wish to restore is essential for utilizing features like Time Travel effectively.

  • Metadata and Settings Loss: Even if you successfully recover all tables and views, be aware that the original dataset's metadata, access controls, and other configurations will not be automatically restored. These settings will need to be manually reconfigured.

Preventive Measures:

To mitigate the impact of such incidents in the future, consider implementing the following best practices:

  • Regular Exports and Snapshots: Schedule regular exports of your datasets to GCS and create snapshots of critical tables.

  • Access Controls: Tighten your IAM policies to ensure only authorized users have delete permissions.

  • Audit Logging: Enable audit logging to monitor and review actions taken on your datasets, which can aid in understanding and preventing data loss events.

Additional Resources:

For more comprehensive guidance on data recovery in BigQuery and effective dataset management, refer to the official Google BigQuery documentation. This resource is regularly updated and offers in-depth instructions and best practices for managing and protecting your data in BigQuery.