Azure / azure-cli

Azure Command-Line Interface
MIT License
3.94k stars 2.92k forks source link

azure postgres flexible-server restore command not working #29353

Open anilnz opened 1 month ago

anilnz commented 1 month ago

Describe the bug

The az postgres flexible-server restore is not working on the latest version of azure cli v2.62.0. The same command works well with azure-cli v2.61.0

Related command

az postgres flexible-server restore

Errors

az postgres flexible-server restore --name restored-pg-server --resource-group destination_resource_group --source-server /subscriptions/{subscription_id_redacted}/resourceGroups/{source_resource_group}/providers/Microsoft.DBforPostgreSQL/flexibleServers/source-pg-server --no-wait
(ResourceNotFound) The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

Issue script & Debug output

Command

az postgres flexible-server restore --name restored-pg-server --resource-group destination_resource_group --source-server /subscriptions/{subscription_id_redacted}/resourceGroups/{source_resource_group}/providers/Microsoft.DBforPostgreSQL/flexibleServers/source-pg-server --no-wait

Debug output

DEBUG: cli.knack.cli: Command arguments: ['postgres', 'flexible-server', 'restore', '--debug', '--name', 'restored-pg-server', '--resource-group', 'destination_resource_group', '--source-server', '/subscriptions/{subscription_id_redacted}/resourceGroups/{test-team}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{source-pg-server}', '--no-wait']
DEBUG: cli.knack.cli: __init__ debug log:
Cannot enable color.
DEBUG: cli.knack.cli: Event: Cli.PreExecute []
DEBUG: cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7f3e1ed48040>, <function OutputProducer.on_global_arguments at 0x7f3e1ecee200>, <function CLIQuery.on_global_arguments at 0x7f3e1eb03ce0>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
DEBUG: cli.azure.cli.core: Modules found from index for 'postgres': ['azure.cli.command_modules.rdbms']
DEBUG: cli.azure.cli.core: Loading command modules:
DEBUG: cli.azure.cli.core: Name                  Load Time    Groups  Commands
DEBUG: cli.azure.cli.core: rdbms                     0.147        49       202
DEBUG: cli.azure.cli.core: Total (1)                 0.147        49       202
DEBUG: cli.azure.cli.core: Loaded 49 groups, 202 commands.
DEBUG: cli.azure.cli.core: Found a match in the command table.
DEBUG: cli.azure.cli.core: Raw command  : postgres flexible-server restore
DEBUG: cli.azure.cli.core: Command table: postgres flexible-server restore
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f3e1ddd6980>]
DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/ubuntu/.azure/commands/2024-07-10.21-20-30.postgres_flexible-server_restore.10828.log'.
INFO: az_command_data_logger: command args: postgres flexible-server restore --debug --name {} --resource-group {} --source-server {} --no-wait
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x7f3e1de0f9c0>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x7f3e1de2ac00>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x7f3e1de2ad40>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f3e1ecee2a0>, <function CLIQuery.handle_query_parameter at 0x7f3e1eb03d80>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x7f3e1de2aca0>]
DEBUG: cli.azure.cli.core.commands.client_factory: Getting management service client client_type=PostgreSQLManagementClient
DEBUG: cli.azure.cli.core.auth.persistence: build_persistence: location='/home/ubuntu/.azure/service_principal_entries.json', encrypt=False
DEBUG: cli.azure.cli.core.auth.persistence: build_persistence: location='/home/ubuntu/.azure/msal_token_cache.json', encrypt=False
DEBUG: cli.azure.cli.core.auth.binary_cache: load: /home/ubuntu/.azure/msal_http_cache.bin
DEBUG: urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
INFO: msal.authority: Initializing with Entra authority: https://login.microsoftonline.com/{tenant_id_redacted}
DEBUG: msal.authority: openid_config("https://login.microsoftonline.com/{tenant_id_redacted}/v2.0/.well-known/openid-configuration") = {'token_endpoint': 'https://login.microsoftonline.com/{tenant_id_redacted}/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com/{tenant_id_redacted}/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonline.com/{tenant_id_redacted}/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com/{tenant_id_redacted}/oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/{tenant_id_redacted}/oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com/{tenant_id_redacted}/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com/{tenant_id_redacted}/kerberos', 'tenant_region_scope': 'NA', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'}
DEBUG: msal.application: Broker enabled? None
DEBUG: cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={}
DEBUG: cli.azure.cli.core.auth.msal_authentication: ServicePrincipalCredential.get_token: scopes=('https://management.core.windows.net//.default',), kwargs={}
DEBUG: msal.application: Cache hit an AT
DEBUG: msal.telemetry: Generate or reuse correlation_id: 55e62c94-b1d0-4fee-8d37-816bd6b71899
DEBUG: cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/{subscription_id_redacted}/resourceGroups/destination_resource_group/providers/Microsoft.DBforPostgreSQL/flexibleServers/%2Fsubscriptions%2F{subscription_id_redacted}%2FresourceGroups%2F{test-team}%2Fproviders%2FMicrosoft.DBforPostgreSQL%2FflexibleServers%2F{source-pg-server}?api-version=2023-12-01-preview'
DEBUG: cli.azure.cli.core.sdk.policies: Request method: 'GET'
DEBUG: cli.azure.cli.core.sdk.policies: Request headers:
DEBUG: cli.azure.cli.core.sdk.policies:     'Accept': 'application/json'
DEBUG: cli.azure.cli.core.sdk.policies:     'x-ms-client-request-id': '229d0e56-3ed4-11ef-9eb6-00155d7cec5e'
DEBUG: cli.azure.cli.core.sdk.policies:     'CommandName': 'postgres flexible-server restore'
DEBUG: cli.azure.cli.core.sdk.policies:     'ParameterSetName': '--debug --name --resource-group --source-server --no-wait'
DEBUG: cli.azure.cli.core.sdk.policies:     'User-Agent': 'AZURECLI/2.62.0 (DEB) azsdk-python-core/1.28.0 Python/3.11.8 (Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.31)'
DEBUG: cli.azure.cli.core.sdk.policies:     'Authorization': '*****'
DEBUG: cli.azure.cli.core.sdk.policies: Request body:
DEBUG: cli.azure.cli.core.sdk.policies: This request has no body
DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): management.azure.com:443
DEBUG: urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/{subscription_id_redacted}/resourceGroups/destination_resource_group/providers/Microsoft.DBforPostgreSQL/flexibleServers/%2Fsubscriptions%2F{subscription_id_redacted}%2FresourceGroups%2F{test-team}%2Fproviders%2FMicrosoft.DBforPostgreSQL%2FflexibleServers%2F{source-pg-server}?api-version=2023-12-01-preview HTTP/1.1" 404 264
DEBUG: cli.azure.cli.core.sdk.policies: Response status: 404
DEBUG: cli.azure.cli.core.sdk.policies: Response headers:
DEBUG: cli.azure.cli.core.sdk.policies:     'Cache-Control': 'no-cache'
DEBUG: cli.azure.cli.core.sdk.policies:     'Pragma': 'no-cache'
DEBUG: cli.azure.cli.core.sdk.policies:     'Content-Length': '264'
DEBUG: cli.azure.cli.core.sdk.policies:     'Content-Type': 'application/json; charset=utf-8'
DEBUG: cli.azure.cli.core.sdk.policies:     'Expires': '-1'
DEBUG: cli.azure.cli.core.sdk.policies:     'x-ms-failure-cause': 'gateway'
DEBUG: cli.azure.cli.core.sdk.policies:     'x-ms-request-id': '95f4104a-6a5c-4902-b6e2-f0660e78443e'
DEBUG: cli.azure.cli.core.sdk.policies:     'x-ms-correlation-request-id': '95f4104a-6a5c-4902-b6e2-f0660e78443e'
DEBUG: cli.azure.cli.core.sdk.policies:     'x-ms-routing-request-id': 'CENTRALINDIA:20240710T155033Z:95f4104a-6a5c-4902-b6e2-f0660e78443e'
DEBUG: cli.azure.cli.core.sdk.policies:     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
DEBUG: cli.azure.cli.core.sdk.policies:     'X-Content-Type-Options': 'nosniff'
DEBUG: cli.azure.cli.core.sdk.policies:     'X-Cache': 'CONFIG_NOCACHE'
DEBUG: cli.azure.cli.core.sdk.policies:     'X-MSEdge-Ref': 'Ref A: 6773C8337D5E45C898E65F8B0EA6C3DE Ref B: SIN221080715005 Ref C: 2024-07-10T15:50:32Z'
DEBUG: cli.azure.cli.core.sdk.policies:     'Date': 'Wed, 10 Jul 2024 15:50:33 GMT'
DEBUG: cli.azure.cli.core.sdk.policies: Response content:
DEBUG: cli.azure.cli.core.sdk.policies: {"error":{"code":"ResourceNotFound","message":"The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"}}
DEBUG: cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/az/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
    raise ex
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/rdbms/flexible_server_custom_postgres.py", line 206, in flexible_server_restore
    instance = client.get(resource_group_name, source_server)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/core/tracing/decorator.py", line 76, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.11/site-packages/azure/mgmt/rdbms/postgresql_flexibleservers/operations/_servers_operations.py", line 903, in get
    map_error(status_code=response.status_code, response=response, error_map=error_map)
  File "/opt/az/lib/python3.11/site-packages/azure/core/exceptions.py", line 112, in map_error
    raise error
azure.core.exceptions.ResourceNotFoundError: (ResourceNotFound) The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

ERROR: cli.azure.cli.core.azclierror: (ResourceNotFound) The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
ERROR: az_command_data_logger: (ResourceNotFound) The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Code: ResourceNotFound
Message: The Resource 'Microsoft.DBforPostgreSQL/flexibleServers/subscriptions' under resource group 'destination_resource_group' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
DEBUG: cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f3e1ddd6c00>]
INFO: az_command_data_logger: exit code: 3
INFO: cli.__main__: Command ran in 1.122 seconds (init: 0.123, invoke: 0.999)
INFO: telemetry.main: Begin splitting cli events and extra events, total events: 1
INFO: telemetry.client: Accumulated 0 events. Flush the clients.
INFO: telemetry.main: Finish splitting cli events and extra events, cli events: 1
INFO: telemetry.save: Save telemetry record of length 4400 in cache
INFO: telemetry.main: Begin creating telemetry upload process.
INFO: telemetry.process: Creating upload process: "/opt/az/bin/python3 /opt/az/lib/python3.11/site-packages/azure/cli/telemetry/__init__.py /home/ubuntu/.azure"
INFO: telemetry.process: Return from creating process
INFO: telemetry.main: Finish creating telemetry upload process.

Expected behavior

The restoration command should work and no error should be reported

Environment Summary

{ "azure-cli": "2.62.0", "azure-cli-core": "2.62.0", "azure-cli-telemetry": "1.1.0", "extensions": {} }

Additional context

Downgrading to v2.61.0 is the only option at the moment.

yonzhan commented 1 month ago

Thank you for opening this issue, we will look into it.

nachoalonsoportillo commented 1 month ago

@anilnz Thanks for having reported this one. This is a regression introduced by #28975. We'll fix it soon.

rlaveycal commented 1 month ago

When will this be fixed? Breaking the CLI like this is not acceptable.

IamSiDean commented 4 weeks ago

@anilnz Thanks for having reported this one. This is a regression introduced by #28975. We'll fix it soon.

How soon is "soon"? This still isn't fixed so now we have scripts not working.

yadavama-intel commented 4 weeks ago

Following for the fix.

nachoalonsoportillo commented 4 weeks ago

@anilnz, @rlaveycal, @IamSiDean, @yadavama-intel Fix is merged now. Will be included in upcoming July 2024 (2024-08-06) milestone. That's release version 2.63.0.

yadavama-intel commented 1 week ago

I believe following is not working, please verify -

here i am trying to restore from another resource group. - az postgres flexible-server restore --resource-group rg-dev-2 --name pgsql-dev-2-restore --source-server /subscriptions/{my-sub-id}/resourceGroups/rg-dev-1/providers/Microsoft.DBforPostgreSQL/flexibleServers/pgsql-rg-dev-1

nachoalonsoportillo commented 4 days ago

@yadavama-intel reopening this issue to solve this particular problem, which is slightly different than the original one for which the issue was created, but has the exact same consequence: cannot restore to a different resource group.

yadavama-intel commented 1 day ago

Also, i encountered another problem while restoring from a backup that resides in another resource-group. Backup snapshot is taken at 11 pm every day. Restore operation triggered with restore-time 22nd Aug 10 AM but data only shown till 21st Aug 11 pm, there were some transactions happened after 21st Aug 11 pm but they are not visible in restored server. What am i missing here?

According to this document - "The database will be recovered until 10:00 AM of August 22 by using the transaction log backup from August 21, 11:00 PM, to August 22, 10:00 AM." But unfortunately i do not see the latest data