crontab 和脚本的组合使用,是我们对服务器文件定时进行备份的好工具,前不久设置的备份发现备份文件的时间跟 crontab 设置的不一样,相差了10个小时,想必是时区设置的问题,查看时区信息如下:
# timedatectl
Local time: Wed 2016-05-11 10:38:13 AEST
Universal time: Wed 2016-05-11 00:38:13 UTC
RTC time: Wed 2016-05-11 00:38:13
Time zone: Australia/Sydney (AEST, +1000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: no
Last DST change: DST ended at
Sun 2016-04-03 02:59:59 AEDT
Sun 2016-04-03 02:00:00 AEST
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2016-10-02 01:59:59 AEST
Sun 2016-10-02 03:00:00 AEDT
Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
解决办法,如 Warning 提示的,通过执行命令:
# timedatectl set-local-rtc 0
完成之后再备份的文件创建时间就跟 crontab 里设置的一致了。