Task
Often we have to deal with long-term projects that require development on a test server under Linux, and after checking by the client, updating the code on its server. Of course, it makes sense to use a version control system (we use SVN), and when there is access to the client server via SSH, it suffices to do the command svn update or svn checkout, for example.
Problem
However, when the client server has only FTP access, you have to upload updates manually using one of the alternatives:
- copy all project files via FTP in order not to miss anything
- make a list of files that have been changed since the previous release, and upload only them.
Decision
I want to share a solution that allows you to automate this process, and update the project on the client server by simply running the script on your dev server. To do this, it is proposed to write a simple Shell script that will do the following:
1) Export project code from version control system
2) Update the project code on the client server
')
The solution to the first problem is extremely simple:
#
rm -r /home/project/release_folder/
#
svn export --force http//svn.yourserver.com/repositary_name /home/project/release_folder/
In this case, of course, depending on the version control system used, parameters can be set, for example, to post a specific revision to the release.
To solve the second problem, you can use the lftp command, which has a large set of parameters and allows extensive file manipulations using the ftp protocol:
# sync folder with release with folder on remote client server
lftp -f sync_script.x
Contents of the sync_script.x file:
open login:password@customerserver.com
mirror -c -e -R -X '*.config.php' --no-perms /home/project/release_folder htdocs/sub
exit
As you can see, this command allows you to create an exact mirror of the folder with the release on a remote client server. In this case, we can, for example, using its parameters, prohibit updating certain files, or changing the permissions of files on a remote server.
Having made such a script on your server, it is enough to start it, and wait a couple of seconds until it updates the release folder and synchronizes its contents with the client server via FTP. It saves great time and nerves + eliminates the “human factor”. By expanding this script, you can update the project on at least a hundred servers in just a couple of minutes.