
    d                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 dd	lmZ dd
lmZ  G d de
j                        Zy)z%Command for spanner restore database.    )absolute_import)division)unicode_literalsN)database_operations)	databases)base)resource_args)logc                   p    e Zd ZdZ ej
                  d       ej
                  d      dZed        Zd Z	y)Restorez!Restore a Cloud Spanner database.zB
          Restores from a backup to a new Cloud Spanner database.a  
          To restore a backup, run:

            $ {command} --source-backup=BACKUP_ID --source-instance=SOURCE_INSTANCE --destination-database=DATABASE --destination-instance=INSTANCE_NAME

          To restore a backup using relative names, run:

            $ {command} --source-backup=projects/PROJECT_ID/instances/SOURCE_INSTANCE_ID/backups/BACKUP_ID --destination-database=projects/PROJECT_ID/instances/SOURCE_INSTANCE_ID/databases/DATABASE_ID
      )DESCRIPTIONEXAMPLESc                     t        j                  |        t        j                  j	                  |        | j                         }t        j                  |       t        j                  |d       y)z Register flags for this command.z%to restore the Cloud Spanner databaseN)r	   AddRestoreResourceArgsr   
ASYNC_FLAGAddToParseradd_argument_groupAddRestoreDbEncryptionTypeArgAddKmsKeyResourceArg)parserencryption_group_parsers     (lib/surface/spanner/databases/restore.pyArgszRestore.Args1   sW     ((0OO'$779//0GH&&'>'NP    c                 "   |j                   j                  j                         }|j                   j                  j                         }t	        j
                  |      }t	        j                  |      }t        j                  ||||      }|j                  r8t        j                  j                  dj                  |j                              S t        j                   |dj                  |j#                         |j#                                     S )a  This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      A message indicating database is restoring or when async, the operation.
    z/Restore database in progress. Operation name={}z$Restoring backup {0} to database {1})CONCEPTSsourceParsedestinationr	   GetRestoreDbEncryptionTypeGetAndValidateKmsKeyNamer   r   async_r
   statusPrintformatnamer   AwaitName)selfargs
backup_refdatabase_refencryption_typekms_keyops          r   RunzRestore.Run;   s     %%++-J==,,224L#>>tDO44T:G			<_g	NB{{ZZ
;
B
B277
KM M$$
.55joo6G6B6G6G6I	KL Lr   N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpstaticmethodr   r0    r   r   r   r      sT    ) (// E F (// 
 -  P PLr   r   )r4   
__future__r   r   r   r5   googlecloudsdk.api_lib.spannerr   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.spannerr	   googlecloudsdk.corer
   RestoreCommandr   r9   r   r   <module>r@      s9    , &  '  > 4 ( < #3Ld!! 3Lr   