阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

135次阅读
没有评论

共计 3149 个字符,预计需要花费 8 分钟才能阅读完成。

要求:写这篇博文是因为今天公司要求上传数据库备份文件到 ftp 服务器,在进入 ftp 服务器后使用 ls 命令要求看到的文件时间戳不改变?

解答:之前本人使用的上传方法是 ftp 无法做到,之后使用 lftp 可以保证原上传文件的时间戳不改变但是再一次出现问题

问题:上传到 ftp 服务器上的文件与本地文件存在几个小时的时间差异

谷歌搜索给出的答案:时区问题,通过谷歌很久无法打开网页只能大约看到 !TZ=’Asia/Shanghai’ && ls 解决但实际上 !TZ=’Asia/Shanghai’ && ls 这条命令只是指在你的 ftp 登陆后看本地文件的。截图如下:

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

可见上传上传到 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 上的文件的时间

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

LFTP 的详细介绍 :请点这里
LFTP 的下载地址 :请点这里

相关阅读:

Ubuntu 上用 LFTP 和 cRON 实现每天自动备份到 FTP 服务器 http://www.linuxidc.com/Linux/2009-10/22063.htm

Linux lftp 乱码解决 http://www.linuxidc.com/Linux/2008-09/15468.htm

Linux lftp 乱码解决及使用书签的方法 http://www.linuxidc.com/Linux/2011-04/34367.htm

LFTP 软件详解 http://www.linuxidc.com/Linux/2013-09/90112.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计3149字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中