mysql , mongodb备份

di026470 3年前

来自: http://my.oschina.net/MaTech/blog/614980


一,准备:

    automysqlbackup 下载: https://sourceforge.net/projects/automysqlbackup/

    automongobackup 下载: https://github.com/micahwedemeyer/automongobackup

    automongobackup是模仿automysqlbackup项目写的,默认并不带配置文件,可以直接修改脚本里对应变量。

 

二,automysqlbackup 配置:

        CONFIG_mysql_dump_username='user'          CONFIG_mysql_dump_password='passwd'          CONFIG_mysql_dump_host='localhost'          CONFIG_backup_dir='/backup/mysql'          CONFIG_multicore='yes'          CONFIG_multicore_threads=2          CONFIG_do_monthly="0"          CONFIG_do_weekly="0"          CONFIG_rotation_daily=6          CONFIG_mysql_dump_port=3306          CONFIG_mysql_dump_single_transaction='yes'          CONFIG_mysql_dump_compression='gzip'

 

automongobackup 配置:

DBHOST="127.0.0.1"  DBPORT="27017"  BACKUPDIR="/backup/mongodb"  DBUSERNAME="user"  DBPASSWORD="passwd"  DBAUTHDB="admin"  MAILCONTENT="stdout"  MAXATTSIZE="4000"  DODAILY="yes"  DAILYRETENTION=6  DOWEEKLY="no"  WEEKLYDAY=0  WEEKLYRETENTION=0  DOMONTHLY="no"  MONTHLYRETENTION=0  COMP="gzip"  CLEANUP="yes"  LATEST="yes"  LATESTLINK="yes"  OPLOG="no"  REPLICAONSLAVE="yes"  REQUIREDBAUTHDB="yes"

两个配置都指定备份文件保存一星期

 

三,执行:

/usr/local/bin/automysqlbackup /etc/automysqlbackup/myserver.conf

automongobackup

 

四,数据导入

mongodb:

mongorestore -h 127.0.0.1 -d dbname dbbakdir/

mysql:

mysql -uusername -ppassword < bak.sql