public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonRDSConfig config = new AmazonRDSConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonRDSClient client = new AmazonRDSClient(creds, config); DescribeDBLogFilesResponse resp = new DescribeDBLogFilesResponse(); do { DescribeDBLogFilesRequest req = new DescribeDBLogFilesRequest { Marker = resp.Marker , MaxRecords = maxItems }; resp = client.DescribeDBLogFiles(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.DescribeDBLogFiles) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.Marker)); }
/// <summary> /// 本接口(DescribeDBLogFiles)用于获取数据库的各种日志列表,包括冷备、binlog、errlog和slowlog。 /// </summary> /// <param name="req">参考<see cref="DescribeDBLogFilesRequest"/></param> /// <returns>参考<see cref="DescribeDBLogFilesResponse"/>实例</returns> public async Task<DescribeDBLogFilesResponse> DescribeDBLogFiles(DescribeDBLogFilesRequest req) { JsonResponseModel<DescribeDBLogFilesResponse> rsp = null; try { var strResp = await this.InternalRequest(req, "DescribeDBLogFiles"); rsp = JsonConvert.DeserializeObject<JsonResponseModel<DescribeDBLogFilesResponse>>(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return rsp.Response; }
/// <summary> /// RDSからログファイルを取得し、保存します。 /// </summary> public void get_logs() { //ファイル名一覧取得 DescribeDBLogFilesRequest request = new DescribeDBLogFilesRequest(); DescribeDBLogFilesResponse ret; request.DBInstanceIdentifier = db_instance_identifier; ret = rds_client.DescribeDBLogFiles(request); foreach (DescribeDBLogFilesDetails log in ret.DescribeDBLogFiles) { //タイムスタンプ取得 var timestamp = log.LastWritten / 1000; DateTime dt_timestamp = UnixTime.FromUnixTime(timestamp);//POSIXからDateTimeに変換 //ディレクトリ作成 string str_timestamp = dt_timestamp.ToString("yyyyMMdd"); string log_path = log_base_path + "\\" + db_instance_identifier + "\\" + str_timestamp + "\\"; if (!Directory.Exists(log_path)) { Directory.CreateDirectory(log_path); } //余計なファイルを除外 if (log.LogFileName == "mysqlUpgrade") { continue; } //ファイル名はslowquery/mysql-slowquery.logのような形式なので、ファイル名だけ抜き出す。 string log_file_name = log_path + log.LogFileName.Split('/')[1]; Console.WriteLine(log_file_name);//for debug... //一旦ファイル削除(上書きする為) if (File.Exists(log_file_name)) { File.Delete(log_file_name); } //ログファイルの中身取得 { get_log_data(log.LogFileName, log_file_name, dt_timestamp); } } }