Showing posts with label SVN. Show all posts
Showing posts with label SVN. Show all posts

Monday, September 7, 2009

Setting up a Subversion Server under Windows

A) Download SubversionYou'll need the latest version of..

B) Install Subversion

  1. Unzip the Windows binaries to a folder of your choice. I chose c:\program files\subversion\ as my path.

  2. Now, add the subversion binaries to the path environment variable for the machine. I used %programfiles%\subversion\bin\

  3. You'll also need another environment variable, SVN_EDITOR, set to the text editor of your choice. I used c:\windows\notepad.exe


C) Create a Repository

  1. Open a command prompt and type
    svnadmin create "c:\Documents and Settings\Subversion Repository"


  2. Navigate to the folder we just created. Within that folder, uncomment the following lines in the /conf/svnserve.conf file:
    [general]
    anon-access = read
    auth-access = write
    password-db = passwd

    Next, uncomment these lines in the /conf/passwd file:
    [users]
    harry = harryssecret
    sally = sallyssecret



D) Verify that everything is working

  1. Start the subversion server by issuing this command in the command window:
    svnserve --daemon --root "C:\Documents and Settings\Subversion Repository"


  2. Create a project by opening a second command window and entering this command:
    svn mkdir svn://localhost/myproject

    It's a standard Subversion convention to have three folders at the root of a project:
    /trunk
    /branches
    /tags


  3. At this point, Notepad should launch:Enter any comment you want at the top of the file, then save and exit.

  4. You'll now be prompted for credentials. In my case I was prompted for the administrator credentials as well:
    Authentication realm:  0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
    Password for 'Administrator': *********
    Authentication realm: 0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
    Username: sally
    Password for 'sally': ************

    Committed revision 1.

    Congratulations! You just checked a change into Subversion!


E) Start the server as a service

  1. Stop the existing command window that's running svnserve by pressing CTRL+C.

  2. Copy the file SVNService.exe from the zip file of the same name to the subversion\bin folder.

  3. Install the service by issuing the following commands:
    svnservice -install --daemon --root "C:\Documents and Settings\Subversion Repository"
    sc config svnservice start= auto
    net start svnservice


  4. Test the new service by listing all the files in the repository:
    svn ls svn://localhost/

    You should see the single project we created earlier, myproject/


F) Set up the shell extension

  1. Run the TortoiseSVN installer. It will tell you to restart, but you don't need to.

  2. Create a project folder somewhere on your hard drive. Right click in that folder and select "SVN Checkout..."type svn://localhost/myproject/ for the repository URL and click OK.


  3. Create a new file in that directory. Right click the file and select "TortoiseSVN, Add"

  4. The file hasn't actually been checked in yet. Subversion batches any changes and commits them as one atomic operation. To send all your changes to the server, right click and select "SVN Commit":


And we're done! You now have a networked Subversion server and client set up on your machine. Note that the default port for svnserve is 3690.

For more tips on using subversion, take a look at the free O'Reilly Subversion book.

Wednesday, January 21, 2009

How to backup SVN repository

How to backup SVN repository

Nếu bạn thường hay sử dụng svn subversion để quản lý các project, thì việc backup định kỳ là rất cần thiết. Nếu lỡ ngày nào đó, svn server của bạn bị hỏng hoặc OS bị hư …. thì dữ liệu của bạn cũng có thể mất trắng, rơi vào hoàn cảnh như vậy thì bạn sẽ thấy tầm quan trọng của việc backup data là như thế nào. Có rất nhiều cách để backup repository.
  1. Cách đơn giản nhất là copy nguyên repository ra một nơi nào đó (usb, DVD, CD).
  2. Nếu bạn có dùng TortoiseSVN on window, thì bạn cũng có thể sử dụng chức năng export để backup, bằng cách chọn TortoiseSVN -> Export . Sau đó thì bạn chỉ định path để export
  3. Dùng command line.

Cách 1 chắc không có gì để nói thêm. Cách 2 thì cũng thủ công, nếu trong repository có 100 project, chẳng lẽ bạn backup từng project một, rất tốn thời gian. Bài này đề cập đến cách thứ 3, dùng command line để backup.

Cách thứ 3 là bạn thực hiện dump toàn bộ repository ra một file nào đó. Cách thực hiện như sau :

Open command line window

svnadmin dump [your repository location] > [destination file]

Ví dụ :

svnadmin dump /usr/local/svn_repos > /tmp/svn_backup.dump

Khi thực hiện lệnh trên thì bạn sẽ thấy các project dump ra như sau

* Dumped revision 0.

* Dumped revision 1.

* Dumped revision 2.

* Dumped revision 3.

…………………..

Bạn có thể dùng một editor nào đó để xem thông tin trong file .dump. Hoặc bạn có thể copy file này vào usb,CD,DVD để lưu giữ.

Sau này nếu bạn muốn restore file .dump đã backup thì bạn làm như sau :

  • Đầu tiên bạn tạo một repository
  • Sau đó dùng command svnadmin load

Cụ thể như sau :

Open command line window

svnadmin load [path of your repository] < [path of .dump file]

Ví dụ :

svnadmin dump /usr/svn_new_repos < /tmp/svn_backup.dump

Vậy là bạn thực hiện xong các bước backup và restore.

Ngoài ra, nếu bạn không muốn thực hiện các lệnh này mỗi khi backup, thì bạn có thể viết một đoạn script (.sh or .bat) hoặc PHP script đơn giản để thực hiện việc backup repository.

The end