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.
Reply
 
Thread Tools Display Modes
  #1  
Old 13th July 2012, 18:25
rafael-ec rafael-ec is offline
Member
 
Join Date: Jul 2007
Posts: 57
Thanks: 15
Thanked 7 Times in 5 Posts
Default Script to sync CMS between remote locations

Hi,

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?

Code:
#!/bin/bash

#### Configuration web servers###

#Remote Web server
servidorWebDest=10.20.20.20

#local directorio. Be sure to include "/" at the ende
dirWebLocal='/var/www/html/'

#remote directory to sync
dirWebRemoto='/var/www/html/'

#exclude files from sync
exluidos='configuration.php'

#remote user
usuarioSshWeb='root'

#### Data Base###
#Remote database server
servidorRemotoBd=10.20.20.50

#Ssh user for the remote database
usuarioSshBd='root'

#local database directory. Put "/" at the end
dirBdLocal='/var/lib/mysql/dataName'

#remote database directory
dirBdRemota='/var/lib/mysql/dataName'

#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 (24th July 2012), falko (25th July 2012)
Sponsored Links
  #2  
Old 24th July 2012, 23: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
Default

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

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.

Quote:
#!/bin/bash
# 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"
/usr/bin/mysqldump -u $USERNAME -p$PASSWORD $DATABASE > $BACKUPFOLDER/$FILENAME
echo "tarring backup"
cd $BACKUPFOLDER
tar -zcf $TARFILE $FILENAME
echo "removing old backup"
rm $FILENAME
Reply With Quote
Reply

Bookmarks

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 15:08
[Info] Remote Desktop Solutions for Linux mar.and65 Desktop Operation 0 27th April 2011 07:05
Cannot login to phpmyadmin penkku HOWTO-Related Questions 1 24th February 2011 09:26
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54


All times are GMT +2. The time now is 02:05.


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