mysql数据库备份并且实现远程复制
一.实现ssh 远程登陆
机器环境:
192.167.33.108 clent 用户:crawler
192.167.33.77 server 用户:crawler
1.客户端 生成密钥
/home/crawler/.ssh/ssh-keygen
2. 查看密钥文件权限
ls -ld ~/.ssh; ls -l ~/.ssh
3.修改文件权限
chmod 700 /home/crawler/.ssh
chmod 600 /home/crawler/.ssh/id_rsa
4.复制公钥到服务器端
scp -r /home/crawler/.ssh/id_rsa.pub [email protected]:/home/crawler/.ssh
5.服务器端设置公钥
ls -ld /home/crawler/.ssh 查看文件权限
chmod 700 /home/crawler/.ssh 需要是drwx
ls -l /home/crawler/.ssh/*pub 查看是否有公钥
cat /home/crawler/.ssh/id_rsa.pub >> /home/crawler/.ssh/authorized_keys //生成公钥最好用这种方式避免替换掉之前的公钥
chmod 644 /home/crawler/.ssh/authorized_keys //修改权限
ls -l /home/crawler/.ssh // 查看权限
6.ssh [email protected] 登陆成功
二、备份mysql数据库
1.备份脚本(每天凌晨3点30开始备份,只保留7天的备份数据)
30 03 * * * sh /home/crawler/mysql_back_up/script/mysql-backup.sh gquan_miss8
rq=` date +%Y%m%d `
echo backuping $1
mysqldump -uroot -p111111 --default-character-set=utf8 --opt --triggers -R --hex-blob --single-transaction $1 | gzip > /home/crawler/mysql_back_up/daily/$1-all-$rq.sql.gz
find /home/crawler/mysql_back_up/daily -mtime +7 -name "*.sql.gz" -exec rm -rf {} \;
echo finished backup $1
2.rsync实现远程备份数据增量同步(每天凌晨5点10分执行)
10 05 * * * sh /home/crawler/mysql_back_up/script/back_mysql_77.sh >> /home/crawler/mysql_back_up/script/back.log
#!/bin/sh
echo "------------------------start--------------"`date`
rsync -au --delete /home/crawler/mysql_back_up/daily/ [email protected]:/home/crawler/back_96_data
echo "------------------------over--------------"`date
3.测试查看服务器上面有client文件说明正确
server图片
client 图片
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。