2011年6月14日星期二

rsync delete 参数

抄的抄的,原文见: http://superuser.com/questions/156664/rsync-delete-options
我好奇的是什么时候才需要考虑具体的delete方式。

--del/--delete_during Deletes files from the destination dir as they are copied (saves memory compared to --delete-before: --delete-before makes a separate scan to look for deleteables)
--delete Deletes files in the destination directory if they don't exist in the source directory.
--delete-before Delete files in the destination directory before coping file-with-same-name from source directory
--delete-during Delete files in the destination directory WHILE copying file-with-same-name from source directory
--delete-delay Mark deletes during transfer, but wait until transfer is complete
--delete-after Receiver deletes after transfer, not before...If some other part of the rsync moved extra files elsewhere, you'd want this instead of --delete-delay, because --delete-delay decides what its going to delete in the middle of transfer, whereas --delete-after checks the directory for files that should be deleted AFTER everything is finished.
--delete-excluded Deletes files from the destination directory that are explicitly excluded from transferring from the source directory.


The point of rsync is not copying, it is archiving. This is an important distinction. Processing deleted/changed files is critical, and in many cases nuanced.

Most of the other options are space or performance related. When you delete the files is important if you want to make sure the transfer is successful before you do anything, but if your device is too small to handle 2 copies of all the information, you need to delete as you go, etc. It's a little wacky because of it's long history across multiple platforms: some options have been added so that people who were used to certain behaviour wouldn't be confused.

2011年6月1日星期三

linux的系统时间与硬件时间

用了 opensuse 11.4 后发现系统时间一直比当前时间快8个小时,明显是时区有问题,但是/etc/localtime 又没有错误,今天查了查资料,搞清楚了几个概念。
1 GMT:格林威治时间。基本可以理解为一个标准时间,时区的原点,按照经线将地球分为24个时区。
2 UTC:世界协调时间。由于地球不是正圆的,自传速度也不一样,因此按照经线来均分地球时区有些不太精确。此时间相当于对GMT的修正,实际还是GMT时间。中国位于东8区,又称为CST(China Standard Time) CST时间 = UTC时间 + 8小时。
3 硬件时间:即通过电池在BIOS里记录的时间。Linux 对此时间的判断有两种可能:a 该时间表示本地时间;b 该时间表示 UTC 时间。Linux启动时会读取硬件时间,并根据 /etc/sysconfig/clock 中的 HWCLOCK 判断该时间记录的是本地时间还是 UTC 时间。
4 系统时间:就是 Linux 系统中显示的本地时间,该时间取决于系统开机后读取的时间以及当前的时区设置。时区配置文件为 /etc/localtime。/usr/share/zoneinfo 下保存了所有时区的配置文件,找个合适的,复制到 /etc/localtime 就可以了。

有了以上概念就不难理解了,在时区配置没有问题的情况下,一定是 Linux 在启动时读取硬件时间出了问题。只要将硬件时钟配置正确,并让 Linux 正确的读出来就问题就可以解决了。考虑到 windows 在启动时会将硬件时间设定为系统时间,因此 Linux 最好也采用此配置,否则启动 windows 后,windows 时钟可能会不正确。另外,系统时间是本地时间,而硬件时间则是 UTC 时间,看起来也不舒服。

修正方式如下:

方法1,读取硬件时间作为本地时间
1 hwclock --localtime 读取硬件时间。
2 如果要将该时间设置为系统时间,则将该时间写回系统 hwclock --localtime --hctosys,这时系统时间应该就变正确了
3 对于openSUSE12.2之前的版本:修改/etc/sysconfig/clock 中的HWCLOCK,由--utc 为 --localtime 否则下次重启还会出现问题。对于openSUSE 12.2:修改/etc/adjtime 将第三行从UTC更改为LOCAL。

办法 2,直接修改系统时间
1 date -s 设置系统时间
2 将系统时间写回硬件时钟 hwclock --localtime --systohc
3 修改/etc/sysconfig/clock


查看和设置时间的几个例子:

1 显示本地时间
# date
Thu Jun 2 21:48:44 CST 2011

2 查看硬件时间(指定硬件时间即为本地时间)
# hwclock --localtime
Thu Jun 2 21:48:47 2011 -0.239341 seconds

3 查看硬件时间 (指定硬件时间为 UTC 时间,则会对该时间+8,转换为本地时间后再显示出来)
# hwclock --utc
Fri Jun 3 05:48:49 2011 -0.125543 seconds

4 指明硬件时间为本地时间,并将该时间设置为系统时间
# hwclock --localtime --hctosys

5 指明硬件时间为本地时间,并将系统时间写回到 BIOS 中
# hwclock --localtime --systohc