

# 下载数据库日志文件


您可使用 Amazon Web Services 管理控制台、Amazon CLI 或 API 下载数据库日志文件。

## 控制台


**要下载数据库日志文件，请执行以下操作**

1. 通过以下网址打开 Amazon RDS 控制台：[https://console.aws.amazon.com/rds/](https://console.amazonaws.cn/rds/)。

1. 在导航窗格中，选择 **Databases (数据库)**。

1. 选择要查看其日志文件的数据库实例的名称。

1. 选择 **Logs & events (日志和事件)** 选项卡。

1. 向下滚动到**日志**部分。

1. 在 **Logs (日志)** 部分中，选择要下载的日志旁边的按钮，然后选择 **Download (下载)**。

1. 打开提供的链接的上下文 (右键单击) 菜单，然后选择**将链接另存为**。输入您希望保存日志文件的位置，然后选择**保存**。  
![\[查看日志文件\]](http://docs.amazonaws.cn/AmazonRDS/latest/AuroraUserGuide/images/log_download2.png)

## Amazon CLI


要下载数据库日志文件，请使用 Amazon CLI 命令 [https://docs.amazonaws.cn/cli/latest/reference/rds/download-db-log-file-portion.html](https://docs.amazonaws.cn/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


要下载数据库日志文件，请使用 Amazon RDS API [https://docs.amazonaws.cn/AmazonRDS/latest/APIReference/API_DownloadDBLogFilePortion.html](https://docs.amazonaws.cn/AmazonRDS/latest/APIReference/API_DownloadDBLogFilePortion.html) 操作。