![如何在应用新更新之前备份 DST 配置?](https://linux22.com/image/211572/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BA%94%E7%94%A8%E6%96%B0%E6%9B%B4%E6%96%B0%E4%B9%8B%E5%89%8D%E5%A4%87%E4%BB%BD%20DST%20%E9%85%8D%E7%BD%AE%EF%BC%9F.png)
要检查时区的“夏令时”配置,我们可以使用以下命令: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