博客园  :: 首页  :: 管理

关于aws cli命令的exit/return code分析

Posted on 2021-11-08 12:37  520_1351  阅读(239)  评论(0编辑  收藏  举报

最近总是收到一个备份脚本的失败邮件,脚本是之前同事写的,没有加入任何有调试信息,及有用的日志

于是去分析 ,脚本中有一条 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.

解决方法:对于这个文件,给执行备份脚本的用户加上读权限即可~

 

另:在生产环境中,笔者还会遇到exit code 为1的情况,查询日志如下:

upload failed: ../../dir/.log.16 to s3://qq5201351/.log.16 [Errno 2] No such file or directory: '/dir/.log.16'

笔者检查了一下,其他文件是正常的,这种情况一般就是少数的文件传输失败

而且笔者这里的场景,很可能这个文件在当时是有变化的,如临时缓存文件完成后重命名了,所以找不到了

 

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/15523673.html