目录
Tools and tips for managing binary and text data on the Debian system are described.
![]() |
警告 |
---|---|
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. |
The security of the data and its controlled sharing have several aspects.
The creation of data archive
The remote storage access
The duplication
The tracking of the modification history
The facilitation of data sharing
The prevention of unauthorized file access
The detection of unauthorized file modification
These can be realized by using some combination of tools.
Archive and compression tools
Copy and synchronization tools
Network filesystems
Removable storage media
The secure shell
The authentication system
Version control system tools
Hash and cryptographic encryption tools
Here is a summary of archive and compression tools available on the Debian system.
表 10.1. List of archive and compression tools
軟件包 | 流行度 | 大小 | extension | 命令 | comment |
---|---|---|---|---|---|
tar
|
V:904, I:999 | 2749 |
.tar
|
tar(1) | the standard archiver (de facto standard) |
cpio
|
V:373, I:998 | 712 |
.cpio
|
cpio(1) | Unix System V style archiver, use with find(1) |
binutils
|
V:210, I:722 | 22155 |
.ar
|
ar(1) | archiver for the creation of static libraries |
fastjar
|
V:6, I:60 | 171 |
.jar
|
fastjar(1) | archiver for Java (zip like) |
pax
|
V:17, I:58 | 170 |
.pax
|
pax(1) |
new POSIX standard archiver, compromise between tar and
cpio
|
gzip
|
V:873, I:999 | 225 |
.gz
|
gzip(1), zcat(1), … | GNU LZ77 compression utility (de facto standard) |
bzip2
|
V:257, I:929 | 84 |
.bz2
|
bzip2(1), bzcat(1), … | Burrows-Wheeler
block-sorting compression utility with higher compression ratio than
gzip(1)
(slower than gzip with similar syntax)
|
lzma
|
V:5, I:69 | 144 |
.lzma
|
lzma(1) | LZMA compression utility with higher compression ratio than gzip(1) (deprecated) |
xz-utils
|
V:321, I:952 | 511 |
.xz
|
xz(1), xzdec(1), … | XZ compression utility with higher compression
ratio than
bzip2(1)
(slower than gzip but faster than
bzip2 ; replacement for LZMA
compression utility)
|
p7zip
|
V:38, I:150 | 862 |
.7z
|
7zr(1), p7zip(1) | 7-Zip file archiver with high compression ratio (LZMA compression) |
p7zip-full
|
V:188, I:529 | 4215 |
.7z
|
7z(1), 7za(1) | 7-Zip file archiver with high compression ratio (LZMA compression and others) |
lzop
|
V:5, I:42 | 92 |
.lzo
|
lzop(1) | LZO compression utility with higher compression
and decompression speed than
gzip(1)
(lower compression ratio than gzip with similar syntax)
|
zip
|
V:49, I:389 | 572 |
.zip
|
zip(1) | InfoZIP: DOS archive and compression tool |
unzip
|
V:300, I:790 | 506 |
.zip
|
unzip(1) | InfoZIP: DOS unarchive and decompression tool |
![]() |
警告 |
---|---|
Do not set the " |
![]() |
注意 |
---|---|
The gzipped
tar(1)
archive uses the file extension " |
![]() |
注意 |
---|---|
The xz-compressed
tar(1)
archive uses the file extension " |
![]() |
注意 |
---|---|
Popular compression method in FOSS tools such as
tar(1)
has been moving as follows: |
![]() |
注意 |
---|---|
cp(1), scp(1) and tar(1) may have some limitation for special files. cpio(1) is most versatile. |
![]() |
注意 |
---|---|
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. |
![]() |
注意 |
---|---|
Internal structure of Libreoffice data files are " |
Here is a summary of simple copy and backup tools available on the Debian system.
表 10.2. List of copy and synchronization tools
軟件包 | 流行度 | 大小 | tool | function |
---|---|---|---|---|
coreutils
|
V:876, I:999 | 14783 | GNU cp | locally copy files and directories ("-a" for recursive) |
openssh-client
|
V:543, I:995 | 3792 | scp |
remotely copy files and directories (client, "-r " for
recursive)
|
openssh-server
|
V:662, I:801 | 898 | sshd | remotely copy files and directories (remote server) |
rsync
|
V:202, I:586 | 687 | - | 1-way remote synchronization and backup |
unison
|
V:5, I:20 | 2213 | - | 2-way remote synchronization and backup |
obnam
|
V:1, I:2 | 977 | - | (remote) incremental backup |
rdiff-backup
|
V:9, I:19 | 704 | - | (remote) incremental backup |
Copying files with rsync(8) offers richer features than others.
delta-transfer algorithm that sends only the differences between the source files and the existing files in the destination
quick check algorithm (by default) that looks for files that have changed in size or in last-modified time
"--exclude
" and "--exclude-from
"
options similar to
tar(1)
"a trailing slash on the source directory" syntax that avoids creating an additional directory level at the destination.
![]() |
提示 |
---|---|
Execution of the |
![]() |
提示 |
---|---|
Version control system (VCS) tools in 表 10.11 “List of version control system tools” can function as the multi-way copy and synchronization tools. |
Here are several ways to archive and unarchive the entire content of the
directory "./source
" using different tools.
GNU tar(1):
$ tar -cvJf archive.tar.xz ./source $ tar -xvJf archive.tar.xz
Alternatively, by the following.
$ find ./source -xdev -print0 | tar -cvJf archive.tar.xz --null -F -
cpio(1):
$ find ./source -xdev -print0 | cpio -ov --null > archive.cpio; xz archive.cpio $ zcat archive.cpio.xz | cpio -i
Here are several ways to copy the entire content of the directory
"./source
" using different tools.
Local copy: "./source
" directory →
"/dest
" directory
Remote copy: "./source
" directory at local host →
"/dest
" directory at "user@host.dom
"
host
rsync(8):
# cd ./source; rsync -aHAXSv . /dest # cd ./source; rsync -aHAXSv . user@host.dom:/dest
You can alternatively use "a trailing slash on the source directory" syntax.
# rsync -aHAXSv ./source/ /dest # rsync -aHAXSv ./source/ user@host.dom:/dest
Alternatively, by the following.
# cd ./source; find . -print0 | rsync -aHAXSv0 --files-from=- . /dest # cd ./source; find . -print0 | rsync -aHAXSv0 --files-from=- . user@host.dom:/dest
GNU cp(1) and openSSH scp(1):
# cd ./source; cp -a . /dest # cd ./source; scp -pr . user@host.dom:/dest
GNU tar(1):
# (cd ./source && tar cf - . ) | (cd /dest && tar xvfp - ) # (cd ./source && tar cf - . ) | ssh user@host.dom '(cd /dest && tar xvfp - )'
cpio(1):
# cd ./source; find . -print0 | cpio -pvdm --null --sparse /dest
You can substitute ".
" with "foo
" for
all examples containing ".
" to copy files from
"./source/foo
" directory to
"/dest/foo
" directory.
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),
and
scp(1)
"/dest/path/to/source/foo
": GNU
tar(1),
and
cpio(1)
![]() |
提示 |
---|---|
rsync(8)
and GNU
cp(1)
have option " |
find(1) is used to select files for archive and copy commands (see 第 10.1.3 节 “Idioms for the archive” and 第 10.1.4 节 “Idioms for the copy”) or for xargs(1) (see 第 9.3.9 节 “Repeating a command looping over files”). This can be enhanced by using its command arguments.
Basic syntax of find(1) can be summarized as the following.
Its conditional arguments are evaluated from left to right.
This evaluation stops once its outcome is determined.
"Logical OR" (specified by
"-o
" between conditionals) has lower precedence than
"logical AND" (specified by
"-a
" or nothing between conditionals).
"Logical NOT" (specified by
"!
" before a conditional) has higher precedence than
"logical 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 glob”) 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
" matches the file newer than the one specified in
its argument.
"-print0
" always returns logical TRUE and print the full filename (null terminated) on the standard output.
find(1) is often used with an idiomatic style as the following.
# 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
This means to do following actions.
Search all files starting from "/path/to
"
Globally limit its search within its starting filesystem and uses ERE (see 第 1.6.2 节 “正則表達式”) instead
Exclude files matching regex of ".*\.cpio
" or
".*~
" from search by stop processing
Exclude directories matching regex of ".*/\.git
" from
search by stop processing
Exclude files larger than 99 Megabytes (units of 1048576 bytes) from search by stop processing
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.
![]() |
注意 |
---|---|
For non-Debian Unix-like system, some
options may not be supported by
find(1).
In such a case, please consider to adjust matching methods and replace
" |
When choosing computer data storage media for important data archive, you should be careful about their limitations. For small personal data backup, I use CD-R and DVD-R by the brand name company and store in a cool, shaded, dry, clean environment. (Tape archive media seem to be popular for professional use.)
![]() |
注意 |
---|---|
A fire-resistant safe are meant for paper documents. Most of the computer data storage media have less temperature tolerance than paper. I usually rely on multiple secure encrypted copies stored in multiple secure locations. |
Optimistic storage life of archive media seen on the net (mostly from vendor info).
100+ years : Acid free paper with ink
100 years : Optical storage (CD/DVD, CD/DVD-R)
30 years : Magnetic storage (tape, floppy)
20 years : Phase change optical storage (CD-RW)
These do not count on the mechanical failures due to handling etc.
Optimistic write cycle of archive media seen on the net (mostly from vendor info).
250,000+ cycles : Harddisk drive
10,000+ cycles : Flash memory
1,000 cycles : CD/DVD-RW
1 cycles : CD/DVD-R, paper
![]() |
小心 |
---|---|
Figures of storage life and write cycle here should not be used for decisions on any critical data storage. Please consult the specific product information provided by the manufacture. |
![]() |
提示 |
---|---|
Since CD/DVD-R and paper have only 1 write cycle, they inherently prevent accidental data loss by overwriting. This is advantage! |
![]() |
提示 |
---|---|
If you need fast and frequent backup of large amount of data, a hard disk on a remote host linked by a fast network connection, may be the only realistic option. |
Removable storage devices may be any one of the following.
Digital camera
Digital music player
They may be connected via any one of the following.
Modern desktop environments such as GNOME and KDE can mount these removable
devices automatically without a matching "/etc/fstab
"
entry.
![]() |
提示 |
---|---|
Automounted devices may have the " |
![]() |
提示 |
---|---|
Automounting under modern desktop environment happens only when those
removable media devices are not listed in " |
Mount point under modern desktop environment is chosen as
"/media/<disk_label>
" which can be customized by
the following.
mlabel(1) for FAT filesystem
genisoimage(1)
with "-V
" option for ISO9660 filesystem
tune2fs(1)
with "-L
" option for ext2/ext3/ext4 filesystem
![]() |
提示 |
---|---|
The choice of encoding may need to be provided as mount option (see 第 8.3.6 节 “Filename encoding”). |
![]() |
提示 |
---|---|
The use of the GUI menu to unmount a filesystem may remove its dynamically
generated device node such as " |
When sharing data with other system via removable storage device, you should format it with common filesystem supported by both systems. Here is a list of filesystem choices.
表 10.3. List of filesystem choices for removable storage devices with typical usage scenarios
filesystem | description of typical usage scenario |
---|---|
FAT12 | cross platform sharing of data on the floppy disk (<32MiB) |
FAT16 | cross platform sharing of data on the small hard disk like device (<2GiB) |
FAT32 | cross platform sharing of data on the large hard disk like device (<8TiB, supported by newer than MS Windows95 OSR2) |
NTFS | cross platform sharing of data on the large hard disk like device (supported natively on MS Windows NT and later version, and supported by NTFS-3G via FUSE on Linux) |
ISO9660 | cross platform sharing of static data on CD-R and DVD+/-R |
UDF | incremental data writing on CD-R and DVD+/-R (new) |
MINIX filesystem | space efficient unix file data storage on the floppy disk |
ext2 filesystem | sharing of data on the hard disk like device with older Linux systems |
ext3 filesystem | sharing of data on the hard disk like device with older Linux systems |
ext4 filesystem | sharing of data on the hard disk like device with current Linux systems |
![]() |
提示 |
---|---|
See 第 9.8.1 节 “Removable disk encryption with dm-crypt/LUKS” for cross platform sharing of data using device level encryption. |
The FAT filesystem is supported by almost all modern operating systems and is quite useful for the data exchange purpose via removable hard disk like media.
When formatting removable hard disk like devices for cross platform sharing of data with the FAT filesystem, the following should be safe choices.
Partitioning them with fdisk(8), cfdisk(8) or parted(8) (see 第 9.5.2 节 “Disk partition configuration”) into a single primary partition and to mark it as the following.
Type "6" for FAT16 for media smaller than 2GB.
Type "c" for FAT32 (LBA) for larger media.
Formatting the primary partition with mkfs.vfat(8) with the following.
Just its device name, e.g. "/dev/sda1
" for FAT16
The explicit option and its device name, e.g. "-F 32
/dev/sda1
" for FAT32
When using the FAT or ISO9660 filesystems for sharing data, the following should be the safe considerations.
Archiving files into an archive file first using tar(1), or cpio(1) to retain the long filename, the symbolic link, the original Unix file permission and the owner information.
Splitting the archive file into less than 2 GiB chunks with the split(1) command to protect it from the file size limitation.
Encrypting the archive file to secure its contents from the unauthorized access.
![]() |
注意 |
---|---|
For FAT filesystems by its design, the maximum file size is |
![]() |
注意 |
---|---|
Microsoft itself does not recommend to use FAT for drives or partitions of over 200 MB. Microsoft highlights its short comings such as inefficient disk space usage in their "Overview of FAT, HPFS, and NTFS File Systems". Of course, we should normally use the ext4 filesystem for Linux. |
![]() |
提示 |
---|---|
For more on filesystems and accessing filesystems, please read "Filesystems HOWTO". |
When sharing data with other system via network, you should use common service. Here are some hints.
表 10.4. List of the network service to chose with the typical usage scenario
network service | description of typical usage scenario |
---|---|
SMB/CIFS network mounted filesystem with Samba |
sharing files via "Microsoft Windows Network", see
smb.conf(5)
and The Official Samba 3.x.x
HOWTO and Reference Guide or the samba-doc
package
|
NFS network mounted filesystem with the Linux kernel | sharing files via "Unix/Linux Network", see exports(5) and Linux NFS-HOWTO |
HTTP service | sharing file between the web server/client |
HTTPS service | sharing file between the web server/client with encrypted Secure Sockets Layer (SSL) or Transport Layer Security (TLS) |
FTP service | sharing file between the FTP server/client |
Although these filesystems mounted over network and file transfer methods over network are quite convenient for sharing data, these may be insecure. Their network connection must be secured by the following.
See also 第 6.10 节 “Other network application servers” and 第 6.11 节 “Other network application clients”.
We all know that computers fail sometime or human errors cause system and data damages. Backup and recovery operations are the essential part of successful system administration. All possible failure modes hit you some day.
![]() |
提示 |
---|---|
Keep your backup system simple and backup your system often. Having backup data is more important than how technically good your backup method is. |
There are 3 key factors which determine actual backup and recovery policy.
Knowing what to backup and recover.
Data files directly created by you: data in "~/
"
Data files created by applications used by you: data in
"/var/
" (except "/var/cache/
",
"/var/run/
", and "/var/tmp/
")
System configuration files: data in "/etc/
"
Local softwares: data in "/usr/local/
" or
"/opt/
"
System installation information: a memo in plain text on key steps (partition, …)
Proven set of data: confirmed by experimental recovery operations in advance
Knowing how to backup and recover.
Secure storage of data: protection from overwrite and system failure
Frequent backup: scheduled backup
Redundant backup: data mirroring
Fool proof process: easy single command backup
Assessing risks and costs involved.
Value of data when lost
Required resources for backup: human, hardware, software, …
Failure mode and their possibility
![]() |
注意 |
---|---|
Do not back up the pseudo-filesystem contents found on
|
As for secure storage of data, data should be at least on different disk partitions preferably on different disks and machines to withstand the filesystem corruption. Important data are best stored on a write-once media such as CD/DVD-R to prevent overwrite accidents. (See 第 9.7 节 “The binary data” for how to write to the storage media from the shell commandline. GNOME desktop GUI environment gives you easy access via menu: "Places→CD/DVD Creator".)
![]() |
注意 |
---|---|
You may wish to stop some application daemons such as MTA (see 第 6.3 节 “Mail transport agent (MTA)”) while backing up data. |
![]() |
注意 |
---|---|
You should pay extra care to the backup and restoration of identity related
data files such as " |
![]() |
注意 |
---|---|
If you run a cron job as a user process, you must restore files in
" |
Here is a select list of notable backup utility suites available on the Debian system.
表 10.5. List of backup suite utilities
軟件包 | 流行度 | 大小 | 說明 |
---|---|---|---|
dump
|
V:1, I:7 | 378 | 4.4 BSD dump(8) and restore(8) for ext2/ext3/ext4 filesystems |
xfsdump
|
V:1, I:12 | 810 | dump and restore with xfsdump(8) and xfsrestore(8) for XFS filesystem on GNU/Linux and IRIX |
backupninja
|
V:3, I:4 | 277 | lightweight, extensible meta-backup system |
sbackup
|
V:0, I:0 | 488 | simple backup suite for GNOME desktop |
bacula-common
|
V:8, I:19 | 1276 | Bacula: network backup, recovery and verification - common support files |
bacula-client
|
I:6 | 156 | Bacula: network backup, recovery and verification - client meta-package |
bacula-console
|
V:2, I:7 | 60 | Bacula: network backup, recovery and verification - text console |
bacula-server
|
I:2 | 159 | Bacula: network backup, recovery and verification - server meta-package |
amanda-common
|
V:1, I:3 | 7418 | Amanda: Advanced Maryland Automatic Network Disk Archiver (Libs) |
amanda-client
|
V:1, I:3 | 993 | Amanda: Advanced Maryland Automatic Network Disk Archiver (Client) |
amanda-server
|
V:0, I:0 | 1046 | Amanda: Advanced Maryland Automatic Network Disk Archiver (Server) |
backuppc
|
V:4, I:5 | 2232 | BackupPC is a high-performance, enterprise-grade system for backing up PCs (disk based) |
backup-manager
|
V:1, I:2 | 543 | command-line backup tool |
backup2l
|
V:1, I:1 | 113 | low-maintenance backup/restore tool for mountable media (disk based) |
Backup tools have their specialized focuses.
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.
sbackup
and keep
packages provide easy
GUI frontend for desktop users to make regular backups of user data. An
equivalent function can be realized by a simple script (第 10.2.2 节 “An example script for the system backup”) and
cron(8).
Bacula, Amanda, and BackupPC are full featured backup suite utilities which are focused on regular backups over network.
Basic tools described in 第 10.1.1 节 “Archive and compression tools” and 第 10.1.2 节 “Copy and synchronization tools” can be used to facilitate system backup via custom scripts. Such script can be enhanced by the following.
The obnam
package enables incremental (remote) backups.
The rdiff-backup
package enables incremental (remote)
backups.
The dump
package helps to archive and restore the whole
filesystem incrementally and efficiently.
![]() |
提示 |
---|---|
See files in " |
For a personal Debian desktop system running unstable
suite, I only need to protect personal and critical data. I reinstall
system once a year anyway. Thus I see no reason to backup the whole system
or to install a full featured backup utility.
I use a simple script to make a backup archive and burn it into CD/DVD using GUI. Here is an example script for this.
#!/bin/sh -e # Copyright (C) 2007-2008 Osamu Aoki <osamu@debian.org>, 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
This is meant to be a script example executed from root.
I expect you to change and execute this as follows.
Edit this script to cover all your important data (see 第 10.1.5 节 “Idioms for the selection of files” and 第 10.2 节 “Backup and recovery”).
Replace "find … -print0
" with "find … -newer
$BUDIR/backup.stamp -print0
" to make a incremental backup.
Transfer backup files to the remote host using scp(1) or rsync(1) or burn them to CD/DVD for extra data security. (I use GNOME desktop GUI for burning CD/DVD. See 第 12.1.8 节 “Shell script example with zenity” for extra redundancy.)
Keep it simple!
![]() |
提示 |
---|---|
You can recover debconf configuration data with
" |
For the set of data under a directory tree, the copy with "cp
-a
" provides the normal backup.
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.
Here is a copy script, which I named as bkup
, for the
data backup. This script copies all (non-VCS) files under the current
directory to the dated directory on the parent directory or on a remote
host.
#!/bin/sh -e # Copyright (C) 2007-2008 Osamu Aoki <osamu@debian.org>, 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}";; # user@remotehost.example.com 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 |
![]() |
提示 |
---|---|
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”). |
The data security infrastructure is provided by the combination of data encryption tool, message digest tool, and signature tool.
表 10.6. List of data security infrastructure tools
軟件包 | 流行度 | 大小 | 命令 | 說明 |
---|---|---|---|---|
gnupg
|
V:580, I:999 | 1878 | gpg(1) | GNU Privacy Guard - OpenPGP encryption and signing tool |
gpgv
|
V:863, I:999 | 584 | gpgv(1) | GNU Privacy Guard - signature verification tool |
paperkey
|
V:0, I:1 | 39 | paperkey(1) | extract just the secret information out of OpenPGP secret keys |
cryptsetup
|
V:26, I:70 | 342 | cryptsetup(8), … | utilities for dm-crypto block device encryption supporting LUKS |
ecryptfs-utils
|
V:5, I:9 | 393 | ecryptfs(7), … | utilities for ecryptfs stacked filesystem encryption |
coreutils
|
V:876, I:999 | 14783 | md5sum(1) | compute and check MD5 message digest |
coreutils
|
V:876, I:999 | 14783 | sha1sum(1) | compute and check SHA1 message digest |
openssl
|
V:772, I:987 | 1127 | openssl(1ssl) |
compute message digest with "openssl dgst " (OpenSSL)
|
See 第 9.8 节 “Data encryption tips” on dm-crypto and ecryptfs which implement automatic data encryption infrastructure via Linux kernel modules.
Here are GNU Privacy Guard commands for the basic key management.
表 10.7. List of GNU Privacy Guard commands for the key management
命令 | 說明 |
---|---|
gpg --gen-key
|
generate a new key |
gpg --gen-revoke my_user_ID
|
generate revoke key for my_user_ID |
gpg --edit-key user_ID
|
edit key interactively, "help" for help |
gpg -o file --export
|
export all keys to file |
gpg --import file
|
import all keys from file |
gpg --send-keys user_ID
|
send key of user_ID to keyserver |
gpg --recv-keys user_ID
|
recv. key of user_ID from keyserver |
gpg --list-keys user_ID
|
list keys of user_ID |
gpg --list-sigs user_ID
|
list sig. of user_ID |
gpg --check-sigs user_ID
|
check sig. of user_ID |
gpg --fingerprint user_ID
|
check fingerprint of user_ID |
gpg --refresh-keys
|
update local keyring |
Here is the meaning of the trust code.
表 10.8. List of the meaning of the trust code
code | description of trust |
---|---|
-
|
no owner trust assigned / not yet calculated |
e
|
trust calculation failed |
q
|
not enough information for calculation |
n
|
never trust this key |
m
|
marginally trusted |
f
|
fully trusted |
u
|
ultimately trusted |
The following uploads my key "1DD8D791
" to the popular
keyserver "hkp://keys.gnupg.net
".
$ gpg --keyserver hkp://keys.gnupg.net --send-keys 1DD8D791
A good default keyserver set up in "~/.gnupg/gpg.conf
"
(or old location "~/.gnupg/options
") contains the
following.
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.
Here are examples for using GNU Privacy Guard commands on files.
表 10.9. List of GNU Privacy Guard commands on files
命令 | 說明 |
---|---|
gpg -a -s file
|
sign file into ASCII armored file.asc |
gpg --armor --sign file
|
同上 |
gpg --clearsign file
|
clear-sign message |
gpg --clearsign file|mail foo@example.org
|
mail a clear-signed message to foo@example.org
|
gpg --clearsign --not-dash-escaped patchfile
|
clear-sign patchfile |
gpg --verify file
|
verify clear-signed file |
gpg -o file.sig -b file
|
create detached signature |
gpg -o file.sig --detach-sig file
|
同上 |
gpg --verify file.sig file
|
verify file with file.sig |
gpg -o crypt_file.gpg -r name -e file
|
public-key encryption intended for name from file to binary crypt_file.gpg |
gpg -o crypt_file.gpg --recipient name --encrypt file
|
同上 |
gpg -o crypt_file.asc -a -r name -e file
|
public-key encryption intended for name from file to ASCII armored crypt_file.asc |
gpg -o crypt_file.gpg -c file
|
symmetric encryption from file to crypt_file.gpg |
gpg -o crypt_file.gpg --symmetric file
|
同上 |
gpg -o crypt_file.asc -a -c file
|
symmetric encryption intended for name from file to ASCII armored crypt_file.asc |
gpg -o file -d crypt_file.gpg -r name
|
decryption |
gpg -o file --decrypt crypt_file.gpg
|
同上 |
Add the following to "~/.muttrc
" to keep a slow GnuPG
from automatically starting, while allowing it to be used by typing
"S
" at the index menu.
macro index S ":toggle pgp_verify_sig\n" set pgp_verify_sig=no
The gnupg
plugin let you run GnuPG transparently for
files with extension ".gpg
", ".asc
",
and ".ppg
".
# aptitude install vim-scripts vim-addon-manager $ vim-addons install gnupg
md5sum(1) provides utility to make a digest file using the method in rfc1321 and verifying each file with it.
$ md5sum foo bar >baz.md5 $ cat baz.md5 d3b07384d113edec49eaa6238ad5ff00 foo c157a79031e1c40f85931829bc5fc552 bar $ md5sum -c baz.md5 foo: OK bar: OK
![]() |
注意 |
---|---|
The computation for the MD5 sum is less CPU intensive than the one for the cryptographic signature by GNU Privacy Guard (GnuPG). Usually, only the top level digest file is cryptographically signed to ensure data integrity. |
There are many merge tools for the source code. Following commands caught my eyes.
表 10.10. List of source code merge tools
軟件包 | 流行度 | 大小 | 命令 | 說明 |
---|---|---|---|---|
diffutils
|
V:847, I:973 | 1319 | diff(1) | compare files line by line |
diffutils
|
V:847, I:973 | 1319 | diff3(1) | compare and merges three files line by line |
vim
|
V:127, I:390 | 2366 | vimdiff(1) | compare 2 files side by side in vim |
patch
|
V:119, I:938 | 191 | patch(1) | apply a diff file to an original |
dpatch
|
V:1, I:18 | 191 | dpatch(1) | manage series of patches for Debian package |
diffstat
|
V:20, I:190 | 65 | diffstat(1) | produce a histogram of changes by the diff |
patchutils
|
V:19, I:182 | 189 | combinediff(1) | create a cumulative patch from two incremental patches |
patchutils
|
V:19, I:182 | 189 | dehtmldiff(1) | extract a diff from an HTML page |
patchutils
|
V:19, I:182 | 189 | filterdiff(1) | extract or excludes diffs from a diff file |
patchutils
|
V:19, I:182 | 189 | fixcvsdiff(1) | fix diff files created by CVS that patch(1) mis-interprets |
patchutils
|
V:19, I:182 | 189 | flipdiff(1) | exchange the order of two patches |
patchutils
|
V:19, I:182 | 189 | grepdiff(1) | show which files are modified by a patch matching a regex |
patchutils
|
V:19, I:182 | 189 | interdiff(1) | show differences between two unified diff files |
patchutils
|
V:19, I:182 | 189 | lsdiff(1) | show which files are modified by a patch |
patchutils
|
V:19, I:182 | 189 | recountdiff(1) | recompute counts and offsets in unified context diffs |
patchutils
|
V:19, I:182 | 189 | rediff(1) | fix offsets and counts of a hand-edited diff |
patchutils
|
V:19, I:182 | 189 | splitdiff(1) | separate out incremental patches |
patchutils
|
V:19, I:182 | 189 | unwrapdiff(1) | demangle patches that have been word-wrapped |
wiggle
|
V:0, I:0 | 166 | wiggle(1) | apply rejected patches |
quilt
|
V:4, I:46 | 710 | quilt(1) | manage series of patches |
meld
|
V:11, I:42 | 3022 | meld(1) | compare and merge files (GTK) |
dirdiff
|
V:0, I:3 | 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:90 | 643 | wdiff(1) | display word differences between text files |
The following procedures extract differences between two source files and
create unified diff files "file.patch0
" or
"file.patch1
" depending on the file location.
$ diff -u file.old file.new > file.patch0 $ diff -u old/file new/file > file.patch1
The diff file (alternatively called patch file) is used to send a program update. The receiving party applies this update to another file by the following.
$ patch -p0 file < file.patch0 $ patch -p1 file < file.patch1
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. |
表 10.11. List of version control system tools
軟件包 | 流行度 | 大小 | tool | VCS type | comment |
---|---|---|---|---|---|
cssc
|
V:0, I:2 | 2012 | CSSC | local | clone of the Unix SCCS (deprecated) |
rcs
|
V:4, I:24 | 547 | RCS | local | "Unix SCCS done right" |
cvs
|
V:7, I:63 | 4084 | CVS | remote | previous standard remote VCS |
subversion
|
V:42, I:170 | 4738 | Subversion | remote | "CVS done right", the new de facto standard remote VCS |
git
|
V:244, I:410 | 26512 | Git | distributed | fast DVCS in C (used by the Linux kernel and others) |
mercurial
|
V:13, I:65 | 204 | Mercurial | distributed | DVCS in Python and some C |
bzr
|
V:4, I:23 | 70 | Bazaar | distributed |
DVCS influenced by tla written in Python (used by Ubuntu)
|
darcs
|
V:0, I:8 | 28056 | Darcs | distributed | DVCS with smart algebra of patches (slow) |
tla
|
V:0, I:8 | 912 | GNU arch | distributed | DVCS mainly by Tom Lord (Historic) |
monotone
|
V:0, I:0 | 5815 | Monotone | distributed | DVCS in C++ |
tkcvs
|
V:0, I:1 | 1400 | CVS, … | remote | GUI display of VCS (CVS, Subversion, RCS) repository tree |
gitk
|
V:9, I:51 | 1374 | Git | distributed | GUI display of VCS (Git) repository tree |
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.
Use "umask 002
" (see 第 1.2.4 节 “Control of permissions for newly created files: umask”)
Make all VCS archive files belonging to a pertinent group
Enable set group ID on all VCS archive directories (BSD-like file creation scheme, see 第 1.2.3 节 “文件系統權限”)
Make user sharing the VCS archive belonging to the group
Here is an oversimplified comparison of native VCS commands to provide the big picture. The typical command sequence may require options and arguments.
表 10.12. Comparison of native VCS commands
Git | CVS | Subversion | function |
---|---|---|---|
git init
|
cvs init
|
svn create
|
create the (local) repository |
- |
cvs login
|
- | login to the remote repository |
git clone
|
cvs co
|
svn co
|
check out the remote repository as the working tree |
git pull
|
cvs up
|
svn up
|
update the working tree by merging the remote repository |
git add .
|
cvs add
|
svn add
|
add file(s) in the working tree to the VCS |
git rm
|
cvs rm
|
svn rm
|
remove file(s) in working tree from the VCS |
- |
cvs ci
|
svn ci
|
commit changes to the remote repository |
git commit -a
|
- | - | commit changes to the local repository |
git push
|
- | - | update the remote repository by the local repository |
git status
|
cvs status
|
svn status
|
display the working tree status from the VCS |
git diff
|
cvs diff
|
svn diff
|
diff <reference_repository> <working_tree> |
git repack -a -d; git prune
|
- | - | repack the local repository into single pack |
gitk
|
tkcvs
|
tkcvs
|
GUI display of VCS repository tree |
![]() |
小心 |
---|---|
Invoking a |
![]() |
提示 |
---|---|
If there is a executable file |
![]() |
提示 |
---|---|
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 has commands which have no equivalents in CVS and Subversion: "fetch", "rebase", "cherry-pick", … |
Git 可以用來做本地和遠程源代碼管理的任何事情。這意味着,你能夠在本地記錄源代碼修改,而不是必須要和遠程倉庫有網絡連接。
你可以在 "~/.gitconfig
" 裏面設置幾個 Git
接下來需要使用的全局配置,比如說你的名字和電子郵件地址。
$ git config --global user.name "姓名" $ git config --global user.email 電子郵件地址
如果你習慣使用 CVS 或 Subversion 命令,你也許希望設置如下幾個命令別名。
$ git config --global alias.ci "commit -a" $ git config --global alias.co checkout
你能夠通過如下方式檢查你的整體組態。
$ git config --global --list
看下面。
man 手冊: git(1)
(/usr/share/doc/git-doc/git.html
)
Git 用戶手冊
(/usr/share/doc/git-doc/user-manual.html
)
git 介紹教程
(/usr/share/doc/git-doc/gittutorial.html
)
git 介紹教程:第二部
(/usr/share/doc/git-doc/gittutorial-2.html
)
GIT 每一天 20個左右的命令
(/usr/share/doc/git-doc/everyday.html
)
CVS 用戶用 git
(/usr/share/doc/git-doc/gitcvs-migration.html
)
描述了怎樣搭建服務,以及如何把老的數據從 CVS 遷移到 Git。
Git 魔術
(/usr/share/doc/gitmagic/html/index.html
)
git-gui(1) 和 gitk(1) 命令使 Git 變得非常容易使用。
![]() |
警告 |
---|---|
不要使用帶空格的標簽字符串。即使一些工具,如
gitk(1)
允許你使用它,但會阻礙其它 |
即使你的上游使用不同的版本控制系統,使用 git(1) 作爲本地活動的版本控制系統,仍然是一個好的主意,因爲 git 可以讓你在沒有上遊網絡連接的情況下,管理你的本地源代碼樹拷貝。這裏有一些 git(1) 使用的包和命令。
表 10.13. git 相關包和命令列表
軟件包 | 流行度 | 大小 | 命令 | 說明 |
---|---|---|---|---|
git-doc
|
I:20 | 10377 | N/A | Git 官方文檔 |
gitmagic
|
I:2 | 719 | N/A | "Git 魔術",易於理解的 Git 手冊 |
git
|
V:244, I:410 | 26512 | git(7) | Git 快速、可擴展、分佈式的版本控制系統 |
gitk
|
V:9, I:51 | 1374 | gitk(1) | 有歷史功能的 Git 圖形倉庫瀏覽器 |
git-gui
|
V:3, I:29 | 2068 | git-gui(1) | Git 圖形界面(無歷史功能) |
git-svn
|
V:2, I:29 | 913 | git-svnimport(1) | 從 Subversion 導出數據,導入到 Git |
git-svn
|
V:2, I:29 | 913 | git-svn(1) | 在 Subversion 和 Git 之間提供雙向操作 |
git-cvs
|
V:0, I:13 | 1035 | git-cvsimport(1) | 從 CVS 導出數據,導入到 Git |
git-cvs
|
V:0, I:13 | 1035 | git-cvsexportcommit(1) | export a commit to a CVS checkout from Git |
git-cvs
|
V:0, I:13 | 1035 | git-cvsserver(1) | Git 的 CVS 服務模擬器 |
git-email
|
V:0, I:13 | 714 | git-send-email(1) | 從 Git 用電子郵件發送收集到的補丁 |
stgit
|
V:0, I:1 | 1692 | stg(1) | 封裝的 git (Python) |
git-buildpackage
|
V:1, I:11 | 4050 | git-buildpackage(1) | 用 Git 自動製作 Debian 包 |
guilt
|
V:0, I:0 | 147 | guilt(7) | 封裝的 git (SH/AWK/SED/…) |
![]() |
提示 |
---|---|
With
git(1),
you work on a local branch with many commits and use something like
" |
![]() |
提示 |
---|---|
When you want to go back to a clean working directory without loosing the
current state of the working directory, you can use " |
你可以把 "svn+ssh://svn.example.org/project/module/trunk
" 的
Subversion 典藏所檢出到在地 Git 典藏所的 "./dest
" 並把修改提交回 Subversion
典藏所。例如:
$ git svn clone -s -rHEAD svn+ssh://svn.example.org/project dest $ cd dest ... 進行修改 $ git commit -a ... 繼續在本地用 git 工作 $ git svn dcommit
![]() |
提示 |
---|---|
使用 " |
你可以使用 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)
是需要用於配置數據文件,任意文件權限的情況。 對於普通用戶的配置數據,你需要省略 |
![]() |
注意 |
---|---|
在上面例子裏的 " |
![]() |
提示 |
---|---|
要更加完整的建立配置歷史記錄,請參閱 |
看下面。
cvs(1)
"/usr/share/doc/cvs/html-cvsclient
"
"/usr/share/doc/cvs/html-info
"
"/usr/share/doc/cvsbook
"
"info cvs
"
The following configuration allows commits to the CVS repository only by a
member of the "src
" group, and administration of CVS only
by a member of the "staff
" group, thus reducing the
chance of shooting oneself.
# cd /var/lib; umask 002; mkdir cvs # export CVSROOT=/srv/cvs/project # cd $CVSROOT # chown root:src . # chmod 2775 . # cvs -d $CVSROOT init # cd CVSROOT # chown -R root:staff . # chmod 2775 . # touch val-tags # chmod 664 history val-tags # chown root:src history val-tags
![]() |
提示 |
---|---|
You may restrict creation of new project by changing the owner of
" |
The default CVS repository is pointed by "$CVSROOT
". The
following sets up "$CVSROOT
" for the local access.
$ export CVSROOT=/srv/cvs/project
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:anonymous@anonscm.debian.org:/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:account@cvs.alioth.debian.org:/cvs/webwml
You can also use public key authentication for SSH which eliminates the remote password prompt.
Create a new local source tree location at
"~/path/to/module1
" by the following.
$ mkdir -p ~/path/to/module1; cd ~/path/to/module1
Populate a new local source tree under
"~/path/to/module1
" with files.
Import it to CVS with the following parameters.
Module name: "module1
"
Vendor tag: "Main-branch
" (tag for the entire branch)
Release tag: "Release-initial
" (tag for a specific
release)
$ cd ~/path/to/module1 $ cvs import -m "Start module1" module1 Main-branch Release-initial $ rm -Rf . # optional
CVS does not overwrite the current repository file but replaces it with
another one. Thus, write permission to the repository directory is
critical. For every new module for "module1
" in
repository at "/srv/cvs/project
", run the following to
ensure this condition if needed.
# cd /srv/cvs/project # chown -R root:src module1 # chmod -R ug+rwX module1 # chmod 2775 module1
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
Make changes to the content as needed.
Check changes by making "diff -u [repository] [local]
"
equivalent by the following.
$ cvs diff -u
You find that you broke some file "file_to_undo
" severely
but other files are fine.
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 " |
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
![]() |
提示 |
---|---|
" |
![]() |
提示 |
---|---|
You can checkout only a sub directory of " |
表 10.14. Notable options for CVS commands (use as first argument(s) to cvs(1))
option | 說明 |
---|---|
-n
|
dry run, no effect |
-t
|
display messages showing steps of cvs activity |
To get the latest files from CVS, use "tomorrow
" by the
following.
$ cvs ex -D tomorrow module_name
Add module alias "mx
" to a CVS project (local server) by
the following.
$ export CVSROOT=/srv/cvs/project $ cvs co CVSROOT/modules $ cd CVSROOT $ echo "mx -a module1" >>modules $ cvs ci -m "Now mx is an alias for module1" $ cvs release -d .
Now, you can check out "module1
" (alias:
"mx
") from CVS to "new
" directory by
the following.
$ cvs co -d new mx $ cd new
![]() |
注意 |
---|---|
In order to perform above procedure, you should have appropriate file permissions. |
When you checkout files from CVS, their execution permission bit is retained.
Whenever you see execution permission problems in a checked out file,
e.g. "filename
", change its permission in the
corresponding CVS repository by the following to fix it.
# chmod ugo-x filename
Subversion is a recent-generation version control system replacing older CVS. It has most of CVS's features except tags and branches.
You need to install subversion
,
libapache2-svn
and subversion-tools
packages to set up a Subversion server.
Currently, the subversion
package does not set up a
repository, so one must set it up manually. One possible location for a
repository is in "/srv/svn/project
".
Create a directory by the following.
# mkdir -p /srv/svn/project
Create the repository database by the following.
# svnadmin create /srv/svn/project
If you only access Subversion repository via Apache2 server, you just need to make the repository only writable by the WWW server by the following.
# chown -R www-data:www-data /srv/svn/project
Add (or uncomment) the following in
"/etc/apache2/mods-available/dav_svn.conf
" to allow
access to the repository via user authentication.
<Location /project> DAV svn SVNPath /srv/svn/project AuthType Basic AuthName "Subversion repository" AuthUserFile /etc/subversion/passwd <LimitExcept GET PROPFIND OPTIONS REPORT> Require valid-user </LimitExcept> </Location>
Create a user authentication file with the command by the following.
# htpasswd2 -c /etc/subversion/passwd some-username
Restart Apache2.
Your new Subversion repository is accessible at URL
"http://localhost/project
" and
"http://example.com/project
" from
svn(1)
(assuming your URL of web server is
"http://example.com/
").
The following sets up Subversion repository for the local access by a group,
e.g. project
.
# chmod 2775 /srv/svn/project # chown -R root:src /srv/svn/project # chmod -R ug+rwX /srv/svn/project
Your new Subversion repository is group accessible at URL
"file:///localhost/srv/svn/project
" or
"file:///srv/svn/project
" from
svn(1)
for local users belonging to project
group. You must run
commands, such as svn
, svnserve
,
svnlook
, and svnadmin
under
"umask 002
" to ensure group access.
A group accessible Subversion repository is at URL
"example.com:/srv/svn/project
" for SSH, you can access it
from
svn(1)
at URL "svn+ssh://example.com:/srv/svn/project
".
Many projects uses directory tree similar to the following for Subversion to compensate its lack of branches and tags.
----- module1 | |-- branches | |-- tags | | |-- release-1.0 | | `-- release-2.0 | | | `-- trunk | |-- file1 | |-- file2 | `-- file3 | `-- module2
![]() |
提示 |
---|---|
You must use " |
Create a new local source tree location at
"~/path/to/module1
" by the following.
$ mkdir -p ~/path/to/module1; cd ~/path/to/module1
Populate a new local source tree under
"~/path/to/module1
" with files.
Import it to Subversion with the following parameters.
Module name: "module1
"
Subversion site URL: "file:///srv/svn/project
"
Subversion directory: "module1/trunk
"
Subversion tag: "module1/tags/Release-initial
"
$ cd ~/path/to/module1 $ svn import file:///srv/svn/project/module1/trunk -m "Start module1" $ svn cp file:///srv/svn/project/module1/trunk file:///srv/svn/project/module1/tags/Release-initial
Alternatively, by the following.
$ svn import ~/path/to/module1 file:///srv/svn/project/module1/trunk -m "Start module1" $ svn cp file:///srv/svn/project/module1/trunk file:///srv/svn/project/module1/tags/Release-initial
![]() |
提示 |
---|---|
You can replace URLs such as " |
Here is an example of typical work flow using Subversion with its native client.
![]() |
提示 |
---|---|
Client commands offered by the |
Check all available modules from Subversion project pointed by URL
"file:///srv/svn/project
" by the following.
$ svn list file:///srv/svn/project module1 module2 ...
Checkout "module1/trunk
" to a directory
"module1
" by the following.
$ cd ~/path/to $ svn co file:///srv/svn/project/module1/trunk module1 $ cd module1
Make changes to the content as needed.
Check changes by making "diff -u [repository] [local]
"
equivalent by the following.
$ svn diff
You find that you broke some file "file_to_undo
" severely
but other files are fine.
Overwrite "file_to_undo
" file with the clean copy from
Subversion by the following.
$ svn revert file_to_undo
Save the updated local source tree to Subversion by the following.
$ svn ci -m "Describe change"
Create and add "file_to_add
" file to Subversion by the
following.
$ 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 " |
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
![]() |
提示 |
---|---|
You can replace URLs such as " |
![]() |
提示 |
---|---|
You can checkout only a sub directory of " |
表 10.15. Notable options for Subversion commands (use as first argument(s) to svn(1))
option | 說明 |
---|---|
--dry-run
|
dry run, no effect |
-v
|
display detail messages of svn activity |