Howtos:Synchronize automatically a package of deployment on all servers OCS distants

From OCS Inventory NG
Jump to: navigation, search

Principle of functioning

  1. Creation of a package of deployment on one of the OCS servers
  2. Saving of the information registered in database concerning the package
  3. Transfer of the file containing the package generated on remote servers A and B
  4. Transfer of the information registered in database concerning the package on remote servers A and B
  5. The Restoration of the information registered in database concerning the package on remote servers A and B

Requirements

The servers (issuers and receivers) must be configured to make of files transfer and command execution with the protocol SSH (tunnel SSH - rsync - rsh)

SQL file for updating the table download_enable

  • .sql file for updating the database of the wide site A (to place on the server that launch the script)

/home/web/maj_tdownload_wide_site_A.sql

update `download_enable` SET `INFO_LOC` = 'IP_SERVEUR_DISTANT_A/download', `PACK_LOC` = 'IP_SERVEUR_DISTANT_A/download';
  • .sql file for updating the database of the wide site B (to place on the server that launch the script))

/home/web/maj_tdownload_wide_site_B.sql

update `download_enable` SET `INFO_LOC` = 'IP_SERVEUR_DISTANT_B/download', `PACK_LOC` = 'IP_SERVEUR_DISTANT_B/download';

Synchronization script

##########################################################
#	OCS INVENTORY   - TRANSFERT DE PAQUETS    
##########################################################
# TRANSFER OF THE TABLES download_available AND download_enable OF THE 
# DATABASE ocsweb FOR MANUAL ACTIVATION OF THE PACKAGES
# Guillaume PRIOU and Frank Bourdeau
##########################################################
#Creation of the file of saving of the table download_available of the bdd ocsweb
FILE=/home/web/bddocsweb_tdownload_available.sql
mysqldump -u user -ppassword ocsweb download_available download_enable> $FILE

echo "SQL File ready for transfer to all remote sites"
##########################################################

echo "Transfer to remote site A"
#Synchronization of the download directory including all OCS packages
rsync -a /var/lib/ocsinventory-reports/download/ IP_WIDE_SERVER_A:/var/lib/ocsinventory-reports/download

#OCS database update for integrating new packages
rsh IP_REMOTE_SERVER_A mysql -u root ocsweb < /home/web/bddocsweb_tdownload_available.sql
rsh IP_REMOTE_SERVER_A mysql -u root ocsweb < /home/web/maj_tdownload_remote_site_A.sql

#The script will be execute each day at 05.30am
#It is possible to put a "guard dog" at 06:00 am to be sure
#That one of the transfers is not planted and that a process doesn't turn for nothing
hour=`date +"%H%M"`
if [ $hour -gt 0600 ]
then
	echo "Transfer remote site B"
        ##Synchronization of the download directory including all OCS packages
	rsync -a /var/lib/ocsinventory-reports/download/ IP_REMOTE_SERVER_B:/var/lib/ocsinventory-reports/download

	#OCS database update for integrating new packages
	rsh IP_REMOTE_SERVER_B mysql -u root ocsweb < /home/web/bddocsweb_tdownload_available.sql
        rsh IP_REMOTE_SERVER_B mysql -u root ocsweb < /home/web/maj_tdownload_remote_site_B.sql
fi

Files architecture

Content of /home/web directory:

Web.jpg

Automation in CRON

Add in the crontab file the following line : (You need to store the script. For example : /home/web/syncOCSpackages.sh)

#Execution all days at 5h30am for synchronization script of OCS packages
05 30 * * * root /home/web/syncOCSpackages.sh