Voir cette page en français

Oct 15 2009

syncsite.sh: shell script to synchronize files and databases from a web site through secure SSH connection


syncsite.sh is a bash shell script that allow to duplicate, backup or synchronize a remote WEB site, like CMS, through a secure connection SSH. Thank to integrated preprocessing and postprocessing variables to his external configuration system files, it can be adapted to all type of CMS.


All the connections mentioned here are secure.
  • The data base
    • syncsite connects to the remote site, request the generation of a compressed MySQL dump of the database referenced by the variable db_name, so transfers the dump on the client and, if the variable auto_install_db is true, it decompresses the file ;
    • in the case of an automatic DB, the bash shell script contained in the configuration variable pre_process_dump_shell_script is applied to the SQL dump before his execution ;
    • always in the case of an automatic DB installation, the DB is installed after a backup of the database has been made ; when the variable make_db_backup is false, this backup is destroyed once the installation was successful.
    • finally, if the variable post_process_sql_file_script is set, the SQL file which it refers is executed on the data base.
  • The files
    • remote directories referenced by the variable remote_sync_dirs are synchronized using the software rsync in the client directory referenced by the variable local_root_dir ; this allows only update files that have been changed since the last synchronization ;
    • finally, the shell script contained in the variable post_process_shell_script is executed with the parameter local_root_dir.


syncsite is configured using external files and to specify the configuration file to use one uses the option -f.
This gives eg syncsite.sh -f ~/.syncsite/my_site.sh.
If no configuration file is specified, synsite looks for the configuration file ~/.syncsite/default.sh ; if this file does not exist, a dialog interface allows to choose one ergonomically.

Configuration files are already predefined for the CMS TYPO3 and WordPress. They allow in particular to automatically retrieve the name of the database and authentication settings directly in the configuration files of the site.


The configuration file for TYPO3 can be found HERE


The configuration file for WORDPRESS can be found HERE


The project is under Git control at this address.
It depends of bash, MySQL, bizip2 and rsync.

Feel free to propose the configuration file of your favorite CMS.

Étiquettes :