HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //snap/google-cloud-cli/394/platform/bq/frontend/command_undelete.py
#!/usr/bin/env python
"""The undelete command for the BQ CLI."""

import datetime

from absl import app
from absl import flags

from clients import client_dataset
from clients import utils as bq_client_utils
from frontend import bigquery_command
from frontend import bq_cached_client

# These aren't relevant for user-facing docstrings:
# pylint: disable=g-doc-args


class Undelete(bigquery_command.BigqueryCmd):
  """Undelete the dataset described by identifier."""

  usage = """bq undelete dataset"""

  def __init__(self, name: str, fv: flags.FlagValues):
    super().__init__(name, fv)
    flags.DEFINE_integer(
        'timestamp',
        None,
        'Optional. Time in milliseconds since the POSIX epoch that this replica'
        ' was marked for deletion. If not specified, it will undelete the most'
        ' recently deleted version.',
        flag_values=fv,
    )
    self._ProcessCommandRc(fv)

  def RunWithArgs(self, identifier: str):
    """Undelete the dataset described by identifier.

    Always requires an identifier, unlike the show and ls commands.
    By default, also requires confirmation before undeleting.
    Supports:
     - timestamp[int]: This signifies the timestamp version of the dataset that
     needs to be restored, this should be in milliseconds

    Examples:
      bq undelete dataset
      bq undelete --timestamp 1714720875568 dataset
    """

    client = bq_cached_client.Client.Get()
    if not identifier:
      raise app.UsageError('Must provide an identifier for undelete.')
    dataset = bq_client_utils.GetDatasetReference(
        id_fallbacks=client, identifier=identifier
    )
    if self.timestamp:
      timestamp = datetime.datetime.fromtimestamp(
          self.timestamp / 1000, tz=datetime.timezone.utc
      )
    else:
      timestamp = None
    job = client_dataset.UndeleteDataset(
        client.apiclient, dataset, timestamp=timestamp
    )
    if job:
      print('Dataset undelete of %s successfully started' % (dataset,))