zoukankan      html  css  js  c++  java
  • 关于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.

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

    另:在生产环境中,笔者还会遇到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

    作者:一名卑微的IT民工

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

    本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。

    博主的文章没有高度、深度和广度,只是凑字数。由于博主的水平不高,不足和错误之处在所难免,希望大家能够批评指出。

    博主是利用读书、参考、引用、抄袭、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!

  • 相关阅读:
    Linux内核分析第七周学习笔记——Linux内核如何装载和启动一个可执行程序
    <深入理解计算机系统>第七章读书笔记
    Linux内核分析第六周学习笔记——分析Linux内核创建一个新进程的过程
    linux内核分析第3章&第18章读书笔记
    Linux内核分析第五周学习总结——分析system_call中断处理过程
    课本第五章读书笔记
    Linux内核分析第四周学习总结——系统调用的工作机制
    课本第一二章读书笔记
    20162328蔡文琛 实验二 树
    20162328蔡文琛 大二week07
  • 原文地址:https://www.cnblogs.com/5201351/p/15523673.html
Copyright © 2011-2022 走看看