Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Server Operation

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Thread Tools Display Modes
Old 13th July 2012, 19:25
rafael-ec rafael-ec is offline
Join Date: Jul 2007
Posts: 57
Thanks: 15
Thanked 7 Times in 5 Posts
Default Script to sync CMS between remote locations


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
Reply With Quote
The Following 2 Users Say Thank You to rafael-ec For This Useful Post:
bozeak (25th July 2012), falko (25th July 2012)
Sponsored Links
Old 25th July 2012, 00:25
bozeak bozeak is offline
Junior Member
Join Date: Sep 2008
Location: Chisinau, Republic of Moldova
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via ICQ to bozeak

I didn't try this script, but I think i'll have to!)
Big thanks!!!
Reply With Quote
Old 28th July 2012, 16:47
amergrgic amergrgic is offline
Junior Member
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

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.

# Makes a mysqldump for the database
# Author: Amer Grgic
# Version 1.0: Initial version

USERNAME="db username"
PASSWORD="db password"
DATABASE="db name"
BACKUPFOLDER="folder to place your backup in"
FILENAME="sql filename"
TARFILE="tar filename"

echo "creating backup"
echo "tarring backup"
echo "removing old backup"
Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
haproxy with stunnel problem abubin Server Operation 6 10th April 2012 16:08
[Info] Remote Desktop Solutions for Linux mar.and65 Desktop Operation 0 27th April 2011 08:05
Cannot login to phpmyadmin penkku HOWTO-Related Questions 1 24th February 2011 10:26
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 17:54

All times are GMT +2. The time now is 23:04.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.