

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 下載資料庫日誌檔案
<a name="USER_LogAccess.Procedural.Downloading"></a>

您可以使用 AWS 管理主控台、AWS CLI 或 API 來下載資料庫日誌檔案。

## 主控台
<a name="USER_LogAccess.Procedural.Downloading.CON"></a>

**下載資料庫日誌檔案**

1. 前往 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)，開啟 Amazon RDS 主控台。

1. 在導覽窗格中，選擇 **Databases** (資料庫)。

1. 選擇您想檢視的日誌檔案所在的資料庫執行個體的名稱。

1. 選擇 **Logs & events (日誌與事件)** 標籤。

1. 向下捲動至 **Logs (日誌)** 區段。

1. 在 **Logs (日誌)** 區段中，選擇您想要下載的日誌旁的按鈕，然後選擇 **Download (下載)**。

1. 開啟提供之連結的內容 (右鍵) 功能表，然後選擇 **Save Link As** (另存連結為)。輸入您要儲存日誌檔案的位置，然後選擇 **Save (儲存)**。  
![\[檢視日誌檔案\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/images/log_download2.png)

## AWS CLI
<a name="USER_LogAccess.Procedural.Downloading.CLI"></a>

若要下載資料庫日誌檔案，請使用 AWS CLI 命令 [https://docs.aws.amazon.com/cli/latest/reference/rds/download-db-log-file-portion.html](https://docs.aws.amazon.com/cli/latest/reference/rds/download-db-log-file-portion.html)。在預設情況下，這個命令只會下載日誌檔案的最新部分。不過，您可以指定參數 `--starting-token 0` 來下載整個檔案。

下列範例顯示下載名為 *log/ERROR.4* 之日誌檔案的完整內容方法，並將該檔案儲存於名為 *errorlog.txt* 的本機檔案中。

**Example**  
針對 Linux、macOS 或 Unix：  

```
1. aws rds download-db-log-file-portion \
2.     --db-instance-identifier myexampledb \
3.     --starting-token 0 --output text \
4.     --log-file-name log/ERROR.4 > errorlog.txt
```
針對 Windows：  

```
1. aws rds download-db-log-file-portion ^
2.     --db-instance-identifier myexampledb ^
3.     --starting-token 0 --output text ^
4.     --log-file-name log/ERROR.4 > errorlog.txt
```

## RDS API
<a name="USER_LogAccess.Procedural.Downloading.API"></a>

若要下載資料庫日誌檔案，請使用 Amazon RDS API [https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DownloadDBLogFilePortion.html](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DownloadDBLogFilePortion.html) 動作。