Cacti node Database automatic synchronization Script

Source: Internet
Author: User
Tags node server ssh port

Because of the company's CA platform, each time the addition or modification of data needs to operate on several CAs, and because the company has an automatic export script deployed on each CA, if you manually add or modify data to each CA server will cause the graphics ID inconsistent, resulting in automatic export graphics inconsistencies and other issues. So make a second script. Deployed on the primary ca. and add crontab Scheduled tasks. All node databases are automatically synchronized every morning, so that all node data is consistent.

First, edit the script

Touch/root/back.shchmod +x/root/back.shvi/root/back.sh

Second, insert the script content, the specific parameters according to the actual situation changes, nodes can be based on their own needs and additions.

#!/bin/bash   #Cacti节点数据库自动同步脚本 #by:fenei qq:407603129#2016 May 12 # Reprint Please specify the source #http:// babyfenei.blog.51cto.com/443861/1772494  st=$ (date +%s)   user= "root"     password= "MySQL database password"  database= "cacti"    mail= "alarm mail Inbox" #mail       backup_dir=/root/data_backup/caname=cacti.sql# backup file storage path    logfile=/root/data_backup/data_ backup.log# log file path      date= ' date +%y%m%d-%h%m ' #用日期格式作为文件名   dumpfile=$ Date.sql   archive= $DATE. sql.tar.gz   options= "-u$user -p$password $ Database --ignore-table=cacti.settings "  #排除settings表    #判断备份文件存储目录是否存在, otherwise create this directory     if [ ! -d  $BACKUP _dir ]   then       mkdir -p  $BACKUP _dir   fi       #开始备份之前 to write the backup header to the journal file    echo  "     ">>  $LOGFILE    echo --------------------"  >> $ logfile   echo  "Backup date:"  $ (date + "%y-%m-%d %h:%m:%s")  > >  $LOGFILE    echo ------------------- >>  $LOGFILE         #切换至备份目录    cd  $BACKUP _dir   mysqldump  $OPTIONS  >  $DUMPFILE # Determine if the database backup was successful    if [[ $? == 0 ]]   then       tar czvf  $ARCHIVE   $DUMPFILE  >> $ logfile 2>&1       echo  "[$ARCHIVE] backup  successful! "  >>  $LOGFILE        rm -f  $DUMPFILE            #删除原始备份文件, just keep the backup package       #  Back up the compressed package file to another machine.    else       echo  "database backup fail!"  >>  $LOGFILE     #备份失败后向管理者发送邮件提醒    mail -s  "database:$ database daily backup fail! "   $MAIL    fi   echo  "Backup process done"   #  Backup file is Cacti.sql and remotely backed up to node server  cd  $BACKUP _dirmysqldump  $OPTIONS  >  $BACKUP _dir$caname   ############## #联通CA同步 ################ #scp  -P 17121  $BACKUP _dir$caname [email  protected] Unicom ip:/tmp/ >>  $LOGFILE   2>&1if [[ $? == 0  ]]thenecho  "Scp is down" ssh -t -p 17121 [email protected] Unicom IP   "Mysql -uroot -p unicom database Password  cacti </tmp/cacti.sql" # -p 17121  as SSH port   No words can be deleted ssh -t -p 17121 [email protected] unicom ip  "rm -f /tmp/cacti.sql "echo " shell is down! " elsemail -s  "Unicom CA Database synchronization Error!"   $MAIL  fi############## #联通CA同步 ############################# #电信CA同步 ############## #scp  -P  17121  $BACKUP _dir$caname [email protected]:/tmp/ >>  $LOGFILE   2> &1if [[ $? == 0 ]]thenecho  "Scp is down" ssh -t -p  17121 [email protected] Telecom ip  "mysql -uroot -p Telecom Database Password  cacti </tmp/ Cacti.sql "ssh -t -p 17121 [email protected" Telecom ip  "Rm -f /tmp/cacti.sql" echo  "shell is down!" elsemail -s  "Telecommunications CA Database synchronization Error!"   $MAIL  fi############## #电信CA同步 ############################ #双线CA-synchronous ############ #scp   $ Backup_dir$caname [email protected] Double line ip :/tmp/ >>  $LOGFILE   2> &1if [[ $? == 0 ]]thenecho  "Scp is down" ssh -t&Nbsp; [email protected] Dual line ip   "Mysql -uroot -p dual-wire Database password  cacti </tmp/ Cacti.sql "ssh -t  [email protected" double line ip   "Rm -f /tmp/cacti.sql" Echo   "shell is down!" elsemail -s  "dual-line ca-Backup database synchronization Error!"   $MAILFI ############## #双线CA-standby sync ########### #rm  -f  $BACKUP _dir$caname# Delete backup files over 3 days   # cleaning  find  $BACKUP _dir  -type f -mtime +30 -name  "*. tar.gz " -exec rm -f {} \;

Third, backup and remote recovery needs to do SSH password-free login for all node servers, specifically refer to http://lhflinux.blog.51cto.com/1961662/526122

Iv. Editorial Ctontab

vi/etc/cron.d/backup# Insert the following content * * * * root/root/back.sh >/dev/null 2>&1# exit Edit Status, restart Crond Services service Crond Resta Rt


This article is from the "www.fenei.com" blog, make sure to keep this source http://babyfenei.blog.51cto.com/443861/1772494

Cacti node Database automatic synchronization Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.