Sunday, May 15, 2011

Tutorial: Move Trac and SVN configuration from old server to new server.

Today I tell you how configure Trac and SVN for developers.

Goals:
  1. We have SVN repository and Trac on first (old) server
  2. We installed SVN on second (new) server 
  3. We have python on second (new) server 
  4. We need move SVN repository from first (old) to second server
  5. We need move Trac from first to second (new) server 
  6. We need configure SVN repository with Trac

Start implementation.
SVN:
  1. Create dump SVN repository on our first server
    • Open directory with SVN repository, example: “cd /home/svn/” 
    • Create dump SVN repository, example: “svnadmin dump myrepo > myrepodump”.
      Where “myrepo” name our repository.
       
  2.  Copy dump SVN repository from first server to second server. For example: you can use command “wged”
    • Open second server 
    • Open directory for SVN, example: “cd /home/svn/”
      Note: we think that path equals on both servers 
    • Copy SVN repository from old server to new, example:
      “wget http://test.org/myrepodump”
       
  3.  Create new SVN repository and load dump
    • Create repository, example: “svnadmin create /home/svn/myrepo” 
    • Load from dump, example: “svnadmin load myrepo < myrepodump”
       
  4. Configure SVN repository access
    • Access denied for anonymous users, example:
      “nano /home/svn/myrepo/conf/svnserve.conf”
      Write next line:
      anon-access = none
      auth-access = write
      realm = myrepo repo
      added password-db = passwd
    • Add user/password in SVN repository, example:
      “nano /home/svn/myrepo/conf/passwd”
       
  5.  Start SVN service on server
    • You can use “xinetd”-service
      Create file "/etc/xinetd.d/svn"
      service svn
      {
      disable = no
      socket_type = stream
      wait = no
      user = svn
      group = svn
      groups = yes
      port = 3690
      server = /usr/bin/svnserve
      server_args = -i -r /home/svn
      log_on_failure += USERID
      }

      Restart “xinetd”-service: “/etc/init.d/xinetd restart”
    • Or you can run SVN manual, example: “svnserve -d -r /home/svn/”
       
 TRAC
  1.  Download Trac, example:
    “cd /usr/src/”
    “copy http://ftp.edgewall.com/pub/trac/trac-0.10.5.tar.gz”
  2. Extract Trac from archive, example:
    “tar xvzf Trac-0.10.5.tar.gz”
  3. Install Trac:
    “cd trac-0.10.5/”
    “python ./setup.py install”
  4. Create directory for Trac, example: "/home/trac/"
  5. Configure Trac environment, example:
    “trac-admin /home/trac/ initenv”
    Project Name [My Project]> myproject
    Database connection string [sqlite:db/trac.db]>
    Repository type [svn]> svnTemplates directory [/usr/share/trac/templates]>
  6. Configure ".htpasswd" in Trac directory (add users), example:
    “cd /home/trac/”
    “/usr/local/apache/bin/htpasswd .htpasswd new_user” , where new_user - username
  7. Download trac database and file attachments from old server to new server
    • Open old server (first server) 
    • Open Trac directory, example: “cd /home/trac/” 
    • Create archive attachments directory, example: “tar cvzf attachments.bak attachments” 
    • Create dump Trac database, example: “sqlite3 /home/trac/db/trac.db ".dump" >> sqlite_trac.sql” 
    • Open new server (second server) 
    • Download “attachments.bak” and “sqlite_trac.sql” from first server, example:
      “cd /home/trac/”
      “wget http:// test.org /attachments.bak”
      “wget http:// test.org /sqlite_trac.sql” 
    • Extract database dump, example:
      “cat sqlite_trac.sql | sqlite3 trac.db”
      “cp trac.db /home/trac/db/” 
    • Extract attachments from archive, example:
       “tar xvzf attachments.bak” 
Trac with SVN
  1.  On new server open port 8000
  2. Configure trac.ini
    • Open trac.ini, example: "nano /home/trac/conf/trac.ini"
    • Change “repository_dir”, example: “repository_dir = /home/svn/myrepo”
  3. Create create post-commit in SVN repository, example:
    • Filename: "/home/svn/myrepo/hooks/post-commit"
    • Text in file:
      /usr/bin/python /usr/src/trac-0.10.5/contrib/trac-post-commit-hook -p "/home/trac/" -r "$REV" -s "http://test.org:8000"
      Where “http://test.org:8000” – URL for Trac
    • Set “0774” permission on file "/home/svn/myrepo/hooks/post-commit"
    • Run trac with apache '.htpasswd', example:
      “/usr/bin/python /usr/bin/tracd -d -p 8000 --basic-auth=*,/home/trac/.htpasswd,myproject /home/trac”
    • Sync Trac “Browse Source” with SVN repository, example:
      “trac-admin /home/trac/ resync”
How it’s working
  1. Create new ticket in Track, example: “#1 Test work Trac with SVN” 
  2. When you commit file in SVN in comments write: “refs #1” 
  3. After this your comments appends to Trac ticket #1 
  4. You open in Trac ticket #1 and see link to your SVN revision 
  5. COOL!
Some help/clarification
  1. Check post-commit hook in line command:
    “/usr/bin/python /usr/src/trac-0.10.5/contrib/trac-post-commit-hook -p "/home/trac" -r "$1" 2>&1 1>> /home/trac/log2.txt” 
  2. Add new developer on project: 
  3. Create new entry in “/home/trac/.htpasswd”, example:
    “/usr/local/apache/bin/htpasswd .htpasswd new_user” 
  4. Add "developer" permissions to new_user, example:
    “trac-admin /home/trac permission add new_user developer” 
  5. Links
    http://trac.edgewall.org/
    http://subversion.tigris.org/
     

No comments:

Post a Comment