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

2022年01月14日 阅读数:3
这篇文章主要向大家介绍关于aws cli命令的exit/return code分析,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

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

因而去分析 ,脚本中有一条 aws s3 sync $srclocal  $dsts3 命令,而后根据这条命令的执行状态码判断成功与失败缓存

失败后,会发送失败的提醒邮件,而后去s3界面去看,s3 sync备份任务又好像是的成功的,主要的核心的备份文件都是在的app

难道是部分文件备份失败,因而加入调试信息,输出stderr信息及exit code,最后return code 为 2 socket

 

最后,去查询了一下,aws cli相关的文档,AWS CLI Return Codes, 有一段说明以下:ui

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.htmlthis

对于2的返回码分析,加之输出的调试信息分析 ,发现用户对某一个文件,没有读的权限spa

[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'

笔者检查了一下,其余文件是正常的,这种状况通常就是少数的文件传输失败code

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

 

 

 

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