出售域名

第 10 章 数据管理

目录

10.1. 共享,拷贝和存档
10.1.1. 存档和压缩工具
10.1.2. 复制和同步工具
10.1.3. 归档语法
10.1.4. 复制语法
10.1.5. 查找文件的语法
10.1.6. 归档媒体
10.1.7. 可移动存储设备
10.1.8. 选择用于分享数据的文件系统
10.1.9. 网络上的数据分享
10.2. 备份和恢复
10.2.1. 实用备份套件
10.2.2. 一个系统备份的脚本例子
10.2.3. 用于备份数据的复制脚本
10.3. 数据安全基础
10.3.1. GnuPG 密钥管理
10.3.2. 在文件上使用 GnuPG
10.3.3. 在 Mutt 中使用 GnuPG
10.3.4. 在 vim 中使用 GnuPG
10.3.5. MD5 校验和
10.4. 源代码合并工具
10.4.1. 从源代码文件导出差异
10.4.2. Merging updates for source files
10.4.3. Updating via 3-way-merge
10.5. Version control systems
10.5.1. Comparison of VCS commands
10.6. Git
10.6.1. 配置 Git 客户端
10.6.2. Git 参考
10.6.3. Git 命令
10.6.4. 用于 Subversion 仓库的 Git
10.6.5. 记录配置历史的 Git
10.7. CVS
10.7.1. Configuration of CVS repository
10.7.2. Local access to CVS
10.7.3. Remote access to CVS with pserver
10.7.4. Remote access to CVS with ssh
10.7.5. Importing a new source to CVS
10.7.6. File permissions in CVS repository
10.7.7. Work flow of CVS
10.7.8. Latest files from CVS
10.7.9. Administration of CVS
10.7.10. Execution bit for CVS checkout
10.8. Subversion
10.8.1. Subversion 存储库的配置
10.8.2. 通过 Apache2 服务器访问 Subversion
10.8.3. Local access to Subversion by group
10.8.4. 通过 SSH 远程访问 Subversion
10.8.5. Subversion 目录结构
10.8.6. 往 Subversion 里导入一个新的源
10.8.7. Subversion 工作流

以下是关于在 Debian 系统上管理二进制和文本数据的工具及其相关提示。

[警告] 警告

The uncoordinated write access to actively accessed devices and files from multiple processes must not be done to avoid the race condition. File locking mechanisms using flock(1) may be used to avoid it.

数据的安全和它的受控共享有如下几个方面。

  • 存档文件的建立

  • 远程存储访问

  • 复制

  • 跟踪修改历史

  • 促进数据共享

  • 防止未经授权的文件访问

  • 检测未经授权的文件修改

这些可以通过使用工具集来实现。

  • 存档和压缩工具

  • 复制和同步工具

  • 网络文件系统

  • 移动存储媒介

  • 安全 shell

  • 认证体系

  • 版本控制系统工具

  • Hash and cryptographic encryption tools

以下是 Debian 系统上可用的存档和压缩工具的预览。

表 10.1. 存档和压缩工具列表

软件包 流行度 大小 扩展名 命令 描述
tar V:901, I:999 2770 .tar tar(1) 标准的归档工具(默认)
cpio V:298, I:998 720 .cpio cpio(1) Unix System V 风格的归档器,与 find(1) 一起使用
binutils V:196, I:721 22939 .ar ar(1) 创建静态库的归档工具
fastjar V:6, I:58 171 .jar fastjar(1) Java 归档工具(类似 zip)
pax V:17, I:56 170 .pax pax(1) 新的 POSIX 归档工具,介于 tarcpio 之间
gzip V:874, I:999 225 .gz gzip(1), zcat(1), … GNU LZ77 压缩工具(默认)
bzip2 V:251, I:931 84 .bz2 bzip2(1), bzcat(1), … Burrows-Wheeler block-sorting 压缩工具有着比 gzip(1) 更高的压缩率 (跟 gzip 有着相似的语法但速度比它慢)
lzma V:5, I:66 144 .lzma lzma(1) LZMA 压缩工具有着比 gzip(1) 更高的压缩率(不推荐)
xz-utils V:315, I:952 511 .xz xz(1), xzdec(1), … XZ 压缩工具有着比 bzip2(1) 更高的压缩率(压缩速度慢于 gzip 但是比 bzip2 快; LZMA 压缩工具的替代品)
p7zip V:32, I:154 866 .7z 7zr(1), p7zip(1) 有着更高压缩率的 7-zip 文件归档器(LZMA 压缩)
p7zip-full V:181, I:528 4215 .7z 7z(1), 7za(1) 有着更高压缩率的 7-Zip 文件归档器(LZMA 压缩和其他)
lzop V:5, I:42 92 .lzo lzop(1) LZO 压缩工具有着比 gzip(1) 更高的压缩和解压缩速度 (跟 gzip 有着相似的语法但压缩率比它低)
zip V:49, I:389 572 .zip zip(1) InfoZip:DOS 归档器和压缩工具
unzip V:318, I:790 506 .zip unzip(1) InfoZIP:DOS 解档器和解压缩工具

[警告] 警告

除非你知道将会发生什么,否则不要设置 "$TAPE" 变量。它会改变 tar(1) 的行为。

[注意] 注意

gzipped tar(1) 归档器用于扩展名是 ".tgz" 或者 ".tar.gz" 的文件。

[注意] 注意

xz-compressed tar(1) 归档器用于扩展名是 ".txz" 或者 ".tar.xz" 的文件。

[注意] 注意

FOSS 工具,例如 tar(1),中的主流压缩方法已经按如下所示的迁移: gzipbzip2xz

[注意] 注意

cp(1),scp(1)tar(1) 工具可能并不适用于一些特殊的文件。cpio(1) 工具的适用范围是最广的。

[注意] 注意

cpio(1) is designed to be used with find(1) and other commands and suitable for creating backup scripts since the file selection part of the script can be tested independently.

[注意] 注意

Libreoffice 数据文件的内部结构是 ".jar" 文件。

以下是 Debian 系统上的可用的简单复制和备份工具的预览。


在复制文件的时候, rsync(8) 比其他工具提供了更多的特性。

  • 差分传输算法只会发送源文件与已存在的目标文件之间的差异部分

  • 快速检查算法 (默认) 会查找大小或者最后的修改时间有变化的文件

  • "--exclude" 和 "--exclude-from" 选项类似于 tar(1)

  • "a trailing slash on the source directory" syntax that avoids creating an additional directory level at the destination.

[提示] 提示

Execution of the bkup script mentioned in 第 10.2.3 节 “用于备份数据的复制脚本” with the "-gl" option under cron(8) should provide very similar functionality as Plan9's dumpfs for the static data archive.

[提示] 提示

Version control system (VCS) tools in 表 10.11 “List of version control system tools” can function as the multi-way copy and synchronization tools.

如下是用不同的工具复制整个 "./source" 目录中的内容。

rsync(8):

# cd ./source; rsync -aHAXSv . /dest
# cd ./source; rsync -aHAXSv . [email protected]:/dest

You can alternatively use "a trailing slash on the source directory" syntax.

# rsync -aHAXSv ./source/ /dest
# rsync -aHAXSv ./source/ [email protected]:/dest

或者,如下所示。

# cd ./source; find . -print0 | rsync -aHAXSv0 --files-from=- . /dest
# cd ./source; find . -print0 | rsync -aHAXSv0 --files-from=- . [email protected]:/dest

GNU cp(1) 和 openSSH scp(1):

# cd ./source; cp -a . /dest
# cd ./source; scp -pr . [email protected]:/dest

GNU tar(1):

# (cd ./source && tar cf - . ) | (cd /dest && tar xvfp - )
# (cd ./source && tar cf - . ) | ssh [email protected] '(cd /dest && tar xvfp - )'

cpio(1):

# cd ./source; find . -print0 | cpio -pvdm --null --sparse /dest

你能够在所有包含 "." 的例子里用 "foo" 替代 ".",这样就可以从 "./source/foo" 目录复制文件到 "/dest/foo" 目录。

You can substitute "." with the absolute path "/path/to/source/foo" for all examples containing "." to drop "cd ./source;". These copy files to different locations depending on tools used as follows.

  • "/dest/foo": rsync(8), GNU cp(1), 和 scp(1)

  • "/dest/path/to/source/foo": GNU tar(1), 和 cpio(1)

[提示] 提示

rsync(8) 和 GNU cp(1) 可以用 "-u" 选项来忽略接受端上更新的文件。

find(1) is used to select files for archive and copy commands (see 第 10.1.3 节 “归档语法” and 第 10.1.4 节 “复制语法”) or for xargs(1) (see 第 9.3.9 节 “使用文件循环来重复一个命令”). This can be enhanced by using its command arguments.

以下是 find(1)基本语法的总结。

  • find 条件参数的运算规则是从左到右。

  • This evaluation stops once its outcome is determined.

  • “逻辑 OR" (由条件之间的 "-o" 参数指定的)优先级低于 "逻辑 AND" (由 "-a" 参数指定或者条件之间没有任何参数)。

  • ”逻辑 NOT" (由条件前面的 "!" 指定) 优先级高于 “逻辑 AND”。

  • "-prune" always returns logical TRUE and, if it is a directory, searching of file is stopped beyond this point.

  • "-name" matches the base of the filename with shell glob (see 第 1.5.6 节 “Shell 通配符”) but it also matches its initial "." with metacharacters such as "*" and "?". (New POSIX feature)

  • "-regex" matches the full path with emacs style BRE (see 第 1.6.2 节 “正则表达式”) as default.

  • "-size" matches the file based on the file size (value precedented with "+" for larger, precedented with "-" for smaller)

  • "-newer" 参数匹配比参数名中指定的文件还要新的文件。

  • "-print0" 参数总是返回逻辑 TRUE 并将完整文件名 (null terminated) 打印到标准输出设备上。

如下是 find(1) 语法格式。

# find /path/to \
    -xdev -regextype posix-extended \
    -type f -regex ".*\.cpio|.*~" -prune -o \
    -type d -regex ".*/\.git" -prune -o \
    -type f -size +99M -prune -o \
    -type f -newer /path/to/timestamp -print0

这些命令会执行如下动作。

  1. 查找 "/path/to" 下的所有文件

  2. Globally limit its search within its starting filesystem and uses ERE (see 第 1.6.2 节 “正则表达式”) instead

  3. Exclude files matching regex of ".*\.cpio" or ".*~" from search by stop processing

  4. Exclude directories matching regex of ".*/\.git" from search by stop processing

  5. Exclude files larger than 99 Megabytes (units of 1048576 bytes) from search by stop processing

  6. Print filenames which satisfy above search conditions and are newer than "/path/to/timestamp"

Please note the idiomatic use of "-prune -o" to exclude files in the above example.

[注意] 注意

对于非 Debian 系的 Unix-like 系统,有些参数可能不被 find(1) 命令所支持。在这种情况下,应该考虑调整匹配方法并用 "-print" 替代 "-print0"。你可能同样需要更改其他相关的命令。

为重要的数据存档寻找 存储设备 时,你应该注意它们的局限性。对于小型的个人数据备份,我使用品牌公司的 CD-R 和 DVD-R 然后把它放在阴凉、干燥、清洁的地方。(专业的一般使用磁带存档介质)

[注意] 注意

防火安全 是对于纸质文档来说的,大多数的计算机数据存储媒介耐热性比纸差。我经常依赖存储在多个安全地点的加密拷贝。

网上(主要是来源于供应商信息)可以查看存储介质的最大使用寿命。

  • 大于100年:用墨水的无酸纸

  • 100年:光盘存储(CD/DVD,CD/DVD-R)

  • 30年:磁带存储(磁带,软盘)

  • 20年:相变光盘存储(CD-RW)

这不包括由于人为导致的机械故障等等。

网上(主要来源于供应商信息)可以查看存储介质的最大的写次数。

  • 大于250,000次:硬盘驱动器

  • 大于10,000次:闪存

  • 1,000次:CD/DVD-RW

  • 1次:CD/DVD-R,纸

[小心] 小心

这里的存储寿命和写次数的数据不应该被用来决定任何用于关键数据的存储媒介,请翻阅制造商提供的特定产品的说明。

[提示] 提示

因为 CD/DVD-R 和 纸只能写一次,它们从根本上阻止了因为重写导致的数据意外丢失。这是优点!

[提示] 提示

如果你需要更快更频繁的进行大数据备份,那么通过高速网络连接的远端主机上的硬盘来实现备份,可能是唯一可行的方法。

可移动存储设备可能是以下的任何一种。

它们可以通过以下的方式来进行连接。

像 GNOME 和 KDE 这样的现代桌面环境能够在 "/etc/fstab" 文件中没有匹配条目的时候,自动挂载这些可移动设备。

  • udisks 包提供了守护进程和相关的实用程序来挂载和卸载这些设备。

  • D-bus creates events to initiate automatic processes.

  • PolicyKit provides required privileges.

[提示] 提示

Automounted devices may have the "uhelper=" mount option which is used by umount(8).

[提示] 提示

只有当这些可移动设备没有在 "/etc/fstab" 文件中列出时,桌面环境下才会自动挂载。

现代桌面环境下的挂载点被选为 "/media/<disk_label>",它可以被如下所示的来定制。

  • FAT 格式的文件系统使用 mlabel(1) 命令

  • ISO9660 文件系统使用带有 "-V" 选项的 genisoimage(1) 命令

  • ext2/ext3/ext4 文件系统使用带有 "-L" 选项的 tune2fs(1) 命令

[提示] 提示

挂载时可能需要提供编码选项(参见 第 8.3.6 节 “文件名编码”)。

[提示] 提示

在图形界面菜单上移除文件系统,可能会移除它的动态设备节点例如 "/dev/sdc"。如果你想要保留它的设备节点,你应该在命令行提示符上输入 umount(8) 命令来卸载它。

当你通过可移动存储设备与其他系统分享数据的时候,你应该先把它格式化为被两种操作系统都支持的通用的 文件系统。下面是文件系统的列表。


[提示] 提示

查看第 9.8.1 节 “Removable disk encryption with dm-crypt/LUKS”来获得关于使用设备级加密的跨平台的数据共享的信息。

FAT 文件系统被绝大多数的现代操作系统支持,它对于通过可移动硬盘进行的数据交换是非常有用的。

当格式化像装有 FAT 文件系统的跨平台数据共享的可移动设备时,以下应该是保险的选择。

当使用 FAT 或 ISO9660 文件系统分享数据时,如下是需要注意的安全事项。

  • tar(1),或cpio(1)命令压缩文件,目地是为了保留文件名,符号链接,原始的文件权限和文件所有者信息。

  • split(1) 命令把压缩文件分解成若干小于 2GiB的小文件,使其免受文件大小限制。

  • 加密压缩文件保护其内容免受未经授权的访问。

[注意] 注意

因为 FAT 文件系统的设计,最大的文件大小为 (2^32 - 1) bytes = (4GiB -1 byte)。对于一些老旧的 32 位系统上的应用程序而言,最大的文件大小甚至更小(2^31 -1) bytes = (2GiB -1 byte)。Debian 没有遇到后者的问题。

[注意] 注意

微软系统本身并不建议在超过 200MB 的分区或者驱动器上使用 FAT。他们的 " Overview of FAT, HPFS, and NTFS File Systems 这篇文章突出显示了微软系统的缺点,例如低效的磁盘空间利用。当然了,我们在 Linux 系统上还是应该使用 ext4 文件系统。

[提示] 提示

有关文件系统和访问文件系统的更多信息,请参考 "Filesystems HOWTO"。

我们都熟知计算机有时会出问题,或者由于人为的错误导致系统和数据损坏。备份和恢复操作是成功的系统管理中非常重要的一部分。可能有一天你的电脑就会出问题。

[提示] 提示

保持你的备份系统简洁并且经常备份你的系统,有备份数据比你采用的备份方法的技术先进要重要的多。

有3个关键的因素决定实际的备份和恢复策略。

  1. 知道要备份和恢复什么。

    • 你自己创建的数据文件:在 "~/" 下的数据

    • 你使用的应用程序创建的数据文件:在 "/var/" 下的数据(除了 "/var/cache/","/var/run/" 和 "/var/tmp/")

    • 系统配置文件:在 "/etc/” 下的数据

    • 本地软件:在 "/usr/local/" 或 "/opt/" 下的数据

    • System installation information: a memo in plain text on key steps (partition, …)

    • Proven set of data: confirmed by experimental recovery operations in advance

  2. 知道怎样去备份和恢复。

    • 安全的数据存储:保护其免于覆盖和系统故障

    • 经常备份:有计划的备份

    • Redundant backup: data mirroring

    • Fool proof process: easy single command backup

  3. 评估涉及的风险和成本。

    • Value of data when lost

    • 备份所需的资源:人力,硬件,软件,…

    • Failure mode and their possibility

[注意] 注意

除非你知道自己做的是什么,否则不要备份 /proc, /sys, /tmp, 和 /run 目录下的伪文件系统(参见 第 1.2.12 节 “procfs 和 sysfs”第 1.2.13 节 “tmpfs”)。它们是庞大且无用的数据。

至于安全的数据存储,数据至少是应该在不同的磁盘分区上最好是在不同的磁盘和机器上,来承受文件系统发生的损坏。重要的数据最好存储在只能写一次的媒介上例如 CD/DVD-R 来防止覆盖事故。(参见 第 9.7 节 “二进制数据” 怎样在 shell 命令行写入存储媒介。GNOME 桌面图形环境可以让你轻松的通过菜单:“位置 → CD/DVD 刻录”来实现写入操作。)

[注意] 注意

当备份数据的时候,你可能希望停止一些应用程序的守护进程例如 MTA(参见第 6.3 节 “邮件传输代理 (MTA)”)。

[注意] 注意

你应该格外小心地备份和恢复身份认证相关的数据文件例如 "/etc/ssh/ssh_host_dsa_key", "/etc/ssh/ssh_host_rsa_key", "~/.gnupg/*", "~/.ssh/*", /etc/passwd", "/etc/shadow", "/etc/fetchmailrc", "popularity-contest.conf", "/etc/ppp/pap-secrets" 和 "/etc/exim4/passwd.client/"。 这些数据中的有一些文件是不能通过向系统输入同样的字符串来再生的。

[注意] 注意

如果你以用户进程的方式执行 cron job,你必须存储文件到 "/var/spool/cron/crontabs" 目录并且重启 cron(8)。参见第 9.3.14 节 “定时任务安排”来获得关于 cron(8)crontab(1) 的信息。

以下是 Debian 系统上值得注意的实用备份程序套件的列表。


备份工具有各自的专用的用途。

  • Mondo Rescue is a backup system to facilitate restoration of complete system quickly from backup CD/DVD etc. without going through normal system installation processes.

  • sbackupkeep 软件包提供了易于桌面用户使用的 GUI 前端,用于定期备份用户数据。同样的功能可以通过一个简单的脚本(第 10.2.2 节 “一个系统备份的脚本例子”)和 cron(8) 来实现。

  • BaculaAmandaBackupPC 是全功能的备份实用套件,主要用于联网的定期备份。

第 10.1.1 节 “存档和压缩工具”第 10.1.2 节 “复制和同步工具” 描述的基础工具能够通过自定义脚本来帮助系统备份。这些脚本的功能可以通过如下的工具来增强。

  • obnam 软件包能够增量备份(远程)。

  • rdiff-backup 软件包能够增量备份(远程)。

  • The dump package helps to archive and restore the whole filesystem incrementally and efficiently.

[提示] 提示

参见 "/usr/share/doc/dump/" 和 "Is dump really deprecated?" 来了解 dump 程序。

对于运行 unstable 套件的个人 Debian 桌面系统来说,只需要保护个人数据和关键数据。我不管怎样每年都会重新安装一次系统。因此没理由去备份整个系统或者安装全功能的备份实用程序。

我使用简单的脚本来制作用于备份的压缩文件并用 GUI 界面把它烧写到 CD/DVD 里。以下是关于这个的脚本例子。

#!/bin/sh -e
# Copyright (C) 2007-2008 Osamu Aoki <[email protected]>, Public Domain
BUUID=1000; USER=osamu # UID and name of a user who accesses backup files
BUDIR="/var/backups"
XDIR0=".+/Mail|.+/Desktop"
XDIR1=".+/\.thumbnails|.+/\.?Trash|.+/\.?[cC]ache|.+/\.gvfs|.+/sessions"
XDIR2=".+/CVS|.+/\.git|.+/\.svn|.+/Downloads|.+/Archive|.+/Checkout|.+/tmp"
XSFX=".+\.iso|.+\.tgz|.+\.tar\.gz|.+\.tar\.bz2|.+\.cpio|.+\.tmp|.+\.swp|.+~"
SIZE="+99M"
DATE=$(date --utc +"%Y%m%d-%H%M")
[ -d "$BUDIR" ] || mkdir -p "BUDIR"
umask 077
dpkg --get-selections \* > /var/lib/dpkg/dpkg-selections.list
debconf-get-selections > /var/cache/debconf/debconf-selections

{
find /etc /usr/local /opt /var/lib/dpkg/dpkg-selections.list \
     /var/cache/debconf/debconf-selections -xdev -print0
find /home/$USER /root -xdev -regextype posix-extended \
  -type d -regex "$XDIR0|$XDIR1" -prune -o -type f -regex "$XSFX" -prune -o \
  -type f -size  "$SIZE" -prune -o -print0
find /home/$USER/Mail/Inbox /home/$USER/Mail/Outbox -print0
find /home/$USER/Desktop  -xdev -regextype posix-extended \
  -type d -regex "$XDIR2" -prune -o -type f -regex "$XSFX" -prune -o \
  -type f -size  "$SIZE" -prune -o -print0
} | cpio -ov --null -O $BUDIR/BU$DATE.cpio
chown $BUUID $BUDIR/BU$DATE.cpio
touch $BUDIR/backup.stamp

这是一个用 root 权限执行的脚本例子。

我建议你按照如下所示的去更改和执行这个脚本。

把事情简单化!

[提示] 提示

You can recover debconf configuration data with "debconf-set-selections debconf-selections" and dpkg selection data with "dpkg --set-selection <dpkg-selections.list".

对于目录树下面的数据集,"cp -a" 命令可以实现常规备份。

For the set of large non-overwritten static data under a directory tree such as the one under the "/var/cache/apt/packages/" directory, hardlinks with "cp -al" provide an alternative to the normal backup with efficient use of the disk space.

以下是一个用于数据备份的名为 bkup 的复制脚本。它把当前目录下的所有 (non-VCS) 文件复制到父目录下的指定目录中或者远程主机上。

#!/bin/sh -e
# Copyright (C) 2007-2008 Osamu Aoki <[email protected]>, Public Domain
fdot(){ find . -type d \( -iname ".?*" -o -iname "CVS" \) -prune -o -print0;}
fall(){ find . -print0;}
mkdircd(){ mkdir -p "$1";chmod 700 "$1";cd "$1">/dev/null;}
FIND="fdot";OPT="-a";MODE="CPIOP";HOST="localhost";EXTP="$(hostname -f)"
BKUP="$(basename $(pwd)).bkup";TIME="$(date  +%Y%m%d-%H%M%S)";BU="$BKUP/$TIME"
while getopts gcCsStrlLaAxe:h:T f; do case $f in
g)  MODE="GNUCP";; # cp (GNU)
c)  MODE="CPIOP";; # cpio -p
C)  MODE="CPIOI";; # cpio -i
s)  MODE="CPIOSSH";; # cpio/ssh
t)  MODE="TARSSH";; # tar/ssh
r)  MODE="RSYNCSSH";; # rsync/ssh
l)  OPT="-alv";; # hardlink (GNU cp)
L)  OPT="-av";;  # copy (GNU cp)
a)  FIND="fall";; # find all
A)  FIND="fdot";; # find non CVS/ .???/
x)  set -x;; # trace
e)  EXTP="${OPTARG}";; # hostname -f
h)  HOST="${OPTARG}";; # [email protected]
T)  MODE="TEST";; # test find mode
\?) echo "use -x for trace."
esac; done
shift $(expr $OPTIND - 1)
if [ $# -gt 0 ]; then
  for x in $@; do cp $OPT $x $x.$TIME; done
elif [ $MODE = GNUCP ]; then
  mkdir -p "../$BU";chmod 700 "../$BU";cp $OPT . "../$BU/"
elif [ $MODE = CPIOP ]; then
  mkdir -p "../$BU";chmod 700 "../$BU"
  $FIND|cpio --null --sparse -pvd ../$BU
elif [ $MODE = CPIOI ]; then
  $FIND|cpio -ov --null | ( mkdircd "../$BU"&&cpio -i )
elif [ $MODE = CPIOSSH ]; then
  $FIND|cpio -ov --null|ssh -C $HOST "( mkdircd \"$EXTP/$BU\"&&cpio -i )"
elif [ $MODE = TARSSH ]; then
  (tar cvf - . )|ssh -C $HOST "( mkdircd \"$EXTP/$BU\"&& tar xvfp - )"
elif [ $MODE = RSYNCSSH ]; then
  rsync -aHAXSv ./ "${HOST}:${EXTP}-${BKUP}-${TIME}"
else
  echo "Any other idea to backup?"
  $FIND |xargs -0 -n 1 echo
fi

This is meant to be command examples. Please read script and edit it by yourself before using it.

[提示] 提示

I keep this bkup in my "/usr/local/bin/" directory. I issue this bkup command without any option in the working directory whenever I need a temporary snapshot backup.

[提示] 提示

For making snapshot history of a source file tree or a configuration file tree, it is easier and space efficient to use git(7) (see 第 10.6.5 节 “记录配置历史的 Git”).

数据安全基础设施是数据加密,讯息摘要和签名工具的结合。


See 第 9.8 节 “数据加密提示” on dm-crypto and ecryptfs which implement automatic data encryption infrastructure via Linux kernel modules.

如下是 GNU 隐私卫士 基本的密钥管理命令。


Here is the meaning of the trust code.


如下命令上传我的 "1DD8D791" 公钥到主流的公钥服务器 "hkp://keys.gnupg.net"。

$ gpg --keyserver hkp://keys.gnupg.net --send-keys 1DD8D791

默认良好的公钥服务器在 "~/.gnupg/gpg.conf" (旧的位置在 "~/.gnupg/options")文件中设置,此文件包含了以下信息。

keyserver hkp://keys.gnupg.net

The following obtains unknown keys from the keyserver.

$ gpg --list-sigs --with-colons | grep '^sig.*\[User ID not found\]' |\
  cut -d ':' -f 5| sort | uniq | xargs gpg --recv-keys

There was a bug in OpenPGP Public Key Server (pre version 0.9.6) which corrupted key with more than 2 sub-keys. The newer gnupg (>1.2.1-2) package can handle these corrupted subkeys. See gpg(1) under "--repair-pks-subkey-bug" option.

md5sum(1) 提供了制作摘要文件的一个工具,它使用 rfc1321 里的方式制作摘要文件.

$ md5sum foo bar >baz.md5
$ cat baz.md5
d3b07384d113edec49eaa6238ad5ff00  foo
c157a79031e1c40f85931829bc5fc552  bar
$ md5sum -c baz.md5
foo: OK
bar: OK
[注意] 注意

MD5 校验和的 CPU 计算强度是比 GNU Privacy Guard (GnuPG) 加密签名要少的.在通常情况下,只有顶级的摘要文件才需要加密签名来确保数据完整性.

这里有许多源代码合并工具。如下的是我感兴趣的工具。

表 10.10. 源代码合并工具列表

软件包 流行度 大小 命令 说明
diffutils V:850, I:975 1319 diff(1) 逐行比较两个文件
diffutils V:850, I:975 1319 diff3(1) 逐行比较和合并三个文件
vim V:112, I:391 2366 vimdiff(1) 在 vim 中并排比较两个文件
patch V:104, I:937 191 patch(1) 给原文件打补丁
dpatch V:1, I:18 191 dpatch(1) 管理 Debian 软件包的系列补丁
diffstat V:23, I:190 65 diffstat(1) produce a histogram of changes by the diff
patchutils V:21, I:182 223 combinediff(1) create a cumulative patch from two incremental patches
patchutils V:21, I:182 223 dehtmldiff(1) extract a diff from an HTML page
patchutils V:21, I:182 223 filterdiff(1) extract or excludes diffs from a diff file
patchutils V:21, I:182 223 fixcvsdiff(1) fix diff files created by CVS that patch(1) mis-interprets
patchutils V:21, I:182 223 flipdiff(1) exchange the order of two patches
patchutils V:21, I:182 223 grepdiff(1) show which files are modified by a patch matching a regex
patchutils V:21, I:182 223 interdiff(1) show differences between two unified diff files
patchutils V:21, I:182 223 lsdiff(1) show which files are modified by a patch
patchutils V:21, I:182 223 recountdiff(1) recompute counts and offsets in unified context diffs
patchutils V:21, I:182 223 rediff(1) fix offsets and counts of a hand-edited diff
patchutils V:21, I:182 223 splitdiff(1) separate out incremental patches
patchutils V:21, I:182 223 unwrapdiff(1) demangle patches that have been word-wrapped
wiggle V:0, I:0 166 wiggle(1) apply rejected patches
quilt V:5, I:46 710 quilt(1) manage series of patches
meld V:13, I:42 3022 meld(1) compare and merge files (GTK)
dirdiff V:0, I:2 144 dirdiff(1) display differences and merge changes between directory trees
docdiff V:0, I:0 573 docdiff(1) compare two files word by word / char by char
imediff2 V:0, I:0 34 imediff2(1) interactive full screen 2-way merge tool
makepatch V:0, I:0 102 makepatch(1) generate extended patch files
makepatch V:0, I:0 102 applypatch(1) apply extended patch files
wdiff V:6, I:88 643 wdiff(1) display word differences between text files

Here is a summary of the version control systems (VCS) on the Debian system.

[注意] 注意

If you are new to VCS systems, you should start learning with Git, which is growing fast in popularity.


VCS is sometimes known as revision control system (RCS), or software configuration management (SCM).

Distributed VCS such as Git is the tool of choice these days. CVS and Subversion may still be useful to join some existing open source program activities.

Debian provides free VCS services via Debian Alioth service. It supports practically all VCSs. Its documentation can be found at http://wiki.debian.org/Alioth .

There are few basics for creating a shared access VCS archive.

Here is an oversimplified comparison of native VCS commands to provide the big picture. The typical command sequence may require options and arguments.


[小心] 小心

Invoking a git subcommand directly as "git-xyz" from the command line has been deprecated since early 2006.

[提示] 提示

If there is a executable file git-foo in the path specified by $PATH, entring "git foo" without hyphen to the command line invokes this git-foo. This is a feature of the git command.

[提示] 提示

GUI tools such as tkcvs(1) and gitk(1) really help you with tracking revision history of files. The web interface provided by many public archives for browsing their repositories is also quite useful, too.

[提示] 提示

Git can work directly with different VCS repositories such as ones provided by CVS and Subversion, and provides the local repository for local changes with git-cvs and git-svn packages. See git for CVS users, and 第 10.6.4 节 “用于 Subversion 仓库的 Git”.

[提示] 提示

Git has commands which have no equivalents in CVS and Subversion: "fetch", "rebase", "cherry-pick", …

Git 可以用来做本地和远程源代码管理的任何事情。这意味着,你能够在本地记录源代码修改,而不是必须要和远程仓库有网络连接。

参见下面内容。

git-gui(1)gitk(1) 命令使 Git 变得非常容易使用。

[警告] 警告

不要使用带空格的标签字符串。即使一些工具,如 gitk(1) 允许你使用它,但会阻碍其它 git 命令。

即使你的上游使用不同的版本控制系统,使用 git(1) 作为本地活动的版本控制系统,仍然是一个好的主意,因为 git 可以让你在没有上游网络连接的情况下,管理你的本地源代码树拷贝。这里有一些 git(1) 使用的包和命令。


[提示] 提示

With git(1), you work on a local branch with many commits and use something like "git rebase -i master" to reorganize change history later. This enables you to make clean change history. See git-rebase(1) and git-cherry-pick(1).

[提示] 提示

When you want to go back to a clean working directory without loosing the current state of the working directory, you can use "git stash". See git-stash(1).

你可以使用 Git 工具来手工记录按时间先后顺序的配置历史。这里是一个例子,让你练习记录"/etc/apt/" 内容。

$ cd /etc/apt/
$ sudo git init
$ sudo chmod 700 .git
$ sudo git add .
$ sudo git commit -a

提交配置,描述此次提交。

对配置文件进行修改。

$ cd /etc/apt/
$ sudo git commit -a

提交配置,说明提交,继续你的工作。

$ cd /etc/apt/
$ sudo gitk --all

你有全部的配置历史。

[注意] 注意

sudo(8) 是需要用于配置数据文件,任意文件权限的情况。 对于普通用户的配置数据,你需要省略 sudo

[注意] 注意

在上面例子里的 "chmod 700 .git" 命令,是用来保护文档数据不被未经授权的读访问。

[提示] 提示

要更加完整的建立配置历史记录,请参阅 etckeeper 包: 第 9.2.10 节 “记录配置文件的变更”

参见下面内容。

  • cvs(1)

  • "/usr/share/doc/cvs/html-cvsclient"

  • "/usr/share/doc/cvs/html-info"

  • "/usr/share/doc/cvsbook"

  • "info cvs"

Many public CVS servers provide read-only remote access to them with account name "anonymous" via pserver service. For example, Debian web site contents are maintained by webwml project via CVS at Debian alioth service. The following sets up "$CVSROOT" for the remote access to this CVS repository.

$ export CVSROOT=:pserver:[email protected]:/cvs/webwml
$ cvs login
[注意] 注意

Since pserver is prone to eavesdropping attack and insecure, write access is usually disable by server administrators.

The following sets up "$CVS_RSH" and "$CVSROOT" for the remote access to the CVS repository by webwml project with SSH.

$ export CVS_RSH=ssh
$ export CVSROOT=:ext:[email protected]:/cvs/webwml

You can also use public key authentication for SSH which eliminates the remote password prompt.

Here is an example of typical work flow using CVS.

Check all available modules from CVS project pointed by "$CVSROOT" by the following.

$ cvs rls
CVSROOT
module1
module2
...

Checkout "module1" to its default directory "./module1" by the following.

$ cd ~/path/to
$ cvs co module1
$ cd module1

按需修改里面的内容。

通过如下所示的命令来检查改变,其作用相当于使用 "diff -u [repository] [local]"。

$ cvs diff -u

你发现自己改坏了 "file_to_undo" 文件,而其他的文件都是好的。

Overwrite "file_to_undo" file with the clean copy from CVS by the following.

$ cvs up -C file_to_undo

Save the updated local source tree to CVS by the following.

$ cvs ci -m "Describe change"

Create and add "file_to_add" file to CVS by the following.

$ vi file_to_add
$ cvs add file_to_add
$ cvs ci -m "Added file_to_add"

Merge the latest version from CVS by the following.

$ cvs up -d

Watch out for lines starting with "C filename" which indicates conflicting changes.

Look for unmodified code in ".#filename.version".

Search for "<<<<<<<" and ">>>>>>>" in files for conflicting changes.

Edit files to fix conflicts as needed.

Add a release tag "Release-1" by the following.

$ cvs ci -m "last commit for Release-1"
$ cvs tag Release-1

Edit further.

Remove the release tag "Release-1" by the following.

$ cvs tag -d Release-1

Check in changes to CVS by the following.

$ cvs ci -m "real last commit for Release-1"

Re-add the release tag "Release-1" to updated CVS HEAD of main by the following.

$ cvs tag Release-1

Create a branch with a sticky branch tag "Release-initial-bugfixes" from the original version pointed by the tag "Release-initial" and check it out to "~/path/to/old" directory by the following.

$ cvs rtag -b -r Release-initial Release-initial-bugfixes module1
$ cd ~/path/to
$ cvs co -r Release-initial-bugfixes -d old module1
$ cd old
[提示] 提示

Use "-D 2005-12-20" (ISO 8601 date format) instead of "-r Release-initial" to specify particular date as the branch point.

Work on this local source tree having the sticky tag "Release-initial-bugfixes" which is based on the original version.

Work on this branch by yourself … until someone else joins to this "Release-initial-bugfixes" branch.

Sync with files modified by others on this branch while creating new directories as needed by the following.

$ cvs up -d

Edit files to fix conflicts as needed.

Check in changes to CVS by the following.

$ cvs ci -m "checked into this branch"

Update the local tree by HEAD of main while removing sticky tag ("-A") and without keyword expansion ("-kk") by the following.

$ cvs up -d -kk -A

Update the local tree (content = HEAD of main) by merging from the "Release-initial-bugfixes" branch and without keyword expansion by the following.

$ cvs up -d -kk -j Release-initial-bugfixes

Fix conflicts with editor.

Check in changes to CVS by the following.

$ cvs ci -m "merged Release-initial-bugfixes"

Make archive by the following.

$ cd ..
$ mv old old-module1-bugfixes
$ tar -cvzf old-module1-bugfixes.tar.gz old-module1-bugfixes
$ rm -rf old-module1-bugfixes
[提示] 提示

"cvs up" command can take "-d" option to create new directories and "-P" option to prune empty directories.

[提示] 提示

You can checkout only a sub directory of "module1" by providing its name as "cvs co module1/subdir".


Subversion is a recent-generation version control system replacing older CVS. It has most of CVS's features except tags and branches.

你需要安装 subversionlibapache2-svnsubversion-tools 软件包来搭建 Subversion 服务器。

这里给出使用 Subversion 及其原生客户端的典型工作流示例。

[提示] 提示

Client commands offered by the git-svn package may offer alternative work flow of Subversion using the git command. See 第 10.6.4 节 “用于 Subversion 仓库的 Git”.

查看如下所示的 URL "file:///srv/svn/project" 指向的 Subversion 项目上所有可用的模块。

$ svn list file:///srv/svn/project
module1
module2
...

按如下所示的签出 "module1/trunk" 到 "module1" 目录。

$ cd ~/path/to
$ svn co file:///srv/svn/project/module1/trunk module1
$ cd module1

按需修改里面的内容。

通过如下所示的命令来检查改变,其作用相当于使用 "diff -u [repository] [local]"。

$ svn diff

你发现自己改坏了 "file_to_undo" 文件,而其他的文件都是好的。

按如下所示的用 Subversion 中的干净副本来覆盖 "file_to_undo" 文件。

$ svn revert file_to_undo

按如下所示的把已经更新了的本地源目录树保存到 Subversion。

$ svn ci -m "Describe change"

按如下所示的创建 "file_to_add" 文件并把它添加到 Subversion。

$ vi file_to_add
$ svn add file_to_add
$ svn ci -m "Added file_to_add"

Merge the latest version from Subversion by the following.

$ svn up

Watch out for lines starting with "C filename" which indicates conflicting changes.

Look for unmodified code in, e.g., "filename.r6", "filename.r9", and "filename.mine".

Search for "<<<<<<<" and ">>>>>>>" in files for conflicting changes.

Edit files to fix conflicts as needed.

Add a release tag "Release-1" by the following.

$ svn ci -m "last commit for Release-1"
$ svn cp file:///srv/svn/project/module1/trunk file:///srv/svn/project/module1/tags/Release-1

Edit further.

Remove the release tag "Release-1" by the following.

$ svn rm file:///srv/svn/project/module1/tags/Release-1

Check in changes to Subversion by the following.

$ svn ci -m "real last commit for Release-1"

Re-add the release tag "Release-1" from updated Subversion HEAD of trunk by the following.

$ svn cp file:///srv/svn/project/module1/trunk file:///srv/svn/project/module1/tags/Release-1

Create a branch with a path "module1/branches/Release-initial-bugfixes" from the original version pointed by the path "module1/tags/Release-initial" and check it out to "~/path/to/old" directory by the following.

$ svn cp file:///srv/svn/project/module1/tags/Release-initial file:///srv/svn/project/module1/branches/Release-initial-bugfixes
$ cd ~/path/to
$ svn co file:///srv/svn/project/module1/branches/Release-initial-bugfixes old
$ cd old
[提示] 提示

Use "module1/trunk@{2005-12-20}" (ISO 8601 date format) instead of "module1/tags/Release-initial" to specify particular date as the branch point.

Work on this local source tree pointing to branch "Release-initial-bugfixes" which is based on the original version.

Work on this branch by yourself … until someone else joins to this "Release-initial-bugfixes" branch.

Sync with files modified by others on this branch by the following.

$ svn up

Edit files to fix conflicts as needed.

Check in changes to Subversion by the following.

$ svn ci -m "checked into this branch"

Update the local tree with HEAD of trunk by the following.

$ svn switch file:///srv/svn/project/module1/trunk

Update the local tree (content = HEAD of trunk) by merging from the "Release-initial-bugfixes" branch by the following.

$ svn merge file:///srv/svn/project/module1/branches/Release-initial-bugfixes

Fix conflicts with editor.

Check in changes to Subversion by the following.

$ svn ci -m "merged Release-initial-bugfixes"

Make archive by the following.

$ cd ..
$ mv old old-module1-bugfixes
$ tar -cvzf old-module1-bugfixes.tar.gz old-module1-bugfixes
$ rm -rf old-module1-bugfixes
[提示] 提示

你能够用像 "http://…" 和 "svn+ssh://..." 这样格式的 URL 来替代 "file:///…" URL。

[提示] 提示

You can checkout only a sub directory of "module1" by providing its name as "svn co file:///srv/svn/project/module1/trunk/subdir module1/subdir", etc.



host by aosp.me  CDN