Skip to content

Commit

Permalink
[CosmosDB] CLI Support for InAccountRestore of deleted resources feat…
Browse files Browse the repository at this point in the history
…ure (#5394)

* InAccount vendored python sdk

* InAccount Restore CLI Commands Code changes

* Test recordings

* Updated test records

* new changes
  • Loading branch information
amisi01 authored Sep 30, 2022
1 parent fc8ac97 commit ab7d604
Show file tree
Hide file tree
Showing 143 changed files with 99,465 additions and 45,118 deletions.
5 changes: 5 additions & 0 deletions src/cosmosdb-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Release History
++++++
* Modify parameter for Managed Identity name.

0.19.0
++++++
* Add support for performing in-account restore of deleted databases and containers for a Sql database account.
* Add support for performing in-account restore of deleted databases and collections for a MongoDB database account.

0.18.0
++++++
* Add support for retrieving and redistributing throughput at physical partition level.
Expand Down
34 changes: 34 additions & 0 deletions src/cosmosdb-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,37 @@ az cosmosdb service delete \
--account-name "MyAccount"
--name "MaterializedViewsBuilder" \
```

#### Restore a deleted database within same account for a Sql database account ####

```sh
az cosmosdb sql database restore --account-name "account-name" \
--name "database-name"
--restore-timestamp "2020-07-20T16:09:53+0000" \
```

#### Restore a deleted container within same account for a Sql database account ####

```sh
az cosmosdb sql container restore --account-name "account-name" \
--database-name "database-name"
--name "container-name"
--restore-timestamp "2020-07-20T16:09:53+0000" \
```

#### Restore a deleted database within same account for a MongoDB database account ####

```sh
az cosmosdb mongodb database restore --account-name "account-name" \
--name "database-name"
--restore-timestamp "2020-07-20T16:09:53+0000" \
```

#### Restore a deleted collection within same account for a MongoDB database account ####

```sh
az cosmosdb mongodb collection restore --account-name "account-name" \
--database-name "database-name"
--collection-name "collection-name"
--restore-timestamp "2020-07-20T16:09:53+0000" \
```
40 changes: 40 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,43 @@
text: |-
az cosmosdb mongodb collection redistribute-partition-throughput --account-name account_name --database-name db_name --name container_name --resource-group rg_name --target-partition-info 8=1200 6=1200' --source-partition-info 9'
"""

# in-account restore of a deleted sql database
helps['cosmosdb sql database restore'] = """
type: command
short-summary: "Restore a deleted sql database within the same account."
examples:
- name: Restore a deleted sql database within the same account.
text: |-
az cosmosdb sql database restore --resource-group resource_group --account-name database_account_name --name name_of_database_needs_to_be_restored --restore-timestamp 2020-07-13T16:03:41+0000
"""

# in-account restore of a deleted sql container
helps['cosmosdb sql container restore'] = """
type: command
short-summary: "Restore a deleted sql container within the same account."
examples:
- name: Restore a deleted sql container within the same account.
text: |-
az cosmosdb sql container restore --resource-group resource_group --account-name database_account_name --database-name parent_database_name --name name_of_container_needs_to_be_restored --restore-timestamp 2020-07-13T16:03:41+0000
"""

# in-account restore of a deleted mongodb database
helps['cosmosdb mongodb database restore'] = """
type: command
short-summary: "Restore a deleted mongodb database within the same account."
examples:
- name: Restore a deleted mongodb database within the same account.
text: |-
az cosmosdb mongodb database restore --resource-group resource_group --account-name database_account_name --name name_of_database_needs_to_be_restored --restore-timestamp 2020-07-13T16:03:41+0000
"""

# in-account restore of a deleted mongodb collection
helps['cosmosdb mongodb collection restore'] = """
type: command
short-summary: "Restore a deleted mongodb collection within the same account."
examples:
- name: Restore a deleted mongodb collection within the same account.
text: |-
az cosmosdb mongodb collection restore --resource-group resource_group --account-name database_account_name --database-name parent_database_name --name name_of_collection_needs_to_be_restored --restore-timestamp 2020-07-13T16:03:41+0000
"""
26 changes: 26 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,29 @@ def load_arguments(self, _):
c.argument('evenly_distribute', arg_type=get_three_state_flag(), help="switch to distribute throughput equally among all physical partitions")
c.argument('target_partition_info', nargs='+', action=CreateTargetPhysicalPartitionThroughputInfoAction, required=False, help="information about desired target physical partition throughput eg: '0=1200 1=1200'")
c.argument('source_partition_info', nargs='+', action=CreateSourcePhysicalPartitionThroughputInfoAction, required=False, help="space separated source physical partition ids eg: 1 2")

# SQL database restore
with self.argument_context('cosmosdb sql database restore') as c:
c.argument('account_name', account_name_type, id_part=None, required=True)
c.argument('database_name', options_list=['--name', '-n'], help="Database name", required=True)
c.argument('restore_timestamp', options_list=['--restore-timestamp', '-t'], action=UtcDatetimeAction, help="The timestamp to which the database needs to be restored to.", required=True)

# SQL collection restore
with self.argument_context('cosmosdb sql container restore') as c:
c.argument('account_name', account_name_type, id_part=None, required=True)
c.argument('database_name', database_name_type, required=True)
c.argument('container_name', options_list=['--name', '-n'], help="Container name", required=True)
c.argument('restore_timestamp', options_list=['--restore-timestamp', '-t'], action=UtcDatetimeAction, help="The timestamp to which the container needs to be restored to.", required=True)

# MongoDB database restore
with self.argument_context('cosmosdb mongodb database restore') as c:
c.argument('account_name', account_name_type, id_part=None, required=True)
c.argument('database_name', options_list=['--name', '-n'], help="Database name", required=True)
c.argument('restore_timestamp', options_list=['--restore-timestamp', '-t'], action=UtcDatetimeAction, help="The timestamp to which the database needs to be restored to.", required=True)

# MongoDB collection restore
with self.argument_context('cosmosdb mongodb collection restore') as c:
c.argument('account_name', account_name_type, id_part=None, required=True)
c.argument('database_name', database_name_type, required=True)
c.argument('collection_name', options_list=['--name', '-n'], help="Collection name", required=True)
c.argument('restore_timestamp', options_list=['--restore-timestamp', '-t'], action=UtcDatetimeAction, help="The timestamp to which the collection needs to be restored to.", required=True)
12 changes: 12 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,15 @@ def load_command_table(self, _):
# Redistribute partition throughput for Mongo collection
with self.command_group('cosmosdb mongodb collection', cosmosdb_mongo_sdk, client_factory=cf_mongo_db_resources) as g:
g.custom_command('redistribute-partition-throughput', 'cli_begin_redistribute_mongo_container_partition_throughput', is_preview=True)

with self.command_group('cosmosdb sql database', cosmosdb_sql_sdk, client_factory=cf_sql_resources) as g:
g.custom_command('restore', 'cli_cosmosdb_sql_database_restore', is_preview=True)

with self.command_group('cosmosdb sql container', cosmosdb_sql_sdk, client_factory=cf_sql_resources) as g:
g.custom_command('restore', 'cli_cosmosdb_sql_container_restore', is_preview=True)

with self.command_group('cosmosdb mongodb database', cosmosdb_mongo_sdk, client_factory=cf_mongo_db_resources) as g:
g.custom_command('restore', 'cli_cosmosdb_mongodb_database_restore', is_preview=True)

with self.command_group('cosmosdb mongodb collection', cosmosdb_mongo_sdk, client_factory=cf_mongo_db_resources) as g:
g.custom_command('restore', 'cli_cosmosdb_mongodb_collection_restore', is_preview=True)
Loading

0 comments on commit ab7d604

Please sign in to comment.