You can use Cloud Shell to download a large number of log files from Simple Log Service and upload the files to Object Storage Service (OSS) within a short period of time. This topic describes how to use Cloud Shell to download logs.
Prerequisites
If you use a RAM user to download logs, you must grant the following permissions to the RAM user:
Read-only permission on Simple Log Service: AliyunLogReadOnlyAccess. For more information, see Create a RAM user and authorize the RAM user to access Simple Log Service.
Permissions to use Cloud Shell. For more information, see Grant a RAM user the permissions to use Cloud Shell.
Procedure
Log on to the Log Service console.
In the Projects section, click the project that you want to manage.
On the tab, click the Logstore that you want to manage.
In the search box, enter a query statement. Then, select a time range and click Search & Analyze.
On the Raw Logs tab, click the download icon and select Download Log.
In the Log Download dialog box, click Download with Cloud Shell and click OK.
If the log file is for temporary use, you do not need to associate or mount an Apsara File Storage NAS (NAS) file system to store the log file. Select Not Create.
NoteThe Cloud Shell server resides in the China (Shanghai) region. If you download logs from a Logstore that does not reside in the China (Shanghai) region, you are charged for data transfer over the Internet. For more information, see Simple Log Service pricing.
In the Download File dialog box of the Cloud Shell window, click OK.
A TXT-formatted file is downloaded to your computer.
If you want to upload the downloaded log file to an OSS bucket, perform the following operations:
Run the following command to view the OSS buckets that you can manage. This way, you can determine the OSS bucket in which you can store the log file.
aliyun oss ls
If the command is successfully run, the system returns a list of OSS buckets that you can manage.
CreationTime Region StorageClass BucketName 2021-09-24 02:03:08 +0000 UTC oss-cn-beijing Standard oss://fyytset 2021-09-26 03:27:10 +0000 UTC oss-cn-hangzhou Standard oss://demo Bucket Number is: 2
Run the
cd aliyunlog
command to go to the aliyunlog directory and run thell
command to find the downloaded log file.The downloaded log file is named in the
data_202***_100331.txt
format.total 8640 drwxr-xr-x 2 shell shell 4096 Sep 28 10:21 ./ drwxr-xr-x 6 shell shell 4096 Sep 28 10:24 ../ -rw-r--r-- 1 shell shell 3198090 Sep 28 10:03 data_20210928_100331.txt
Run the following command to upload the log file to the OSS bucket:
aliyun oss cp data_20210928_100331.txt oss://demo --region cn-hangzhou
If the following information is returned, the log file is uploaded:
Succeed: Total num: 1, size: 3,198,090. OK num: 1(upload 1 files). average speed 12792000(byte/s) 0.250823(s) elapsed