@@ -1661,21 +1661,17 @@ static void cancelCreateBackup(
1661
1661
// [END spanner_cancel_backup_create]
1662
1662
1663
1663
// [START spanner_list_backup_operations]
1664
- static void listBackupOperations (InstanceAdminClient instanceAdminClient , DatabaseId databaseId ) {
1664
+ static void listBackupOperations (InstanceAdminClient instanceAdminClient , DatabaseId databaseId , BackupId backupId ) {
1665
1665
Instance instance = instanceAdminClient .getInstance (databaseId .getInstanceId ().getInstance ());
1666
1666
// Get create backup operations for the sample database.
1667
- Timestamp last24Hours = Timestamp .ofTimeSecondsAndNanos (TimeUnit .SECONDS .convert (
1668
- TimeUnit .HOURS .convert (Timestamp .now ().getSeconds (), TimeUnit .SECONDS ) - 24 ,
1669
- TimeUnit .HOURS ), 0 );
1670
1667
String filter =
1671
1668
String .format (
1672
- "(metadata.database:%s) AND "
1673
- + "(metadata.@type:type.googleapis.com/"
1674
- + "google.spanner.admin.database.v1.CreateBackupMetadata) AND "
1675
- + "(metadata.progress.start_time > \" %s\" )" ,
1676
- databaseId .getName (), last24Hours );
1677
- Page <Operation > operations = instance .listBackupOperations (Options .filter (filter ));
1678
- for (Operation op : operations .iterateAll ()) {
1669
+ "(metadata.@type:type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) "
1670
+ + "AND (metadata.database:%s)" ,
1671
+ databaseId .getName ());
1672
+ Page <Operation > createBackupOperations = instance .listBackupOperations (Options .filter (filter ));
1673
+ System .out .println ("Create Backup Operations:" );
1674
+ for (Operation op : createBackupOperations .iterateAll ()) {
1679
1675
try {
1680
1676
CreateBackupMetadata metadata = op .getMetadata ().unpack (CreateBackupMetadata .class );
1681
1677
System .out .println (
@@ -1689,6 +1685,30 @@ static void listBackupOperations(InstanceAdminClient instanceAdminClient, Databa
1689
1685
System .err .println (e .getMessage ());
1690
1686
}
1691
1687
}
1688
+
1689
+ // Get copy backup operations for the sample database.
1690
+ filter =
1691
+ String .format (
1692
+ "(metadata.@type:type.googleapis.com/"
1693
+ + "google.spanner.admin.database.v1.CopyBackupMetadata) "
1694
+ + "AND (metadata.source_backup:%s)" ,
1695
+ backupId .getName ());
1696
+ Page <Operation > copyBackupOperations = instance .listBackupOperations (Options .filter (filter ));
1697
+ System .out .println ("Copy Backup Operations:" );
1698
+ for (Operation op : copyBackupOperations .iterateAll ()) {
1699
+ try {
1700
+ CopyBackupMetadata copyBackupMetadata = op .getMetadata ().unpack (CopyBackupMetadata .class );
1701
+ System .out .println (
1702
+ String .format (
1703
+ "Copy Backup %s on backup %s pending: %d%% complete" ,
1704
+ copyBackupMetadata .getName (),
1705
+ copyBackupMetadata .getSourceBackup (),
1706
+ copyBackupMetadata .getProgress ().getProgressPercent ()));
1707
+ } catch (InvalidProtocolBufferException e ) {
1708
+ // The returned operation does not contain CopyBackupMetadata.
1709
+ System .err .println (e .getMessage ());
1710
+ }
1711
+ }
1692
1712
}
1693
1713
// [END spanner_list_backup_operations]
1694
1714
@@ -2055,7 +2075,7 @@ static void run(
2055
2075
BackupId .of (backup .getInstanceId (), backup .getBackup () + "_cancel" ));
2056
2076
break ;
2057
2077
case "listbackupoperations" :
2058
- listBackupOperations (instanceAdminClient , database );
2078
+ listBackupOperations (instanceAdminClient , database , backup );
2059
2079
break ;
2060
2080
case "listdatabaseoperations" :
2061
2081
listDatabaseOperations (instanceAdminClient , dbAdminClient , database .getInstanceId ());
@@ -2151,14 +2171,14 @@ static void printUsageAndExit() {
2151
2171
System .err .println (" SpannerExample querywithqueryoptions my-instance example-db" );
2152
2172
System .err .println (" SpannerExample createbackup my-instance example-db" );
2153
2173
System .err .println (" SpannerExample listbackups my-instance example-db" );
2154
- System .err .println (" SpannerExample listbackupoperations my-instance example-db" );
2174
+ System .err .println (" SpannerExample listbackupoperations my-instance example-db backup-id " );
2155
2175
System .err .println (" SpannerExample listdatabaseoperations my-instance example-db" );
2156
2176
System .err .println (" SpannerExample restorebackup my-instance example-db" );
2157
2177
System .exit (1 );
2158
2178
}
2159
2179
2160
2180
public static void main (String [] args ) throws Exception {
2161
- if (args .length != 3 ) {
2181
+ if (args .length != 3 && args . length != 4 ) {
2162
2182
printUsageAndExit ();
2163
2183
}
2164
2184
// [START init_client]
@@ -2182,6 +2202,9 @@ public static void main(String[] args) throws Exception {
2182
2202
String .format (
2183
2203
"%s_%02d" ,
2184
2204
db .getDatabase (), LocalDate .now ().get (ChronoField .ALIGNED_WEEK_OF_YEAR ));
2205
+ if ( args .length == 4 ) {
2206
+ backupName = args [3 ];
2207
+ }
2185
2208
BackupId backup = BackupId .of (db .getInstanceId (), backupName );
2186
2209
2187
2210
// [START init_client]
0 commit comments