您的位置:首页 > 编程语言 > PHP开发

lftp上传备份文件关于时区的问题 推荐

2014-01-13 15:07 393 查看
要求:写这篇博文是因为今天公司要求上传数据库备份文件到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 crmtest@192.168.1.100:/dbbackup/test> set -a ftp:timezone 'Asia/Shanghai'
设置和你本地的时区相同就好了,如果你知道服务器上设置的时区的话那么只需要做最后一步就可以了。
好了 现在截图查看ftp上的文件的时间


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息