1. 程式人生 > 其它 >關於aws cli命令的exit/return code分析

關於aws cli命令的exit/return code分析

最近總是收到一個備份指令碼的失敗郵件,指令碼是之前同事寫的,沒有加入任何有除錯資訊,及有用的日誌

於是去分析 ,指令碼中有一條 aws s3 sync $srclocal $dsts3 命令,然後根據這條命令的執行狀態碼判斷成功與失敗

失敗後,會發送失敗的提醒郵件,然後去s3介面去看,s3 sync備份任務又好像是的成功的,主要的核心的備份檔案都是在的

難道是部分檔案備份失敗,於是加入除錯資訊,輸出stderr資訊及exit code,最後return code 為 2

最後,去查詢了一下,aws cli相關的文件,AWS CLI Return Codes, 有一段說明如下:

These are the following return
codes returned at the end of execution of a CLI command: 0 -- The service responded with an HTTP response status code of 200 and there were no errors from either the CLI or the service the request was made to. 1 -- Limited to s3 commands, at least one or more s3 transfers failed for the command executed.
2 -- The meaning of this return code depends on the command being run. The primary meaning is that the command entered on the command line failed to be parsed. Parsing failures can be caused by, but are not limited to, missing any required subcommands or arguments or using any unknown commands or arguments. Note that this
return code meaning is applicable to all CLI commands. The other meaning is only applicable to s3 commands. It can mean at least one or more files marked for transfer were skipped during the transfer process. However, all other files marked for transfer were successfully transferred. Files that are skipped during the transfer process include: files that do not exist, files that are character special devices,block special device, FIFO's, or sockets, and files that the user cannot read from. 130 -- The process received a SIGINT (Ctrl-C). 255 -- Command failed. There were errors from either the CLI or the service the request was made to.

官方文件參考:https://docs.aws.amazon.com/cli/latest/topic/return-codes.html

對於2的返回碼分析,加之輸出的除錯資訊分析 ,發現使用者對某一個檔案,沒有讀的許可權

[qq_5201351@localhost tmp]$ cat Project_s3sync_stderr.log
warning: Skipping file /backup/db-backup.20211108.tar. File/Directory is not readable.

解決方法:對於這個檔案,給執行備份指令碼的使用者加上讀許可權即可~

尊重別人的勞動成果 轉載請務必註明出處:https://www.cnblogs.com/5201351/p/15523673.html

作者:一名卑微的IT民工

出處:https://www.cnblogs.com/5201351

本部落格所有文章僅用於學習、研究和交流目的,歡迎非商業性質轉載。

博主的文章沒有高度、深度和廣度,只是湊字數。由於博主的水平不高,不足和錯誤之處在所難免,希望大家能夠批評指出。

博主是利用讀書、參考、引用、抄襲、複製和貼上等多種方式打造成自己的文章,請原諒博主成為一個卑微的IT民工!