
    O                         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 backup copy.    )absolute_import)division)unicode_literalsN)backup_operations)backups)base)resource_args)logc                   N    e Zd ZdZd ej
                  d      iZed        Zd Z	y)Copyz,Copies a backup of a Cloud Spanner database.EXAMPLESaj          To copy a backup within the same project, run:

          $ {command} --source-instance=SOURCE_INSTANCE_ID --source-backup=SOURCE_BACKUP_ID  --destination-instance=DESTINATION_INSTANCE_ID --destination-backup=DESTINATION_BACKUP_ID --expiration-date=2020-03-29T10:49:41Z

        To copy a backup to a different project, run:

          $ {command} --source-backup=projects/SOURCE_PROJECT_ID/instances/SOURCE_INSTANCE_ID/backups/SOURCE_BACKUP_ID --destination-backup=projects/DESTINATION_PROJECT_ID/instances/DESTINATION_INSTANCE_ID/backups/DESTINATION_BACKUP_ID --expiration-date=2020-03-29T10:49:41Z

        c                 T   t        j                  |        | j                  dd      }|j                  dd       |j                  dd       t        j
                  j                  |        | j                         }t        j                  |       t        j                  |d       y	)
z Register flags for this command.T)mutexrequiredz--expiration-datezExpiration time of the backup, must be at least 6 hours and at most 366 days from the time when the source backup is created. See `$ gcloud topic datetimes` for information on date/time formats.)helpz--retention-periodzRetention period of the backup relative from now, must be at least 6 hours and at most 366 days from the time when the source backup is created. See `$ gcloud topic datetimes` for information on duration formats.z to copy the Cloud Spanner backupN)	r	   AddCopyBackupResourceArgsadd_argument_groupadd_argumentr   
ASYNC_FLAGAddToParserAddCopyBackupEncryptionTypeArgAddKmsKeyResourceArg)parsergroup_parserencryption_group_parsers      #lib/surface/spanner/backups/copy.pyArgsz	Copy.Args/   s     ++F3,,4$,GLK  L
     	OO'$779001HI&&'>'IK    c                    |j                   j                  j                         }|j                   j                  j                         }t	        j
                  |      }t	        j                  |      }t        j                  |||||      }|j                  rXt        j                  j                  dj                  |j                         |j                         |j                               |S t!        j"                  |dj                  |j                              }|j$                  t        j&                  |       |S )z9This is what gets called when the user runs this command.zFCopy request issued from [{}] to [{}]
Check operation [{}] for status.z&Waiting for operation [{}] to complete)CONCEPTSsourceParsedestinationr	   GetCopyBackupEncryptionTypeGetAndValidateKmsKeyNamer   
CopyBackupasync_r
   statusPrintformatRelativeNamenamer   AwaiterrorCreatedResource)selfargssource_backup_refdestination_backup_refencryption_typekms_keyop	op_results           r   RunzCopy.RunF   s    ,,224!]]66<<>#??EO44T:G			-/Et+W
6B{{	jj ::@&,99;1>>@"'';KL i!''
4;;BGGDFI	xx	)$r   N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpstaticmethodr   r8    r   r   r   r      s?    4 
(// 	 	- K K,r   r   )r<   
__future__r   r   r   r=   googlecloudsdk.api_lib.spannerr   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.spannerr	   googlecloudsdk.corer
   Commandr   rA   r   r   <module>rH      s5    ' &  '  < 2 ( < #<4<< <r   