要求:寫這篇博文是因爲今天公司要求上傳數據庫備份文件到ftp服務器, 在進入ftp服務器後使用ls命令要求看到的文件時間戳不改變?
解答:之前本人使用的上傳方法是ftp無法做到,之後使用lftp可以保證原上傳文件的時間戳不改變但是再一次出現問題
問題:上傳到ftp服務器上的文件與本地文件存在幾個小時的時間差異
谷歌搜索給出的答案:時區問題,通過谷歌很久無法打開網頁只能大約看到 !TZ='Asia/Shanghai' && ls 解決但實際上 !TZ='Asia/Shanghai' && ls這條命令只是指在你的ftp登陸後看本地文件的。截圖如下:
可見上傳上傳到ftp的文件看起來和你本地的文件有8個小時的時差。
解決辦法:首先將本地服務器的時區改成你知道的
[root@localhost ~]# tzselect Please identify a location so that time zone rules can be set correctly. Please select a continent or ocean. 1) Africa 2) Americas 3) Antarctica 4) Arctic Ocean 5) Asia 6) Atlantic Ocean 7) Australia 8) Europe 9) Indian Ocean 10) Pacific Ocean 11) none - I want to specify the time zone using the Posix TZ format. #?
這裏我選亞洲
#? 5 Please select a country. 1) Afghanistan 18) Israel 35) Palestine 2) Armenia 19) Japan 36) Philippines 3) Azerbaijan 20) Jordan 37) Qatar 4) Bahrain 21) Kazakhstan 38) Russia 5) Bangladesh 22) Korea (North) 39) Saudi Arabia 6) Bhutan 23) Korea (South) 40) Singapore 7) Brunei 24) Kuwait 41) Sri Lanka 8) Cambodia 25) Kyrgyzstan 42) Syria 9) China 26) Laos 43) Taiwan 10) Cyprus 27) Lebanon 44) Tajikistan 11) East Timor 28) Macau 45) Thailand 12) Georgia 29) Malaysia 46) Turkmenistan 13) Hong Kong 30) Mongolia 47) United Arab Emirates 14) India 31) Myanmar (Burma) 48) Uzbekistan 15) Indonesia 32) Nepal 49) Vietnam 16) Iran 33) Oman 50) Yemen 17) Iraq 34) Pakistan
這裏選擇中國9)然後選擇地區beijing,guangdong,shanghai,etc 1)
#? 9 Please select one of the following time zone regions. 1) east China - Beijing, Guangdong, Shanghai, etc. 2) Heilongjiang (except Mohe), Jilin 3) central China - Sichuan, Yunnan, Guangxi, Shaanxi, Guizhou, etc. 4) most of Tibet & Xinjiang 5) west Tibet & Xinjiang #? 1 The following information has been given: China east China - Beijing, Guangdong, Shanghai, etc. Therefore TZ='Asia/Shanghai' will be used. Local time is now: Mon Jan 13 14:55:45 CST 2014. Universal Time is now: Mon Jan 13 06:55:45 UTC 2014. Is the above information OK? 1) Yes 2) No
選擇Yes 1)
#? 1 You can make this change permanent for yourself by appending the line TZ='Asia/Shanghai'; export TZ to the file '.profile' in your home directory; then log out and log in again. Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts: Asia/Shanghai
再將時區文件cp到/etc/localtime
[root@localhost ~]# date Mon Jan 13 15:02:04 CST 2014 [root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime cp: overwrite `/etc/localtime'? y [root@localhost ~]# date Mon Jan 13 15:02:30 CST 2014 [root@localhost ~]# ls -l total 60 -rw-r--r-- 1 root root 3 Jan 13 11:02 11 -rw-------. 1 root root 1027 Sep 23 19:20 anaconda-ks.cfg -rwxr-xr-x 1 root root 2094 Sep 30 19:22 a.sh -rwxr-xr-x 1 root root 5684 Aug 29 01:02 centos6.x_init.sh -rw-r--r-- 1 root root 9990 Dec 25 11:02 cpu.log -rw-r--r--. 1 root root 15478 Sep 23 19:20 install.log -rw-r--r--. 1 root root 4169 Sep 23 19:18 install.log.syslog -rw-r--r-- 1 root root 91 Sep 30 19:57 resolv.conf
最後一步:
lftp [email protected]:/dbbackup/test> set -a ftp:timezone 'Asia/Shanghai'
設置和你本地的時區相同就好了,如果你知道服務器上設置的時區的話那麼只需要做最後一步就可以了。
好了 現在截圖查看ftp上的文件的時間