tar: file changed as we read it

前端 未结 8 1953
你的背包
你的背包 2020-12-02 15:03

I am using make and tar to backup. When executing makefile, tar command shows file changed as we read it. In this case,

相关标签:
8条回答
  • 2020-12-02 15:54

    I am not sure does it suit you but I noticed that tar does not fail on changed/deleted files in pipe mode. See what I mean.

    Test script:

    #!/usr/bin/env bash
    set -ex
    tar cpf - ./files | aws s3 cp - s3://my-bucket/files.tar
    echo $?
    

    Deleting random files manually...

    Output:

    + aws s3 cp - s3://my-bucket/files.tar
    + tar cpf - ./files
    tar: ./files/default_images: File removed before we read it
    tar: ./files: file changed as we read it
    + echo 0
    0
    
    0 讨论(0)
  • 2020-12-02 15:56

    It worked for me by adding a simple sleep timeout of 20 sec. This might happen if your source directory is still writing. Hence put a sleep so that the backup would finish and then tar should work fine. This also helped me in getting the right exit status.

    sleep 20
    tar -czf ${DB}.${DATE}.tgz ./${DB}.${DATE}
    
    0 讨论(0)
提交回复
热议问题