Linux tar命令解壓時(shí)提示時(shí)間戳異常的處理辦法
在Linux服務(wù)器上的文件會(huì)有3個(gè)時(shí)間戳信息 訪問(wèn)時(shí)間(Access)、修改時(shí)間(Modify)、改變時(shí)間(Change),都是存放在該文件的Inode里面
問(wèn)題描述:
公司網(wǎng)站是前后端分離的,所有的靜態(tài)頁(yè)面全部都需要單獨(dú)部署,使用的是云服務(wù)。部署方式是通過(guò) jenkins 從指定的 SVN 地址把 前端靜態(tài)頁(yè)面檢出到 jenkins服務(wù)器,且每次檢出的代碼前都會(huì)把上一次的全部刪除掉,也就是在檢出代碼的時(shí)候所有的文件都是重新創(chuàng)建的,時(shí)間戳每次都是當(dāng)前系統(tǒng)的時(shí)間;由于公司出口帶寬比較小,為了提高傳輸效率,會(huì)在Jenkins服務(wù)器上先把源代碼(tar)壓縮后再上傳到云服務(wù)器解壓后部署。再部署的過(guò)程中從Jenkins控制臺(tái)看到在云服務(wù)器對(duì)代碼解壓縮的時(shí)候提示 “tar: xxx: time stamp 2017-09-03 08:32:34 is 444.030325759 s in the future” 大概意思就是文件的時(shí)間戳信息異常
問(wèn)題分析:
tar命令在打包文件的時(shí)候會(huì)包含文件的所有屬性,如時(shí)間戳、文件名、大小等等,根據(jù) tar 命令報(bào)錯(cuò)的信息,tar命令在解壓提取原來(lái)文件時(shí)間戳準(zhǔn)備創(chuàng)建文件的時(shí)候遇到 Jenkins服務(wù)器時(shí)間 比 云服務(wù)器時(shí)間要新(in the future),就報(bào)了上面的錯(cuò)誤。
解決辦法:
方案一:
1、所有服務(wù)器 用定時(shí)任務(wù)每個(gè)幾分鐘就同步同一個(gè)國(guó)內(nèi)公開(kāi)時(shí)間服務(wù)器(ntp1.aliyun.com 國(guó)內(nèi)阿里云的,或其他的都行),或者直接搭建時(shí)間同步服務(wù)器(NTP)
方案二:(推薦)
2、tar命令在解壓的時(shí)候加上 -m 參數(shù),作用是不提取壓縮包里文件的修改時(shí)間,以當(dāng)前系統(tǒng)時(shí)間為準(zhǔn)創(chuàng)建時(shí)間戳。
提示:所有服務(wù)器時(shí)間應(yīng)該需要一致的,不然其他服務(wù)也有可能出現(xiàn)時(shí)間的問(wèn)題。最好是這2種方案都使用。
報(bào)錯(cuò)復(fù)現(xiàn):
[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 # 雖然時(shí)間戳有問(wèn)題,但還是解壓了,不確定會(huì)不會(huì)有其他問(wèn)題 -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 參數(shù)后沒(méi)有報(bào)錯(cuò),且時(shí)間是當(dāng)前系統(tǒng)時(shí)間 [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

浙公網(wǎng)安備 33010602011771號(hào)