备份机制:

Wiki后台mysql数据是使用多实例安装配置的,主要是优点是能够按照多个业务做多个实例库,合理利用系统资源、增强业务扩展。

分库备份:(此备份方法较适合单数据库,在单个库出现问题是只恢复问题库。)

WIKI、Mysql数据备份_第1张图片

命令如下:

mysqldump-u$user -p$password --skip-lock-tables --default-character-set=utf8 -B$DBname>$DBfile


定时任务:(mysql服务器操作)

WIKI、Mysql数据备份_第2张图片

#添加定时任务,让系统自动对数据库进行定时备份。(直接crontab –e 复制粘贴进去即可)

0 0 * * */bin/sh /data/DBscripts/confluence-dump.sh>/data/DBback/confluence/mysqldb.log 2>&1

15 0 * * */bin/sh /data/DBscripts/jira-dump.sh>/data/DBback/confluence/mysqldb.log 2>&1

30 0 * * */bin/sh /data/DBscripts/crowd-dump.sh>/data/DBback/confluence/mysqldb.log 2>&1

0 01 * * */bin/sh /data/DBscripts/backup.sh>>/data/rsync.log


开机启动项:(mysql服务器操作)

WIKI、Mysql数据备份_第3张图片

#将启动命令添加到开启自启动内。(mysql安装详见《wiki系统安装配置文档》)

/data/3306/mysql start


Mysql数据库配置文件my.cnf mysql服务器操作)


[client]

port = 3306

socket = /data/3306/mysql.sock


[mysql]

no-auto-rehash


[mysqld]

default-storage-engine=MYISAM

default_table_type=MYISAM

user = mysql

port = 3306

socket = /data/3306/mysql.sock

basedir = /usr/local/mysql

datadir = /data/3306/data

default-character-set=utf8

symbolic-links=0

open_files_limit = 1024

back_log = 600

max_connections = 800

max_connect_errors = 3000

table_cache = 614

external-locking = FALSE

max_allowed_packet =250M

sort_buffer_size = 1M

join_buffer_size = 1M

thread_cache_size = 100

thread_concurrency = 2

query_cache_size = 2M

query_cache_limit = 1M

query_cache_min_res_unit = 2k

#default_table_type = InnoDB

thread_stack = 192K

#transaction_isolation = READ-COMMITTED

tmp_table_size = 2M

max_heap_table_size = 2M

long_query_time = 1

log_long_format

log-error = /data/3306/error.log

log-slow-queries = /data/3306/slow.log

pid-file = /data/3306/mysql.pid

log-bin = /data/3306/mysql-bin

relay-log = /data/3306/relay-bin

relay-log-info-file =/data/3306/relay-log.info

binlog_cache_size = 1M

binlog_format=row

max_binlog_cache_size = 1M

max_binlog_size = 2M

expire_logs_days = 7

key_buffer_size = 16M

read_buffer_size = 1M

read_rnd_buffer_size = 1M

bulk_insert_buffer_size = 1M

myisam_sort_buffer_size = 1M

myisam_max_sort_file_size = 10G

myisam_max_extra_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover


lower_case_table_names = 1

skip-name-resolve

slave-skip-errors = 1032,1062

replicate-ignore-db=mysql


server-id = 1


#innodb_additional_mem_pool_size = 4M

#innodb_buffer_pool_size = 32M

#innodb_data_file_path =ibdata1:128M:autoextend

#innodb_file_io_threads = 4

#innodb_thread_concurrency = 8

#innodb_flush_log_at_trx_commit = 2

#innodb_log_buffer_size = 2M

#innodb_log_file_size = 4M

#innodb_log_files_in_group = 3

#innodb_max_dirty_pages_pct = 90

#innodb_lock_wait_timeout = 120

#innodb_file_per_table = 0

[mysqldump]

quick

max_allowed_packet = 160M


[mysqld_safe]

log-error=/data/3306/mysql_oldboy3306.err

pid-file=/data/3306/mysqld.pid


单库备份:(mysql服务器操作)

mysql备份脚本:(该脚本可用在jiraconfluencecorwd3个库,按照下面提示只要将DBName=“数据库名”即可)。

#!/bin/bash

##The script is for admin!

##backup mysql database

DBName=confluence (根据数据库名字可以写多个库的脚本)

DBUser=root

DBPath=/data/DBback/confluence

DBLog=/data/DBback/confluence/mysqldb.log

DBSock=/data/3306/mysql.sock

DBMax="--max_allowed_packet=512M"

DBSkip="--skip-lock-tables--default-character-set=utf8"

echo"-------------------------------------------" >> $DBLog

echo $(date +"%y-%m-%d %H:%M:%S")>> $DBLog

echo"---------------------------------------" >> $DBLog

/usr/local/mysql/bin/mysqldump $DBMax -u$DBUser -S $DBSock $DBName $DBSkip -B >$DBPath/confluence_$(date +%F).sql

cd $DBPath

tar zcf confluence_$(date +%F).tar.gz confluence_$(date +%F).sql >/dev/null2>&1

rm -f confluence_$(date +%F).sql\

&& echo "mysqldump confluenceis succeed ">>$DBLog \

|| echo "mysqldump cpmfluence isfail">>$DBLog

#del old files

echo "***************************************">>$DBLog

echo "delete confluence old datafiles" >>$DBLog

echo"*******************************************">>$DBLog

find $DBPath -name "*.tar.gz"-mtime +15 |xargs rm -f \

&& echo "delete 7 days ago oldfile succeed">>$DBLog \

|| echo "delete 7 days ago old filefail" >>$DBLog




Rsync服务拓扑图:

WIKI、Mysql数据备份_第4张图片

Rsync脚本:(此为数据传输服务,该配置里是将备份到本地的数据。Mysql服务器操作)

[root@wikiDB ~]# cat/data/DBscripts/backup.sh

BKlog=/data/rsync.log

cd /data/

echo "thersync-backup at `date +%F`" >>$BKlog

/usr/bin/rsync -avzDBback [email protected]::backup/ --password-file=/etc/rsync.password>>$BKlog

/usr/bin/rsync -avzDBscripts [email protected]::backup/--password-file=/etc/rsync.password >>$BKlog

/usr/bin/rsync -avz/etc/rc.d/rc.local [email protected]::backup/--password-file=/etc/rsync.password >>$BKlog

/usr/bin/rsync -avz/var/spool/cron/root [email protected]::backup/--password-file=/etc/rsync.password >>$BKlog

/usr/bin/rsync -avz/data/3306 [email protected]::backup/ --password-file=/etc/rsync.password>>$BKlog

echo "backupok........!" >>$BKlog

exit 1

定时备份WIKI前端的数据:(WIKI前端操作)

[root@wikiscripts]# crontab -l

*/5 * * * */usr/sbin/ntpdate time.windows.com >/dev/null 2>&1

00 0 * * * /bin/sh/data/backup/scripts/jiradata.sh >/dev/null2>&1

15 0 * * * /bin/sh/data/backup/scripts/wikidata.sh >/dev/null 2>&1

30 0 * * * /bin/sh/data/backup/scripts/del-oldfile.sh >/dev/null 2>&1

总结:将所有备份文件推送到10.168.0.182上,定时保留该服务器的镜像。同时在mysql数据库上启用samba服务,定时拉取备份文件。