zoukankan      html  css  js  c++  java
  • Linux tar命令解压时提示时间戳异常的处理办法

    在Linux服务器上的文件会有3个时间戳信息 访问时间(Access)、修改时间(Modify)、改变时间(Change),都是存放在该文件的Inode里面

    问题描述:

      公司网站是前后端分离的,所有的静态页面全部都需要单独部署,使用的是云服务。部署方式是通过 jenkins 从指定的 SVN 地址把 前端静态页面检出到 jenkins服务器,且每次检出的代码前都会把上一次的全部删除掉,也就是在检出代码的时候所有的文件都是重新创建的,时间戳每次都是当前系统的时间;由于公司出口带宽比较小,为了提高传输效率,会在Jenkins服务器上先把源代码(tar)压缩后再上传到云服务器解压后部署。再部署的过程中从Jenkins控制台看到在云服务器对代码解压缩的时候提示 “tar: xxx: time stamp 2017-09-03 08:32:34 is 444.030325759 s in the future” 大概意思就是文件的时间戳信息异常

    问题分析:

      tar命令在打包文件的时候会包含文件的所有属性,如时间戳、文件名、大小等等,根据 tar 命令报错的信息,tar命令在解压提取原来文件时间戳准备创建文件的时候遇到 Jenkins服务器时间 比 云服务器时间要新(in the future),就报了上面的错误。

    解决办法:

    方案一:

      1、所有服务器 用定时任务每个几分钟就同步同一个国内公开时间服务器(ntp1.aliyun.com 国内阿里云的,或其他的都行),或者直接搭建时间同步服务器(NTP)

    方案二:(推荐)

      2、tar命令在解压的时候加上 -m 参数,作用是不提取压缩包里文件的修改时间,以当前系统时间为准创建时间戳。

    提示:所有服务器时间应该需要一致的,不然其他服务也有可能出现时间的问题。最好是这2种方案都使用。

    报错复现:

    [root@localhost home]# date
    Sun Sep  3 08:32:30 CST 2017
    [root@localhost home]# touch {1..5}.log
    [root@localhost home]# ll
    total 0
    -rw-r--r--. 1 root root 0 Sep  3 08:32 1.log
    -rw-r--r--. 1 root root 0 Sep  3 08:32 2.log
    -rw-r--r--. 1 root root 0 Sep  3 08:32 3.log
    -rw-r--r--. 1 root root 0 Sep  3 08:32 4.log
    -rw-r--r--. 1 root root 0 Sep  3 08:32 5.log
    [root@localhost home]# tar zcf home.tar.gz *
    [root@localhost home]# rm -f *.log
    [root@localhost home]# date -s "20170903 08:25:00"
    Sun Sep  3 08:25:00 CST 2017
    [root@localhost home]# tar xf home.tar.gz 
    tar: 1.log: time stamp 2017-09-03 08:32:34 is 444.030325759 s in the future
    tar: 2.log: time stamp 2017-09-03 08:32:34 is 444.029975178 s in the future
    tar: 3.log: time stamp 2017-09-03 08:32:34 is 444.029878161 s in the future
    tar: 4.log: time stamp 2017-09-03 08:32:34 is 444.029821403 s in the future
    tar: 5.log: time stamp 2017-09-03 08:32:34 is 444.029553439 s in the future
    [root@localhost home]# ll
    total 4
    -rw-r--r--. 1 root root   0 Sep  3  2017 1.log    # 虽然时间戳有问题,但还是解压了,不确定会不会有其他问题
    -rw-r--r--. 1 root root   0 Sep  3  2017 2.log
    -rw-r--r--. 1 root root   0 Sep  3  2017 3.log
    -rw-r--r--. 1 root root   0 Sep  3  2017 4.log
    -rw-r--r--. 1 root root   0 Sep  3  2017 5.log
    -rw-r--r--. 1 root root 136 Sep  3  2017 home.tar.gz
    [root@localhost home]# stat 1.log 
      File: `1.log'
      Size: 0             Blocks: 0          IO Block: 4096   regular empty file
    Device: 802h/2050d    Inode: 917607      Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2017-09-03 08:25:09.967538065 +0800
    Modify: 2017-09-03 08:32:34.000000000 +0800
    Change: 2017-09-03 08:25:09.967999958 +0800
    [root@localhost home]# rm -f *.log
    [root@localhost home]# ll
    total 4
    -rw-r--r--. 1 root root 136 Sep  3  2017 home.tar.gz
    [root@localhost home]#
    tar mxf home.tar.gz # 加上 -m 参数后没有报错,且时间是当前系统时间 [root@localhost home]# ll total 4 -rw-r--r--. 1 root root 0 Sep 3 08:26 1.log -rw-r--r--. 1 root root 0 Sep 3 08:26 2.log -rw-r--r--. 1 root root 0 Sep 3 08:26 3.log -rw-r--r--. 1 root root 0 Sep 3 08:26 4.log -rw-r--r--. 1 root root 0 Sep 3 08:26 5.log -rw-r--r--. 1 root root 136 Sep 3 2017 home.tar.gz [root@localhost home]# stat 1.log File: `1.log' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 802h/2050d Inode: 917607 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2017-09-03 08:26:05.388000347 +0800 Modify: 2017-09-03 08:26:05.388000347 +0800 Change: 2017-09-03 08:26:05.388000347 +0800

    [root@localhost home]# tar --help|fgrep 'touch'
    -m, --touch don't extract file modified time

     
    ***** 不要假装努力,结果不会陪你演戏! *****
  • 相关阅读:
    leetcode33. Search in Rotated Sorted Array
    pycharm 设置sublime text3 monokai主题
    django class Meta
    leetcode30, Substring With Concatenation Of All Words
    Sublime text3修改tab键为缩进为四个空格,
    sublime text3 python打开图像的问题
    安装上imesupport输入法依然不跟随的解决办法,
    sublime text3 的插件冲突弃用问题,
    sublime text3 BracketHighlighter括号匹配的设置
    windows 下wget的使用
  • 原文地址:https://www.cnblogs.com/chenjinxi/p/7468824.html
Copyright © 2011-2022 走看看