Wednesday, 22 August 2012
Tuesday, 21 August 2012
Monday, 20 August 2012
HTML + Javascript
Vertical - content
http://baijs.nl/tinycarousel/
http://dev.css-zibaldone.com/onwebdev/post/jquery_vertical_content_slider.html
http://baijs.nl/tinycarousel/
http://dev.css-zibaldone.com/onwebdev/post/jquery_vertical_content_slider.html
Thursday, 16 August 2012
Replicate one database mysql in ubuntu
This tutorial will go through the setup of MySQL database
replication. I will also talk about how to get everything working
smoothly again after a server crash, or if you wish to switch databases.
I will try to explain what is going on behind the scenes for every step
(something I've found missing from other tutorials). This is written
specifically for MySQL 5.0 on Centos 4, but should be very similar on
other Linux distributions. It should also work this way with MySQL 4.x.
You should follow the instructions below with two console windows open - one for the Master and one for the Slave. Also note that I will capitalise the first letters of Master and Slave to indicate I am talking about the servers.
mysql -u root -p (log into MySQL)
The second line chooses the database to write the log for. You should change this to your database. The third line gives the server an ID (to distinguish it from the Slave).
You should also make sure
You should now restart the Master:
The remaining lines set a retry limit, and tell the Slave the user, password and database it needs to replicate. We also tell the slave what to use as its relay log. It's best to set this directly, or MySQL will create the name from the hostname and should you change hostname, replication will fail.
You should also make sure
You should now restart the Slave:
mysql -u root -p (log into MySQL)
mysql -u root -p (log into MySQL)
mysql -u root -p (log into MySQL)
mysql -u root -p (log into MySQL)
The Slave will now be waiting. So all that's left is to...
The theory
We have 2 servers, one of which is a Master and the other which is a Slave. We tell the Master that it should keep a log of every action performed on it. We tell the slave server that it should look at this log on the Master and whenever something new happens, it should do the same thing.You should follow the instructions below with two console windows open - one for the Master and one for the Slave. Also note that I will capitalise the first letters of Master and Slave to indicate I am talking about the servers.
Configuring the Master
First of all, we need to create a user on the Master server that the Slave will connect as. I call mine 'slave_user'. Log into mysql as root and create the user:mysql -u root -p (log into MySQL)
CODE:
Now, we should edit the my.cnf file (usually in /etc/my.cnf), in the
[mysqld] section and tell MySQL that it's going to be a Master:
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
FLUSH PRIVILEGES;
CODE:
The first line tells MySQL to start writing a log, and tells it where
to write the log. Make sure this directory is empty of all replication
logs, especially if you're starting again after replication has already
been used.
log-bin = /home/mysql/logs/mysql-bin.log
binlog-do-db=my_database
server-id=1
binlog-do-db=my_database
server-id=1
The second line chooses the database to write the log for. You should change this to your database. The third line gives the server an ID (to distinguish it from the Slave).
You should also make sure
skip-networking
has not been enabled.You should now restart the Master:
CODE:
(MySQL restart commands may vary)
/etc/rc.d/init.d/mysqld restart
Configuring the Slave
Again, we should change the /etc/my.cnf of the Slave server, in the [mysqld] section:
CODE:
Line 1 gives the Slave its unique ID. Line 2, tells the Slave the I.P
address of the Master server - so you need to change the I.P here.
server-id=2
master-host=128.0.0.1
master-connect-retry=60
master-user=slave_user
master-password=slave_password
replicate-do-db=my_database relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
master-host=128.0.0.1
master-connect-retry=60
master-user=slave_user
master-password=slave_password
replicate-do-db=my_database relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
The remaining lines set a retry limit, and tell the Slave the user, password and database it needs to replicate. We also tell the slave what to use as its relay log. It's best to set this directly, or MySQL will create the name from the hostname and should you change hostname, replication will fail.
You should also make sure
skip-networking
has not been enabled.You should now restart the Slave:
CODE:
/etc/rc.d/init.d/mysqld restart
Getting the data onto the Slave
On the Master...
I'm assuming you have a live Master server, and an as yet empty Slave server. This stage depends on whether data is constantly being added to the Master. If so, we will have to prevent all database access on the Master so nothing can be added. This means your server will hang during the next step. If no data is being added to the server, you can skip this step. On the Master server, log into MySQL and do the following:mysql -u root -p (log into MySQL)
CODE:
Now we will use mysqldump to get the data out. So, still on the Master server:
FLUSH TABLES WITH READ LOCK;
CODE:
Make sure you change my_database to your database name, and my_home_dir to the name of your home directory (or another directory of your choosing). You wll now have a file called database.sql.gz in your home directory. This is a gziped copy of your database.
mysqldump my_database -u root -p > /home/my_home_dir/database.sql;
gzip /home/my_home_dir/database.sql;
gzip /home/my_home_dir/database.sql;
On the Slave...
Now we need to copy over the gzipped file. On the Slave run the following:
CODE:
Make sure 128.0.0.1 is the I.P of the Master. This will copy the file
from the Master and put it in your home directory on the Slave. Now we
just need to import into MySQL:
scp root@128.0.0.1:/home/my_home_dir/database.sql.gz /home/my_home_dir/
mysql -u root -p (log into MySQL)
CODE:
CREATE DATABASE `my_database`;
CODE:
gunzip /home/my_home_dir/database.sql.gz
mysql -u root -p my_database </home/my_home_dir/database.sql
mysql -u root -p my_database </home/my_home_dir/database.sql
Ready to rumble...
On the Master...
Now we're ready to kick things off. We need to find the position the Master is at in the logs. So, log into MySQL and run the following:mysql -u root -p (log into MySQL)
CODE:
This should give you an output along these lines:
SHOW MASTER STATUS;
CODE:
Keep that on-screen.
+---------------------+----------+-------------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+-------------------------------+------------------+
| mysql-bin.000001 | 21197930 | my_database,my_database | |
+---------------------+----------+-------------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+-------------------------------+------------------+
| mysql-bin.000001 | 21197930 | my_database,my_database | |
+---------------------+----------+-------------------------------+------------------+
On the Slave...
Log into MySQL and do the following:mysql -u root -p (log into MySQL)
CODE:
First we stop the Slave. Then we tell it exactly where to look in the
Master log file. We use the values for our previous SHOW MASTER STATUS;
command on the Master. You should change 128.0.0.1 to the I.P of the
Master, and change the user and password accordingly.
slave stop;
CHANGE MASTER TO MASTER_HOST='128.0.0.1', MASTER_USER='slave_user', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=21197930;
slave start;
CHANGE MASTER TO MASTER_HOST='128.0.0.1', MASTER_USER='slave_user', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=21197930;
slave start;
The Slave will now be waiting. So all that's left is to...
Back on the Master...
We shoud already be logged into MySQL, so all you have to do is:
CODE:
To release the tables from lock. Note you only have to do this if you previously ran FLUSH TABLES WITH READ LOCK;
unlock tables;
And the recovery part?
Several times it's happened to me that a server has crashed, or a hostname changed or whatever, and I've had a real trouble getting replication to work again. The solution has been to clear out the logs.On the Slave
Clear out any replication logs from /var/lib/mysql or whever the logs are being stored, as stated in my.cnf. This usually does the trick:
CODE:
rm *relay*
rm master.info
rm master.info
On the Master
Again, get rid of the logs, as per where they are stored in my.cnf. For me it's the following:
CODE:
This should give you a fresh start on things. You can now start again from the beginning...
cd /home/mysql/logs/
rm -f *
rm -f *
Final Notes
My database doesn't use InnoDB tables - it's all MyISAM. However, the MySQL manual recommends adding this to my.cnf for InnoDB databases:
CODE:
See here for more info: http://dev.mysql.com/doc/refman/5.1/en/replication-howto-masterbaseconfig.html
innodb_flush_log_at_trx_commit=1
sync_binlog=1
sync_binlog=1
Wednesday, 15 August 2012
SQL command line
dump file sql
mysqldump -umytable -p -hserver DatabseName TableName > test.sql;
dump file gz
mysqldump -umytable -p -hserver DatabseName TableName | gzip > test.gz;
unzip mysql dump
gunzip < filename.gz | mysql -uphuc.duong -p -hlocalhost DatabseName;
mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]
mysqldump -umytable -p -hserver DatabseName TableName > test.sql;
dump file gz
mysqldump -umytable -p -hserver DatabseName TableName | gzip > test.gz;
unzip mysql dump
gunzip < filename.gz | mysql -uphuc.duong -p -hlocalhost DatabseName;
mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]
Wednesday, 8 August 2012
5 Vi du ve htaccess
Xin chào các bạn, nhất là những bạn đã đang và sẽ là một webmaster
Bạn là một WM ắt hẳn phải chú trọng đến việc quảng bá website để thu hút traffic. Có rất nhiều yếu tố để đạt được yêu cầu đó mà trong khuôn khổ bài viết hạn hẹp này Việt Coding không thể nói hết. Việt Coding chỉ nói đến việc “viết lại” (rewrite) đường dẫn web (url) của bạn cho đẹp, cho dễ nhớ, nói chung là thân thiện. Thân thiện với cả visitor và các search engine. Bạn nghĩ sao nếu phải gõ tay hoặc copy dòng địa chỉ này paste vào trình duyệt :
/index.php?option=com_content&view=article&id=25:bai-hc-t-cuc-sng&catid=1:news-tonghop&joscclean=1&comment_id=473#josc473
hay bạn chỉ muốn gõ đơn giản như vầy:
/article/25/bai-hoc-tu-cuoc-song/
Tôi có cần trả lời giùm bạn không nhỉ ?
Bài viết dưới đây sẽ hướng dẫn các bạn sử dụng sức mạnh của tập tin .htaccess, qua đó viết lại đường dẫn website của bạn một cách thân thiện (friendly url).
Hy vọng bạn chưa quên một bài viết khác của Việt Coding cũng nói về .htaccess : Bảo vệ băng thông webblog của bạn bằng htaccess ?
Đây là 5 ví dụ thông dụng nhất:
1. product.php?id=12 —> product-12.html
Đây là một ví dụ cực kỳ cơ bản của rewrite url, thường dùng để che dấu đuôi PHP:
RewriteEngine on
RewriteRule ^product-([0-9]+).html$ product.php?id=$1
2. product.php?id=12 —> product/ipod-nano/12.html
Một SEO chuyên nghiệp luôn biết khéo léo hiển thị từ khoá chính trên URL. Như trong ví dụ sau, URL hiển thị tên của sản phẩm chính:
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+).html$ product.php?id=$2
3. Non www URL —> www URL
Nếu bạn muốn khi visitor gõ vào trình duyệt vietcoding.com thì được chuyển thẳng vào www.vietcoding.com thì cấu hình như sau:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^vietcoding.com$
RewriteRule (.*) http://www.vietcoding.com/$1 [R=301,L]
4) vietcoding.com/user.php?username=xyz —> vietcoding.com/xyz
Nếu website của bạn có một lượng lớn thành viên (như mạng xã hội, diễn đàn), đây là một cách rất hay để rút gọn liên kết cho thành viên dễ nhớ
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
5) Chuyển domain vào cấp thư mục:
Trong quá trình phát triển website, luôn luôn có sự thay đổi (về mã nguồn, cơ sở dữ liệu, cấu trúc site,…). Ví dụ vietcoding.com trước giờ vẫn chạy ở thư mục gốc (root), giả sử vì một lý do nào đó, Việt Coding cần dùng root cho việc khác và muốn chuyển webblog hiện tại vào thư mục /blog/ thì sao ?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^vietcoding.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.vietcoding.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1
Thế là xong ! Từ nay mọi truy vấn đến vietcoding.com hoặc www.vietcoding.com đều được redirect vào vietcoding.com/blog
Tất nhiên, URL rewriting rất đa dạng và phong phú, tuỳ sự sáng tạo của từng webmaster mà sẽ cho ra những url độc đáo không đụng hàng, ví dụ như:
http://abc.com/Music/#List_Album2,-1,1http://abc.com/Products/#IPhone|3GS|32G
Monday, 23 July 2012
SVN command
Subversion Commands: |
Command | Description |
---|---|
svn --help | List Subversion commands |
svn help command Also: ? or h |
Help on given "command" |
svn add filename
svn add directory |
Add a file or directory to Subversion CM control. Must also perform: svn ci filename (or svn commit) to upload the file or directory. File will not be available in the repository until a "commit" is performed. If adding a directory, the directory and all of its contents recursively are added. i.e.: svn ci directory svn commit directory svn commit . |
svn blame filename svn blame -r RevisionNumber filename Also: praise, annotate, ann |
Show file contents with revisions annotated with author information. |
svn cat filename | List contents of file under Subversion control. |
svn checkout http://node-name/repos/svn/trunk/parentPath/path This creates: path/file1 path/file2 ... svn checkout http://node-name/repos/svn/trunk/parentPath . This creates: path/file1 path/file2 ... Note the difference a "." makes. svn checkout file:///repos/svn/trunk/path/ svn co -r 497 http://node-name/repos/svn/trunk/path file-name Also: svn co https://..., svn://..., and svn+ssh:// MS/Windows: svn co file:///c:/repository/project/trunk |
Checkout every file from the path and subdirectories specified below. Creates "working" copy of files and directories. Checkout a repository. Use option "-r" to specify a specific revision other than the latest. The URL "svn://" communicates with an SVN server (port 3690) The URL "http://" comunicates with the Apache server and module mod_dav_svn (port 80) [more common server] |
svn cleanup | Cleanup subversion files resulting from escaped processes and crashed. |
svn commit filename svn commit --message "Message goes here." filename svn commit -m "Message goes here." filename svn ci filename1 filename2 filename3 svn ci . |
Check-in (commit) local "working" file, files or directory and contents (recursively) into Subversion repository. Atomic, i.e. all committed or none, no incomplete check-in. |
svn copy source destination_clone Also: svn cp ... |
Copy file or directory tree. One can copy from one local working copy to another or to repository server URL's. The sources and destinations can be working copies or URLs. |
svn copy http://host/repos/project/trunk http://host/repos/project/tags/TagName-1.4.5 -m "Tag Release 1.4.5" | Tag a release. Takes a snapshot of the repository and assigns a name. This can be performed at any directory branch. |
svn copy . http://host/repos/project/tags/TagName-1.4.5 -m "Tag Release 1.4.5" | Tag a release. Takes a snapshot of your local working copy and assigns a name. This can be performed at any directory branch. |
svn delete filename svn delete directory Also: del, remove or rm svn rm http://host/repos/project/trunk/file-or-directory |
Delete file from repository. The UNIX command rm file-name. Must perform a "commit" to update the repository and local working directory with the changes. i.e.: svn commit . |
svn diff filename svn di filename |
Show file diffs between SVN repository and your file changes using GNU file diff format. Use GUI diff tools as shown below. |
svn diff -r rev1:rev2 filename | Show file diffs between specified versions. Example: svn diff -r 456:459 subfn.cpp Using GUI diff tool: svn diff -r 457:459 --diff-cmd kdiff3 file-name |
svn diff filename > patch-file | Generate patch file used by the patch command. |
svn export directory | Export directory tree to your file system but it will not be a "working directory" under SVN control. |
svn export -r Rev-Number http://node-name/path | Export directory tree of specified version and create local directory tree and files not under SVN control. |
svn import local-directory http://node/repos/svn/trunk/directory | Add directory (and files in it recursively) to path in repository specified. |
svn info filename | Display information about file or directory. (Date modified, author, revision, path in repository.) Can not specify a URL. |
svn list directory svn list file-name |
List file or directory of files in repository. Used to browse repository before checkout. If current directory is given (svn list ./), then Subversion will list the repository URL of the current directory. |
svn list -r RevisionNumber directory | List directory of files in repository in specified revision. |
svn lock filename -m "comment as to why its locked or by whom" (Comment is not required but is often useful) |
Lock file to grant exclusive access to one and forbid all others. A commit will unlock the file (unless the "--no-unlock" option is used). A lock can be removed with the commands: svn unlock filename, svnlook and the svnadmin comands (i.e. List: svnadmin lslocks and remove: svnadmin rmlocks filename). |
svn log filename svn log . svn log http://URL/path/file svn log -v . svn log -r RevisionNumber http://URL/path/file |
Show the Subversion log messages for a set of revision(s) and/or file(s) and/or all directory contents in repository. List verbose. Includes list of all files in change Shows the file changes associated with revision number. |
svn merge http://url/path/branch1 http://url/path/branch2 working-local-dir svn merge file1@revJ file2@revK svn merge -r 414:411 http://url/path working-dir svn merge -r 413:HEAD file-name |
Merge directory changes into your current
working directory or merge a file in Subversion into the file in your
working directory. If target is not specified, the identical basename
or current directory is assumed. Used to incorporate changes checked in
which are not accounted for in your file or to merge branches. Example using GUI merge tool: svn diff -r 459:454 --diff-cmd kdiff3 --extensions '-m' file-name Next, tell subversion that the conflicts have been resolved: svn resolve file-name Finally, check-in file: svn ci file-name or abort changes: svn revert file-name |
svn merge --dry-run -r 414:413 http://url/path | Test merge. No changes are made to your local working copy but shows Subversion feedback as if merge was performed. |
svn merge -r 414:413 http://url/path svn merge -r 414:413 . |
Undo changes committed in revision 414. |
svn mkdir directory svn mkdir http://URL/directory |
Create a new directory under version control. |
svn move directory1 directory2 svn mv directory1 directory2 svn mv file-old-name file-new-name |
Rename or move a file or directory. Moves/renames file/directory in repository and in local work area. Must perform svn ci file-new-name after the move for changes to to take place in repository. |
svn revert filename | Undo changes in local work files. Throw away local changes. |
svn resolved filename | Run this command after resolving merge conflicts. Next "commit" your changes. |
svn status svn status -u svn status -u . svn status -uq . |
Show status of file changes in current directory and recursively in directories below. Show out of date file info: svn status --show-updates (equivalent: svn status -u) -u: Determines status by comparing your local repository with the server repository. Without this option, the status shown will only be the changes you have made in your local repository. -q: Quiet. Do not print "?: File/directory not under version control" or "!: File/directory missing" extraneous information. First collumn:
|
svn switch http://server/new-branch svn switch --relocate http://server/old-path http://server/new-path |
Switch your local working copy to mirror a new repository branch instead of main trunk or previous branch. Also allows you to point your repository to a new path on the server if the server path changes since you performed a check-out. |
svn update svn update filename svn update -r458 filename svn update --ignore-externals ./ |
Migrate all updates from Subversion
repository to your local copy (recusively for all files in the current
directory and all below it). If there have been updates to the svn
repository since you downloaded the files, subversion will give you the
opportunity to merge. Status of files will use the coding as stated
above for "status". Files marked with a "C" (conflict) should be merged
of reverted. If merged then one can perform a "resolve" and then a
"check-in". If a file name is specified, only that file is updated. Can also syncronize to a specified revision given by -r. Use --ignore-externals to avoid the slow processing of externals to a potentially slow distant internet server. |
- HEAD: The latest revision in the repository.
- BASE: The "pristine" revision of an item in a working copy. Matches checked out version before any modifications.
- COMMITTED: The last revision in which an item changed before (or at) BASE.
- PREV: The revision just before the last revision in which an item changed. (Technically, COMMITTED - 1.)
Example Session:
(Assumes that the repository has already been created. For Subversion repository creation and Subversion server configuration, see the (YoLinux Subversion and Trac tutorial)- Checkout: svn checkout http://svnserver/repos/svn/trunk/Project1
- Go to source code directory: cd Project1/src
- Edit files:
- vi file1.cpp
- vi file2.cpp
- Verify and test: make
We are ready to check-in the files into the Subversion repository. - Check repository and report on new revisions and changes others have checked in: svn status -u .
- After many long hours or days of editing and work, get updates others have made: svn update
U file.h C file1.cpp G file2.cpp ? a.out
You will see:- U: File was updated with a newer version checked-in since your checkout.
- G: Automatically merged with no conflicts.
- C: Not merged due to conflicts. You made changes to the same section of code as the update made by someone else since your checkout.
- For each "conflicted" file there will be three new local files generated by "update":
- file1.cpp.mine (File - post editing)
- file1.cpp.rold (BASE - pre editing)
- file1.cpp.rnew (HEAD - Updated file from repository)
At this point, a check-in will fail until the merge is resolved. - Merge options:
- Edit the file file1.cpp
Text markers are placed in the file to show the conflicts between the "HEAD" and "mine" versions.
OR - tkdiff -conflict file1.cpp
OR - Use a GUI merge tool: kdiff3 file1.cpp.mine file1.cpp.rnew -o file1.cpp
OR - Throw out your changes/abort: svn revert file1.cpp
No resolve or check-in necessary if file is reverted.
- Edit the file file1.cpp
- Verify and test, again: make
- Notify Subversion that conflicts have been resolved: svn resolved file1.cpp
Note: This also removes the temporary files ".mine" and ".r###". - Check-in to Subversion repository: svn ci -m "Add comments here" file1.cpp
Subversion Peg revisions: |
$ svn command -r OPERATIVE-REV item@PEG-REV
The default peg revision is BASE for working copy items and HEAD for repository URLs. When no operative revision is provided, it defaults to being the same revision as the peg revision.
The PEG-REV is specified if the resource (file/directory) in question use to appear in a directory which is no longer in the same place or no longer exists. The "peg-revision" must be specified so subversion can look at the directory in that revision so it can find the resource.
If a peg revision is specified without an operative revision, then the operative revision is assumed to be the same as the peg revision.
For more see: http://svnbook.red-bean.com/en/1.5/svn.advanced.pegrevs.html
Subversion Properties: |
The following properties can be set on entities stored in Subversion:
Property | Description | ||||
---|---|---|---|---|---|
svn:ignore | A newline separated list of file patterns to ignore. List of files/directories to be ignored by svn status | ||||
svn:keywords | Valid RCS style keywords are:
|
||||
svn:executable | Ensure file attribute is executable. Possible values: ON, OFF Example: svn propset svn:executable ON app.exe |
||||
svn:eol-style | One of 'native', 'LF', 'CR', 'CRLF'. Specify and maintain specified line ending for text file.
|
||||
svn:mime-type | The mime type of the file:
|
||||
svn:needs-lock | Prevents conflicts for files which can not be contextually merged. i.e. photos, binaries, object libraries. | ||||
svn:externals | List of files or directories pointed to. Locate repository where directory specified should be retrieved. The directive propset is not required:
svn propedit svn:externals local-target-dir
svn commit svn propget svn:externals ./ The property applies to the directory. Subversion can not list or web browse svn:externals. Check-out ("co"), "export" and "log" can be performed. Must set environment variable "EDITOR", "SVN_EDITOR", "VISUAL" or set the Subversion configuration file (~/.subversion/config) attribute editor-cmd. i.e.: export EDITOR=vi Note: Subversion 1.6 introduces file externals in addition to directory externals. The files however must reside in the same repository. Also, the file must point to a location which exists in your local working directory. [Potential Pitfall]: Apply svn externals to directories and not files. (version 1.4) [Potential Pitfall]: If generating a tag (branch), one should assign the revision number to the external link to truly snapshot the repository for that tag. This revision number should be specified in the tagged branch version of the svn external. [Potential Pitfall]: The revision numbers shown by svn info will reflect the version numbers of the repository in which the files are stored. If the files are imported via an svn external directory, the revision numbers will reflect that of the external repository which the external points to and thus from where the files were imported. |
Command | Description |
---|---|
svn propdel PropertyName file-name svn propdel --revprop -r RevisionName http://url/path Also: pdel, pd |
Remove property name from files or directories. Remove properties on file in repository. |
svn propedit PropertyName file-name svn propedit --revprop -r RevisionName http://url/path Also: pedit, pe |
Edit property name of files or directories. Edit properties on file in repository. |
svn propget PropertyName file-name svn propget --revprop -r RevisionName http://url/path Also: pget, pg |
Print value of property name of files or directories. Print properties on file in repository. |
svn proplist file-name svn proplist * svn proplist --revprop -r RevisionName http://url/path Also: plist, pl |
List properties of file, files or directory. |
svn propset PROPNAME PropertyValue file-name svn propset PROPNAME --revprop -r RevisionName PropertyValue http://url/path svn propset svn:mime-type text/html file-name.dat Also: pset, ps |
Set properties of file or directory. Set mime type for a file in the repository. Must perform a commit to upload changes to the repository. Set file properties so that "^M"'s are removed upon check-in: svn propset svn:eol-style LF file-name.txt See YoLinux Subversion server configuration tutorial: No ctrl-M. |
Subversion and Graphical diffs for Linux: |
- Show file differences made since checkout was made. This shows the changes you have made. It is usefull to perform this before an update.
- Show file differences between two files versions stored in Subversion.
- Show differences / conflicts, choose and merge. Use our bash script svndiffwrapper which integrates into Subversion's file check-in process.
1) File differences since checkout: |
Use the following bash shell script to use the graphical diff tool "mgdiff" with Subversion.
-
svndiff:
01
#!/bin/bash
02
# svndiff 1.0
03
# usage: svndiff file
04
05
if
[[ ! -d .svn ]]
06
then
07
echo
ERROR: You are not working
in
an SVN directory.
08
exit
1
09
fi
10
11
rev=
"--revision HEAD"
12
13
if
[[ ! -n $1 ]]
14
then
15
echo
"Usage: svndiff [option] file"
16
echo
"Options:"
17
echo
" -h Diff with latest in repository (HEAD) - Default"
18
echo
" -b Diff with what you had checked out (BASE)"
19
echo
" -c Diff with COMMITTED, the version before BASE"
20
echo
" -p Diff with PREV, the version before COMMITTED"
21
echo
" -r revnum Diff with specified revision (specify integer)"
22
exit
1
23
fi
24
25
while
getopts
":r:hbcp"
Option
26
do
27
case
$Option
in
28
h) rev=
"--revision HEAD"
;;
29
b) rev=
"--revision BASE"
;;
30
c) rev=
"--revision COMMITTED"
;;
31
p) rev=
"--revision PREV"
;;
32
r) rev=
"--revision $OPTARG"
;;
33
*)
echo
"Incorrect option specified. Use -h or -b or -r #"
;;
34
esac
35
done
36
shift
$(($OPTIND -1))
37
38
# Define graphical diff tool
39
#
40
41
# The geometry option used by Motif, Tcl and X based programs
42
geometry=
"-geometry 1280x800+0+0"
43
44
# The following is for Motif diff
45
# -w: ignore white space
46
dif=
"mgdiff -args -w"
47
48
file
=$1
49
prev=${
file
}_PREV
50
51
# Trap bash command signals
52
# SIGINT 2
53
# SIGQUIT 3
54
# SIGTERM 15
55
trap
"rm -f $prev"
2 3 15
56
svn
cat
$rev $
file
> $prev 2>/dev/null
57
$dif $geometry $prev $
file
58
59
sleep
1
60
rm
-f $prev
Use the following bash shell script to use the graphical diff tool "gvimdiff:" with Subversion:
-
svndiff:
01
#!/bin/bash
02
# usage: svndiff file
03
04
if
[[ ! -d .svn ]]
05
then
06
echo
ERROR: You are not working
in
an SVN directory.
07
exit
1
08
fi
09
10
# Define graphical diff tool
11
#
12
13
dif=
"gvimdiff \"+colo morning\" -R"
14
15
file
=$1
16
prev=PREV_${
file
}
17
18
# Trap bash command signals
19
# SIGINT 2
20
# SIGQUIT 3
21
# SIGTERM 15
22
trap
"rm -f $prev"
2 3 15
23
svn
cat
$
file
> $prev 2>/dev/null
24
$dif $prev $
file
25
26
# Sleep for non-blocking apps like gvimdiff.
27
# Allow gvimdiff to read file before it is deleted.
28
sleep
2
29
rm
-f $prev
2) File differences between two revisions: |
Some diff tools are supported with native svn. i.e.: svn diff -r 457:459 --diff-cmd kdiff3 file-name while others require a wrapper script to arrange the arguments correctly.
Subversion configurations and defaults are specified in the file: $HOME/.subversion/config
-
.. ... [helpers] editor-cmd = gedit diff-cmd = /opt/bin/diffScript diff3-cmd = /opt/bin/diff3Script ... ..
File: /opt/bin/diffScript01
#!/bin/bash
02
03
LeftLabel=$3
04
RightLabel=$5
05
LeftFile=$6
06
RightFile=$7
07
08
#gtkdiff $LeftFile $RightFile
09
tkdiff $LeftFile $RightFile -L
"$LeftLabel"
-L
"$RightLabel"
&
10
11
# wait for command to finish
12
wait
-
.. ... [helpers] diff-cmd = echo ... ..
3) Conflicts, file differences and merge: |
- tkdiff: Subversion conflict resolution merge: tkdiff -conflict file1.cpp
Select from tkdiff toolbar: "Merge" + "Show Merge Window" to open third results window.
- kdiff3 diff and merge: svn diff -r 457:459 --diff-cmd kdiff3 --extensions '-m' file-name
- svndiffwrapper: Bash script to add options to Merge|Ignore|Accept|Revert etc as a result of a check-in. This script does it all!!
-
Edit file: $HOME/.subversion/config
... [helpers] diff-cmd = svndiffwrapper diff3-cmd = svndiffwrapper ...
Place the script in /opt/bin/ for global use or $HOME/bin/ for private user access and set permissions so that script execution is allowed: chmod ugo+x /opt/bin/svndiffwrapper -
Edit file: $HOME/.subversion/config
List of graphical diff and merge tools: |
- tkdiff: [download] Comes with tkcvs Subversion GUI front-end.
Examples of Subversion diffs with tkdiff: (See: tkdiff --help)- tkdiff old-URL@revA new-URL@revB
- tkdiff -r457 -r459 file-name
- gtkdiff: Has diff3 and merge features. Written with GTK+. After gtkdiff-0.8.0, GNOME desktop required.
- diffUse: Diff/merge GUI tool. Good line matching features. Supports Unicode.
- kdiff3:
Graphical directory and file diff, merge and edit. KDE3/Qt based.
Supports drag and drop. Comes with S.u.S.E. distro. (Cross platform)
MS/Windows download available. A very good directory and file diff and
merge tool.
- Difference: kdiff3 file1 file2
- Difference: kdiff3 file1 file2 file3
- Difference of two files: kdiff3 directory1/file directory2
- Difference: kdiff3 directory1 directory2
- Merge: kdiff3 directory1 directory2 -o dest-directory
- Merge: kdiff3 file1 file2 -m
- Merge: kdiff3 file1 file2 -o output-file
- Diff with SVN: svn diff -r 457:459 --diff-cmd kdiff3 file-name
- Kompare: Ships with (RHEL5/RHEL4/FC3+) KDE SDK. [manual]
Included in RPM package "kdesdk".
[Potential Pitfall]: RPM installation error:error: Failed dependencies: perl(DCOP) is needed by kdesdk-3.5.4-3.el5.i386
Solution: Install the dependency package "kdebindings". - mgdiff: [download] Motif-based graphical file difference browser and merge. Comes with S.u.S.E. distro.
- Meld: Compare, edit and merge.
- fldiff: Graphical file and directory diff. (Cross platform)
- xxdiff: Compare 2 or 3 files and merge. Also compares directories.
- gvim and gvimdiff
- Beyond Compare - commercial tool (cross platform)
Subversion GUI interfaces for Linux: |
- TkSVN / TkCVS:
Tcl/Tk based GUI. A very good Unix/Linux and MS/Windows GUI front-end
to Subversion. Simple to install (requires tk). Supports GUI
diff/merge, branching, tagging, editing, check-in/check-out, ...
Installation to /usr/local/bin and lib (Add to your path.): (requires RPM: tk version 8.4+)- tar xzf tkcvs_8_0_3.tar.gz
- cd tkcvs_8_0_3
- ./doinstall.tcl -nox /opt
-
Set default editor and diff tool:
... set cvscfg(editor) "xterm -e vim" set cvscfg(tkdiff) "tkdiff"
Sets default editors for various file types. Set editor to "gedit" for rookies.
- Tigris.org: RapidSVN: Dependent on wxWidgets cross platform C++ GUI API.
Download RPMs from RpmForge.org:- rapidsvn-0.7.2-1.2.el4.rf.i386.rpm
- wxGTK-2.4.2-5.2.el4.rf.i386.rpm
- pysvn: Python subversion front-end. (cross platform) [download]
- eSVN: qt based GUI. Mediocre.
- KdeSvn: KDE front-end.
- Subcommander: Subversion GUI client with visual diff and merge tool with support for different text encodings
- Subview: GTK based subversion (1.3+) client.
- JSVN: Java SVN client
- Syncro SVN Client - Commercial product. Editor, diff tool and SVN client in one integrated tool.
Web Clients:
- Kamikaze-qscm: Web based front-end similar to Mozilla Bonsai.
- WebClient for SVN: Implemented in JSP for Tomcat 4
- ViewSVN: PHP4
- Easy SVN: PERL cgi
Plug-ins:
- Rabbitvcs: GNOME
Nautilus file browser SVN plug-in. Google code project to develop
TortoiseSVN clone in Linux Nautilus file manager. Best prospect for my
next favorite SVN client. Will also support other Gnome applications.
YoLinux RabbitVCS tutorial - NaughtySVN: GNOME Nautilus file browser SVN plug-in.
- Ksvn: Subversion client plugin for the KDE Konqueror browser.
- Eclipse plug-ins:
Subversion Security Tips: |
Here are three solutions to reduce this potential security vulnerability:
- Don't allow Subversion to cache the password:
svn commit -F file.txt --no-auth-cache
This will request a username and password but will not store it. - Set the Subversion configuration file on server to not cache:
-
[auth] store-auth-creds = no
-
- Delete cached files when you logout. Reduces risk but does not eliminate it.
This uses the bash shell logout script to perform a clean-up of the authentication files.
-
File: ~/.bash_logout
1
rm
~/.subversion/auth/svn.simple/*
-
File: ~/.bash_logout
Subversion utility commands and scripts: |
-
Command Description svnversion local-path This svn admin command will produce a compact version number for a working copy. Lists range of versions, adds "S" if switched, "M" modified. svnchangesince Shows the changes to the subversion repository since the local copy was last updated. svnlastlog Displays the last log message that pertains to the current working copy. Simplified svnlastchange. svnlastchange Displays the last log message and a unified diff of the changes made in the last commit. svn-clean Removes all the files and directories that are not in Subversion.
Subscribe to:
Posts (Atom)