次の方法で共有


Azure CLI を使用して Azure Database for MySQL - フレキシブル サーバーのログをリストしダウンロードする

この記事では、Azure CLI を使用して Azure Database for MySQL フレキシブル サーバーのログをリストしダウンロードする方法について説明します。

Prerequisites

この記事では、Azure CLI バージョン 2.39.0 以降をローカルで実行している必要があります。 インストールされているバージョンを確認するには、az --version コマンドを実行します。 インストールまたはアップグレードする必要がある場合は、「Azure CLI のインストール」を参照してください。

You need to sign in to your account using the az login command. Note the id property, which refers to Subscription ID for your Azure account.

az login

az account set コマンドを使用して、アカウントの特定のサブスクリプションを選択します。 Make a note of the id value from the az login output to use as the value for subscription argument in the command. 複数のサブスクリプションをお持ちの場合は、リソースが課金の対象となる適切なサブスクリプションを選択してください。 すべてのサブスクリプションを取得するには、az account list を使用します。

az account set --subscription <subscription id>

Azure CLI を使用してサーバー ログをリスト化する

前提条件を構成してサブスクリプションに接続したら、次のコマンドを実行して、Azure Database for MySQL フレキシブル サーバー インスタンスのサーバー ログを一覧表示します。 コマンド出力の詳細を次に示します。

az mysql flexible-server server-logs list --resource-group <myresourcegroup> --server-name <serverlogdemo> --out <table>

上記のコマンドの詳細を次に示します

LastModifiedTime Name ResourceGroup SizeInKb TypePropertiesType Url
2022-08-01T11:09:48+00:00 mysql-slow-serverlogdemo-2022073111.log myresourcegroup 10947 slowlog https://00000000000.file.core.windows.net/0000000serverlog/slowlogs/mysql-slow-serverlogdemo-2022073111.log?
2022-08-02T11:10:00+00:00 mysql-slow-serverlogdemo-2022080111.log myresourcegroup 10927 slowlog https://00000000000.file.core.windows.net/0000000serverlog/slowlogs/mysql-slow-serverlogdemo-2022080111.log?
2022-08-03T11:10:12+00:00 mysql-slow-serverlogdemo-2022080211.log myresourcegroup 10936 slowlog https://00000000000.file.core.windows.net/0000000serverlog/slowlogs/mysql-slow-serverlogdemo-2022080211.log?
2022-08-03T11:12:00+00:00 mysql-slow-serverlogdemo-2022080311.log myresourcegroup 8920 slowlog https://00000000000.file.core.windows.net/0000000serverlog/slowlogs/mysql-slow-serverlogdemo-2022080311.log?

この一覧には、使用可能なサーバー ログの LastModifiedTime、Name、ResourceGroup、SizeInKb、ダウンロード URL が表示されます。 既定の LastModifiedTime は 72 時間に設定されています。 72 時間より前のファイルを一覧表示するには、 --file-last-written <Time:HH> フラグを使用します。

az mysql flexible-server server-logs list --resource-group <myresourcegroup>  --server-name <serverlogdemo> --out table --file-last-written <144>

Azure CLI を使用してサーバー ログをダウンロードする

次のコマンドは、上記のサーバー ログを現在のディレクトリにダウンロードします。

az mysql flexible-server server-logs download --resource-group <myresourcegroup> --server-name <serverlogdemo>  --name <mysql-slow-serverlogdemo-2022073111.log>