要检查时区的“夏令时”配置,我们可以使用以下命令:zdump -v <timezone>
但是有时一个国家/地区的政策会发生变化。可以通过此命令下载并应用新更新:zic <timezone>
例如(这只是一个示例,澳大利亚没有任何更改):
[root@test DST]# zdump -v Australia/Canberra | grep '2023'
Australia/Canberra Sat Apr 1 15:59:59 2023 UTC = Sun Apr 2 02:59:59 2023 AEDT isdst=1 gmtoff=39600
Australia/Canberra Sat Apr 1 16:00:00 2023 UTC = Sun Apr 2 02:00:00 2023 AEST isdst=0 gmtoff=36000
Australia/Canberra Sat Sep 30 15:59:59 2023 UTC = Sun Oct 1 01:59:59 2023 AEST isdst=0 gmtoff=36000
Australia/Canberra Sat Sep 30 16:00:00 2023 UTC = Sun Oct 1 03:00:00 2023 AEDT isdst=1 gmtoff=39600
[root@test DST]# zic australasia
[root@test DST]# zdump -v Australia/Canberra | grep '2023'
Australia/Canberra Sat Apr 2 16:59:59 2023 UTC = Sun Apr 2 02:59:59 2023 AEDT isdst=1 gmtoff=39600
Australia/Canberra Sat Apr 2 17:00:00 2023 UTC = Sun Apr 2 02:00:00 2023 AEST isdst=0 gmtoff=36000
Australia/Canberra Sat Sep 29 16:59:59 2023 UTC = Sun Oct 1 01:59:59 2023 AEST isdst=0 gmtoff=36000
Australia/Canberra Sat Sep 29 17:00:00 2023 UTC = Sun Oct 1 03:00:00 2023 AEDT isdst=1 gmtoff=39600
如果出现错误并且我想恢复更改怎么办?有什么方法可以备份以前的配置然后应用新的更改吗?如果可以进行备份那么我该如何恢复它?
答案1
从man tzfile
:
... tzset(3) 使用的时区信息文件 ... 通常可以在 /usr/lib/zoneinfo 或 /usr/share/zoneinfo 目录之一下找到。
并man zic
说:
/usr/local/etc/zoneinfo Standard directory used for created files.
备份这两个目录将是一个好的开始:
for d in /usr/lib/zoneinfo /usr/share/zoneinfo /usr/local/etc/zoneinfo
do
[ -d "$d" ] && rsync -HAXa --delete "$d/" "$d.backup/"
done
如果稍后需要恢复:
for d in /usr/lib/zoneinfo /usr/share/zoneinfo /usr/local/etc/zoneinfo
do
[ -d "$d.backup" ] && rsync -HAXa --delete "$d.backup/" "$d/"
done