Quick project updates on client servers via FTP
Task
Often you have to deal with long-term projects that require development on a test server for Linux, and after checking by the client - updating the code on his 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 is enough to do for example the svn update or svn checkout command.
Problem
However, when access to the client server is only via FTP - you have to upload updates manually using one of the alternatives:
- copy all the project files via FTP so as not to miss anything
- make a list of files that have 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 the project code from the version control system
2) Update the project code on the client server
The solution to the first task is extremely simple: In this case, of course, depending on the version control system used, you can set parameters, for example, to post a specific revision to a release. To solve the second problem, you can use the lftp command, which has a large set of parameters and allows you to perform extensive file manipulations using the ftp protocol:
#удаление папки содержащей старый релиз
rm -r /home/project/release_folder/
#експорт кода проекта в папку релиза
svn export --force http//svn.yourserver.com/repositary_name /home/project/release_folder/
# synchronization of the folder with the release with the folder on the remote client server The
lftp -f sync_script.x
contents of the sync_script.x file: As you can see, this command allows you to create an exact mirror of the release folder on the remote client server. At the same time, we can, for example, using its parameters, prohibit updating certain files, or changing access rights to files on a remote server. Having made such a script on your server, just 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 a lot of time and nerves + excludes the “human factor”. By expanding this script, you can update the project on at least a hundred servers, in just a couple of minutes.
open login:password@customerserver.com
mirror -c -e -R -X '*.config.php' --no-perms /home/project/release_folder htdocs/sub
exit