|

- 帖子
- 947
- 主题
- 215
- 精华
- 0
- 可用积分
- 4847
- 专家积分
- 0
- 在线时间
- 160 小时
- 注册时间
- 2007-01-06
- 最后登录
- 2010-03-01
状态:...当前离线...
[微博]
[博客]
[短信]
|
Server setup | SVN+SSH | SVN over http | SVN usage
Subversion (SVN)http://subversion.tigris.org/ is a version control system designed to be the successor of CVS (Concurrent Versions System). The concept is similar to CVS, but many shortcomings where improved. See also the SVN bookhttp://svnbook.red-bean.com/en/1.4/.
Server setup
The initiation of the repository is fairly simple (here for example /home/svn/ must exist):
# svnadmin create --fs-type fsfs /home/svn/project1
Now the access to the repository is made possible with:
file:// Direct file system access with the svn client with. This requires local permissions on the file system.
svn:// or svn+ssh:// Remote access with the svnserve server (also over SSH). This requires local permissions on the file system.
http:// Remote access with webdav using apache. No local users are necessary for this method.
Using the local file system, it is now possible to import and then check out an existing project. Unlike with CVS it is not necessary to cd into the project directory, simply give the full path:
# svn import /project1/ file:///home/svn/project1/trunk -m 'Initial import'
# svn checkout file:///home/svn/project1
The new directory "trunk" is only a convention, this is not required.
Remote access with ssh
No special setup is required to access the repository via ssh, simply replace file:// with svn+ssh/hostname. For example:
# svn checkout svn+ssh://hostname/home/svn/project1
As with the local file access, every user needs an ssh access to the server (with a local account) and also read/write access. This method might be suitable for a small group. All users could belong to a subversion group which owns the repository, for example:
# groupadd subversion
# groupmod -A user1 subversion
# chown -R root:subversion /home/svn
# chmod -R 770 /home/svn
Remote access with http (apache)
Remote access over http (https) is the only good solution for a larger user group. This method uses the apache authentication, not the local accounts. This is a typical but small apache configuration:
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so # Only for access control
<Location /svn>
DAV svn
# any "/svn/foo" URL will map to a repository /home/svn/foo
SVNParentPath /home/svn
AuthType Basic
AuthName "Subversion repository"
AuthzSVNAccessFile /etc/apache2/svn.acl
AuthUserFile /etc/apache2/svn-passwd
Require valid-user
</Location>
The apache server needs full access to the repository:
# chown -R www:www /home/svn
Create a user with htpasswd2:
# htpasswd -c /etc/svn-passwd user1 # -c creates the file
Access control svn.acl example
# Default it read access. "* =" would be default no access
[/]
* = r
[groups]
project1-developers = joe, jack, jane
# Give write access to the developers
[project1:]
@project1-developers = rw
SVN commands and usage
See also the Subversion Quick Reference Cardhttp://www.cs.put.poznan.pl/csobaniec/Papers/svn-refcard.pdf. Tortoise SVNhttp://tortoisesvn.tigris.org is a nice Windows interface.
Import
A new project, that is a directory with some files, is imported into the repository with the import command. Import is also used to add a directory with its content to an existing project.
# svn help import # Get help for any command
# Add a new directory (with content) into the src dir on project1
# svn import /project1/newdir http://host.url/svn/project1/trunk/src -m 'add newdir'
Typical SVN commands
# svn co http://host.url/svn/project1/trunk # Checkout the most recent version
# Tags and branches are created by copying
# svn mkdir http://host.url/svn/project1/tags/ # Create the tags directory
# svn copy -m "Tag rc1 rel." http://host.url/svn/project1/trunk \
http://host.url/svn/project1/tags/1.0rc1
# svn status [--verbose] # Check files status into working dir
# svn add src/file.h src/file.cpp # Add two files
# svn commit -m 'Added new class file' # Commit the changes with a message
# svn ls http://host.url/svn/project1/tags/ # List all tags
# svn move foo.c bar.c # Move (rename) files
# svn delete some_old_file # Delete files
Useful Commands
less | vi | mail | tar | dd | screen | find | Miscellaneous
less
The less command displays a text document on the console. It is present on most installation.
# less unixtoolbox.xhtml
Some important commands are (^N stands for [control]-[N]):
h H good help on display
f ^F ^V SPACE Forward one window (or N lines).
b ^B ESC-v Backward one window (or N lines).
F Forward forever; like "tail -f".
/pattern Search forward for (N-th) matching line.
?pattern Search backward for (N-th) matching line.
n Repeat previous search (for N-th occurrence).
N Repeat previous search in reverse direction.
q quit
vi
Vi is present on ANY Linux/Unix installation and it is therefore useful to know some basic commands. There are two modes: command mode and insertion mode. The commands mode is accessed with [ESC], the insertion mode with i.
Quit
:w newfilename save the file to newfilename
:wq or save and quit
:q! quit without saving
Search and move
/string Search forward for string
?string Search back for string
n Search for next instance of string
N Search for previous instance of string
{ Move a paragraph back
} Move a paragraph forward
1G Move to the first line of the file
nG Move to the n th line of the file
G Move to the last line of the file
:%s/OLD/NEW/g Search and replace every occurrence
Delete text
dd delete current line
D Delete to the end of the line
dw Delete word
x Delete character
u Undo last
U Undo all changes to current line
mail
The mail command is a basic application to read and send email, it is usually installed. To send an email simply type "mail user@domain". The first line is the subject, then the mail content. Terminate and send the email with a single dot (.) in a new line. Example:
# mail c@cb.vu
Subject: Your text is full of typos
"For a moment, nothing happened. Then, after a second or so,
nothing continued to happen."
.
EOT
#
This is also working with a pipe:
# echo "This is the mail body" | mail c@cb.vu
This is also a simple way to test the mail server.
tar
The command tar (tape archive) creates and extracts archives of file and directories. The archive .tar is uncompressed, a compressed archive has the extension .tgz or .tar.gz (zip) or .tbz (bzip2). Do not use absolute path when creating an archive, you probably want to unpack it somewhere else. Some typical commands are:
Create
# cd /
# tar -cf home.tar home/ # archive the whole /home directory (c for create)
# tar -czf home.tgz home/ # same with zip compression
# tar -cjf home.tbz home/ # same with bzip2 compression
Only include one (or two) directories from a tree, but keep the relative structure. For example archive /usr/local/etc and /usr/local/www and the first directory in the archive should be local/.
# tar -C /usr -czf local.tgz local/etc local/www
# tar -C /usr -xzf local.tgz # To untar the local dir into /usr
# cd /usr; tar -xzf local.tgz # Is the same as above
Extract
# tar -tzf home.tgz # look inside the archive without extracting (list)
# tar -xf home.tar # extract the archive here (x for extract)
# tar -xzf home.tgz # same with zip compression
# tar -xjf home.tgz # same with bzip2 compression
# tar -xjf home.tgz home/colin/file.txt # Restore a single file
More advanced
# tar c dir/ | gzip | ssh user@remote 'dd of=dir.tgz' # arch dir/ and store remotely.
# tar cvf - `find . -print` > backup.tar # arch the current directory.
# tar -cf - -C /etc . | tar xpf - -C /backup/etc # Copy directories
# tar -cf - -C /etc . | ssh user@remote tar xpf - -C /backup/etc # Remote copy.
# tar -czf home.tgz --exclude '*.o' --exclude 'tmp/' home/
dd
The program dd (disk dump) is used to copy partitions and disks and for other copy tricks. Typical usage:
# dd if=<source> of=<target> bs=<byte size> conv=<conversion>
Important conv options:
notrunc do not truncate the output file, all zeros will be written as zeros.
noerror continue after read errors (e.g. bad blocks)
sync pad every input block with Nulls to ibs-size
The default byte size is 512 (one block). The MBR, where the partiton table is located, is on the first block, the first 63 blocks of a disk are empty. Larger byte sizes are faster to copy but require also more memory.
Backup and restore
# dd if=/dev/hda of=/dev/hdc bs=16065b # Copy disk to disk (same size)
# dd if=/dev/sda7 of /home/root.img bs=4096 conv=notrunc,noerror # Backup /
# dd if /home/root.img of=/dev/sda7 bs=4096 conv=notrunc,noerror # Restore /
# dd bs=1M if=/dev/ad4s3e | gzip -c > ad4s3e.gz # Zip the backup
# gunzip -dc ad4s3e.gz | dd of=/dev/ad0s3e bs=1M # Restore the zip
# dd bs=1M if=/dev/ad4s3e | gzip | ssh eedcoba@fry 'dd of=ad4s3e.gz' # also remote
# gunzip -dc ad4s3e.gz | ssh eedcoba@host 'dd of=/dev/ad0s3e bs=1M'
# dd if=/dev/ad0 of=/dev/ad2 skip=1 seek=1 bs=4k conv=noerror # Skip MBR
# This is necessary if the destination (ad2) is smaller.
Recover
The command dd will read every single block of the partiton, even the blocks. In case of problems it is better to use the option conv=sync,noerror so dd will skip the bad block and write zeros at the destination. Accordingly it is important to set the block size equal or smaller than the disk block size. A 1k size seems safe, set it with bs=1k. If a disk has bad sectors and the data should be recovered from a partiton, create an image file with dd, mount the image and copy the content to a new disk. With the option noerror, dd will skip the bad sectors and write zeros instead, thus only the data contained in the bad sectors will be lost.
# dd if=/dev/hda of=/dev/null bs=1m # Check for bad blocks
# dd bs=1k if=/dev/hda1 conv=sync,noerror,notrunc | gzip | ssh \ # Send to remote
root@fry 'dd of=hda1.gz bs=1k'
# dd bs=1k if=/dev/hda1 conv=sync,noerror,notrunc of=hda1.img # Store into an image
# mount -o loop /hda1.img /mnt # Mount the image
# rsync -ax /mnt/ /newdisk/ # Copy on a new disk
# dd if=/dev/hda of=/dev/hda # Refresh the magnetic state
# The above is useful to refresh a disk. It is perfectly safe, but must be unmounted.
Delete
# dd if=/dev/zero of=/dev/hdc count=1 # Delete MBR and partiton table
# dd if=/dev/zero of=/dev/hdc # Delete full disk
# dd if=/dev/urandom of=/dev/hdc # Delete full disk better
# kill -USR1 PID # View dd progress (Linux only!)
screen
Screen has two main functionalities:
Run multiple terminal session within a single terminal.
A started program is decoupled from the real terminal and can thus run in the background. The real terminal can be closed and reattached later.
Short start example
start screen with:
# screen
Within the screen session we can start a long lasting program (like top). Detach the terminal and reattach the same terminal from an other machine (over ssh for example).
# top
Now detach with Ctrl-a Ctrl-d. Reattach the terminal with
# screen -r
or better:
# screen -R -D
Attach here and now. In detail this means: If a session is running, then reattach. If necessary detach and logout remotely first. If it was not running create it and notify the user.
Screen commands (within screen)
All screen commands start with Ctrl-a.
Ctrl-a ? help and summary of functions
Ctrl-a c create an new window (terminal)
Ctrl-a Ctrl-n and Ctrl-a Ctrl-p to switch to the next or previous window in the list, by number.
Ctrl-a Ctrl-N where N is a number from 0 to 9, to switch to the corresponding window.
Ctrl-a " to get a navigable list of running windows
Ctrl-a a to clear a missed Ctrl-a
Ctrl-a Ctrl-d to disconnect and leave the session running in the background
Ctrl-a x lock the screen terminal with a password
The screen session is terminated when the program within the running terminal is closed and you logout from the terminal.
Find
Some important options:
-x (on BSD) -xdev (on Linux) Stay on the same file system (dev in fstab).
-exec cmd {} \; Execute the command and replace {} with the full path
-iname Like -name but is case insensitive
-ls Display information about the file (like ls -la)
-size n n is +-n (k M G T P)
-cmin n File's status was last changed n minutes ago.
# find . -type f ! -perm -444 # Find files not readable by all
# find . -type d ! -perm -111 # Find dirs not accessible by all
# find /home/user/ -cmin 10 -print # Files created or modified in the last 10 min.
# find . -name '*.[ch]' | xargs grep -E 'expr' # Search 'expr' in this dir and below.
# find / -name "*.core" | xargs rm # Find core dumps and delete them
# find / -name "*.core" -print -exec rm {} \; # Other syntax
# find . \( -name "*.png" -o -name "*.jpg" \) -print
# iname is not case sensitive
# find . \( -iname "*.png" -o -iname "*.jpg" \) -print -exec tar -rf images.tar {} \;
# find . -type f -name "*.txt" ! -name README.txt -print # Exclude README.txt files
# find /var/ -size +1M -exec ls -lh {} \;
# find /var/ -size +1M -ls # This is simpler
# find . -size +10M -size -50M -print
# find /usr/ports/ -name work -type d -print -exec rm -rf {} \; # Clean the ports
Find files with SUID; those file have to be kept secure
# find / -type f -user root -perm -4000 -exec ls -l {} \;
Miscellaneous
# which command # Show full path name of command
# time command # See how long a command takes to execute
# time cat # Use time as stopwatch. Ctrl-c to stop
# set | grep $USER # List the current environment
# cal -3 # Display a three month calendar
# date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
# date 10022155 # Set date and time
# whatis grep # Display a short info on the command or word
# whereis java # Search path and standard directories for word
# setenv varname value # Set env. variable varname to value (csh/tcsh)
# export varname="value" # set env. variable varname to value (sh/ksh/bash)
# pwd # Print working directory
# mkdir -p /path/to/dir # no error if existing, make parent dirs as needed
# rmdir /path/to/dir # Remove directory
# rm -rf /path/to/dir # Remove directory and its content (force)
# cp -la /dir1 /dir2 # Archive and hard link files instead of copy
# cp -lpR /dir1 /dir2 # Same for FreeBSD
# mv /dir1 /dir2 # Rename a directory |
|