Skip to content

Commit

Permalink
[RDBMS] az postgres flexible-server backup create/delete: New comma…
Browse files Browse the repository at this point in the history
…nds to support creating and deleting backups on PostgreSql Flex Server (#30197)

* Add on demand backups

* Trigger build

* add missing yes command
  • Loading branch information
nasc17 authored Oct 29, 2024
1 parent 2a770c0 commit 856cb62
Show file tree
Hide file tree
Showing 6 changed files with 1,638 additions and 127 deletions.
18 changes: 18 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,16 @@
short-summary: Manage flexible server backups.
"""

helps['postgres flexible-server backup create'] = """
type: command
short-summary: Create a new backup for a flexible server.
examples:
- name: >
Create a backup.
text: >
az postgres flexible-server backup create -g testgroup -n testsvr --backup-name testbackup
"""

helps['postgres flexible-server backup list'] = """
type: command
short-summary: List all the backups for a given server.
Expand All @@ -740,6 +750,14 @@
text: az postgres flexible-server backup show -g testgroup -n testsvr --backup-name testbackup
"""

helps['postgres flexible-server backup delete'] = """
type: command
short-summary: Delete a specific backup.
examples:
- name: Delete a backup.
text: az postgres flexible-server backup delete -g testgroup -n testsvr --backup-name testbackup
"""

helps['postgres flexible-server replica'] = """
type: group
short-summary: Manage read replicas.
Expand Down
7 changes: 6 additions & 1 deletion src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def _flexible_server_params(command_group):
c.argument('max_file_size', type=int, help='The file size limitation to filter files.')

# backups
if command_group == 'mysql':
if command_group != 'mariadb':
with self.argument_context('{} flexible-server backup create'.format(command_group)) as c:
c.argument('backup_name', options_list=['--backup-name', '-b'], help='The name of the new backup.')

Expand All @@ -889,6 +889,11 @@ def _flexible_server_params(command_group):
with self.argument_context('{} flexible-server backup list'.format(command_group)) as c:
c.argument('server_name', id_part=None, arg_type=server_name_arg_type)

if command_group == 'postgres':
with self.argument_context('{} flexible-server backup delete'.format(command_group)) as c:
c.argument('backup_name', options_list=['--backup-name', '-b'], help='The name of the new backup.')
c.argument('yes', arg_type=yes_arg_type)

# identity
with self.argument_context('{} flexible-server identity'.format(command_group)) as c:
c.argument('server_name', id_part=None, options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def load_flexibleserver_command_table(self, _):
client_factory=cf_postgres_flexible_backups) as g:
g.command('list', 'list_by_server', transform=transform_backups_list)
g.show_command('show', 'get', transform=transform_backup)
g.custom_command('create', 'backup_create_func', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('delete', 'backup_delete_func', custom_command_type=flexible_servers_custom_postgres)

with self.command_group('postgres flexible-server replica', postgres_flexible_replica_sdk) as g:
g.command('list', 'list_by_server')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,28 @@ def virtual_endpoint_update_func(client, resource_group_name, server_name, virtu
parameters)


def backup_create_func(client, resource_group_name, server_name, backup_name):
validate_resource_group(resource_group_name)

return client.begin_create(
resource_group_name,
server_name,
backup_name)


def backup_delete_func(client, resource_group_name, server_name, backup_name, yes=False):
validate_resource_group(resource_group_name)

if not yes:
user_confirmation(
"Are you sure you want to delete the backup '{0}' in resource group '{1}'".format(backup_name, resource_group_name), yes=yes)

return client.begin_delete(
resource_group_name,
server_name,
backup_name)


def flexible_server_approve_private_endpoint_connection(cmd, client, resource_group_name, server_name, private_endpoint_connection_name,
description=None):
"""Approve a private endpoint connection request for a server."""
Expand Down
Loading

0 comments on commit 856cb62

Please sign in to comment.