Thursday, July 9, 2009

SVN to FTP/web on Windows with svn client+winscp

Post moved to the new blog: Svn to ftp

How to deploy a web application and to quickly deploy future updates/patches from a SVN repository into a remote web server (only with ftp access and without possibility to setup svn client) ?
Here are my suggested steps:
  1. export SVN (that is obtain the last repository without ".svn" directories)
  2. process the exported SVN (e.g. adding or deleting files before uploading)
  3. upload (1st time) or synchronize (update new files to the remote webserver)
  4. chmod folders (only 1st time or new folders)
All the 4 steps are executable from a handy shell script using:
Example of a svn to ftp batch in Windows (with subversion client and winscp, both are free):
  1. Create a profile with winscp, and set local folder "c:\temp\site1" and remote folder (e.g. "/httpdocs" ).
  2. Write a batch file svn2ftpsite1.bat
    set PATHFOLDER=c:\temp\site1
    svn export svn://1.2.3.4/trunk %PATHFOLDER% --force
    del %PATHFOLDER%\file-not-to-upload\* /q
    copy c:\other-folder\file-to-add-to-site1 %PATHFOLDER%
    c:\path-to\winscp.exe /console "open winscp-profile" "synchronize remote" "chmod 777 uploads" "close"
  3. Save. And launch when you want to update the remote site (don't forget to commit the svn before)
Read the winscp online scripting manual for further information.
Note: if the web server (Linux I think!) can access the SVN repository, has SSH server and subversion client, you can export directly the repository in the web server.
Note: if the web application works correctly, take note of the current repository version. in case of future problems you will be able to export that revision (svn client command line option) and restore the online web site.
Note: If you can install svn client in the web server and the repository is visible from the web server, you can use "check out" and "update" directly in the webserver, then use an apache rule to hide .svn directories
RewriteRule /\.svn /errorpage

1 comment:

  1. Thanks for this excellent tip. There's a better and recommended way for scripting Winscp (the Winscp command line in your script was failing on my Vista prompt). That is, instead of writing all of it on one line, for example:

    c:\path-to\winscp.exe /console "open winscp-profile" "synchronize remote" "chmod 777 uploads" "close"

    Write a winscp specific batch file:

    option batch on
    option confirm off
    open winscp-profile
    synchronize remote
    chmod 777 uploads
    close
    exit

    Save it as any_name.txt, and then pass it as an argument to win-scp.exe in the .bat file:

    c:\path-to\winscp.exe /console /script=any_name.txt

    http://winscp.net/eng/docs/scripting#example

    Thanks for your excellent post though, as it helped me learn this new automation mechanism that I can perform right from my Windows! :D

    ReplyDelete

 

PHP and tips|PHP