Script to sync CMS between remote locations

Discussion in 'Server Operation' started by rafael-ec, Jul 13, 2012.

  1. rafael-ec

    rafael-ec New Member


    I wrote this simple script to sync sites between remote locations. I have tested with joomla and it works good, but I think it needs to be improved.

    The script works good with the root user using login with authentication keys.

    My concerns are related to the database. I am using rsync for mysql sync, it has work find, but something tells me it is not the best idea. Specially if the origin is writing at the moment of sync. Ideas to improve this script?

    #### Configuration web servers###
    #Remote Web server
    #local directorio. Be sure to include "/" at the ende
    #remote directory to sync
    #exclude files from sync
    #remote user
    #### Data Base###
    #Remote database server
    #Ssh user for the remote database
    #local database directory. Put "/" at the end
    #remote database directory
    #Sync web server
    rsync -azpP --exclude $exluidos $dirWebLocal $usuarioSshWeb@$servidorWebDest:$dirWebRemoto
    echo "Stop remote database"
    ssh $usuarioSshBd@$servidorRemotoBd service mysqld stop
    #Sync Database
    rsync -azpP  $dirBdLocal $usuarioSshBd@$servidorRemotoBd:$dirBdRemota
    #Start database
    echo "Start remote database"
    ssh $usuarioSshBd@$servidorRemotoBd service mysqld start                                               
  2. bozeak

    bozeak New Member

    I didn't try this script, but I think i'll have to!)
    Big thanks!!!
  3. amergrgic

    amergrgic New Member HowtoForge Supporter

    hi rafael,

    instead of using rsync to export and import the database you should use mysqldump, below is a quick example of a bash script i've made. What you could do is use rsync to copy the tar file to the new server, extract it there and then use mysql -p <database name> < <name of sql file>.sql.


Share This Page