MySQL——备份和还原

news2024/10/11 14:17:06

备份

热备

即MySQL服务在运行的时候进行的备份 

mysqldump命令

mysqldump --databases db1 db2 db3 > dump.sql
mysqldump -uroot -p'Sanchuang1234#' --all-databases >all_db.sql
mysqldump -uroot -p'Sanchuang123#' --databases TENNIS  >/backup/tennis.sql
mysqldump -uroot -p'Sanchuang123#'  TENNIS  PLAYERS  >tennis_players.sql

冷备

即关闭MySQL服务,不关闭机器时,进行的备份

cp tar scp rsync命令

异地备份

配置ssh免密码登录

写脚本

[root@wudang-mysql-2 mysql]# cat backup_db.sh 
#!/bin/bash

#得到时间
ctime=$(date +%F_%H%M%S)

#在本地新建存放目录/backup_db
mkdir  -p  /backup_db

#备份TENNIS库到/backup_db叫tennis.sql
mysqldump -uroot -pSanchuang1234#  TENNIS >/backup_db/${ctime}_tennis.sql

#备份mysql库里user表
mysqldump -uroot -pSanchuang1234#  mysql  user >/backup_db/${ctime}_mysql_user.sql

#备份服务器上新建文件夹/backup_db
ssh root@192.168.0.136  mkdir -p /backup_db
#上传当天备份的文件到备份服务器里192.168.0.136
scp /backup_db/${ctime}*.sql  root@192.168.0.136:/backup_db

#本地保留最近30天的备份文件
find  /backup_db  -mtime +30 -type f -name "*.sql" -exec rm -rf {} \;

#备份服务器上也保留最近30天的文件
#生成一个脚本文件
cat >del_30days_file.sh <<EOF
find  /backup_db  -mtime +30 -type f -name "*.sql" -exec rm -rf {} \;
EOF

#上传脚本文件到备份服务器
scp del_30days_file.sh root@192.168.0.136:/root

#远程执行脚本
ssh root@192.168.0.136 bash /root/del_30days_file.sh

备份方式

参考:https://www.cnblogs.com/zywu-king/p/10745600.html 

完全备份(全备)

mysqldump命令

优点:备份了所有内容

缺点:备份的东西比较多的话,时间比较长

增量备份

备份的好处是每次备份需要备份的数据较少,耗时较短,占用的空间较小;

坏处是数据恢复比较麻烦

差异备份

差异备份也要先进行一次完全备份,但是和增量备份不同的是,每次差异备份都备份和原始的完全备份不同的数据。也就是说,差异备份每次备份的参照物都是原始的完全备份,而不是上一次的差异备份。

案例

备份方案:
每天的下午16:50点做全备,刚好到了下午17点10分的时候,数据库被删除了,如何将数据恢复到17点10分的状态?

mysqlbinlog命令

根据位置号来恢复

备份和还原操作:
1.产生一个全新的二进制文件
root@(none) 10:33  sc-mysql>show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| sc-mysql-bin.000004 |    23054 |              |                  |                   |
+---------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

root@(none) 10:34  sc-mysql>flush logs;
Query OK, 0 rows affected (0.01 sec)

root@(none) 10:35  sc-mysql>show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| sc-mysql-bin.000005 |      154 |              |                  |                   |
+---------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)

root@(none) 10:35  sc-mysql>

2.给数据库做全备
[root@sc-mysql mysql]# mysqldump -uroot -p'Sanchuang123#' --databases sanchuang >/backup/sanchuang.sql

3.让数据发生变化,进行insert 和删除操作等
root@sanchuang 10:40  sc-mysql>insert into emp(id,name,deptid) values(3,'苏文洋',20);
Query OK, 1 row affected (0.00 sec)

root@sanchuang 10:40  sc-mysql>insert into emp(id,name,deptid) values(4,'qinjiahui',20);
Query OK, 1 row affected (0.00 sec)

root@sanchuang 10:40  sc-mysql>insert into emp(id,name,deptid) values(5,'chenran',20);
Query OK, 1 row affected (0.00 sec)

root@sanchuang 10:41  sc-mysql>show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| sc-mysql-bin.000005 |      998 |              |                  |                   |
+---------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

root@sanchuang 10:41  sc-mysql>

4.模拟出现故障,删除数据库
root@sanchuang 10:41  sc-mysql>drop database sanchuang;

5.开始取恢复数据
	第1步恢复全备
	[root@sc-mysql backup]# mysql -uroot -p'Sanchuang123#' < sanchuang.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@sc-mysql backup]#

	第2步:查看二进制日志找到删除数据库之前的position 位置号
[root@sc-mysql mysql]# mysqlbinlog  -v sc-mysql-bin.000005|egrep -C 5 "drop database"
#210401 10:42:39 server id 1  end_log_pos 1063 CRC32 0x8623d686 	Anonymous_GTID	last_committed=3	sequence_number=4	rbr_only=no
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 1063
#210401 10:42:39 server id 1  end_log_pos 1170 CRC32 0xf9eee347 	Query	thread_id=14	exec_time=0	error_code=0
SET TIMESTAMP=1617244959/*!*/;
drop database sanchuang
/*!*/;
# at 1170
#210401 10:44:13 server id 1  end_log_pos 1235 CRC32 0xa92ef3c4 	Anonymous_GTID	last_committed=4	sequence_number=5	rbr_only=no
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 1235
[root@sc-mysql mysql]#

	第3步:使用二进制日志去恢复
[root@sc-mysql mysql]# mysqlbinlog   --start-position=154 --stop-position=1063  sc-mysql-bin.000005|mysql -uroot -p'Sanchuang123#'
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@sc-mysql mysql]#

6.查看数据是否恢复
root@sanchuang 10:54  sc-mysql>select * from emp;
+----+-----------+--------+
| id | NAME      | deptid |
+----+-----------+--------+
|  1 | 张三      |     10 |
|  2 | 李四      |     10 |
|  3 | 苏文洋    |     20 |
|  4 | qinjiahui |     20 |
|  5 | chenran   |     20 |
| 19 | 吴佩      |     10 |
+----+-----------+--------+
6 rows in set (0.00 sec)

root@sanchuang 10:55  sc-mysql>

根据时间点来恢复

mysqlbinlog --start-datetime="2005-04-20 9:55:00" \
         --stop-datetime="2005-04-20 10:05:00" \
         /var/log/mysql/bin.123456 > /tmp/mysql_restore.sql

难点是找到起始点和结束点

配合grep语句,当时最后做的删除操作 

[root@zabbix-4-centos7 mysql]# mysqlbinlog -vv zabbix-4-centos7-bin.000003|grep -i -n -A 150  "create table student"

自动化脚本——计划任务

练习:
    1.编写一个脚本备份tennis库和mysql库到/backup目录下,要求备份的文件里有时间,精确到秒 
    2.每天的凌晨3点开始备份
   3.本地备份完成后,上传到专门的网络上的另外一台备份服务器里/backup/业务+机器名.tar.gz

[root@wudang-mysql-2 mysql]# cat backup_db.sh 
#!/bin/bash

#得到时间
ctime=$(date +%F_%H%M%S)

#在本地新建存放目录/backup_db
mkdir  -p  /backup_db

#备份TENNIS库到/backup_db叫tennis.sql
mysqldump -uroot -pSanchuang1234#  TENNIS >/backup_db/${ctime}_tennis.sql

#备份mysql库里user表
mysqldump -uroot -pSanchuang1234#  mysql  user >/backup_db/${ctime}_mysql_user.sql

#备份服务器上新建文件夹/backup_db
ssh root@192.168.0.136  mkdir -p /backup_db
#上传当天备份的文件到备份服务器里192.168.0.136
scp /backup_db/${ctime}*.sql  root@192.168.0.136:/backup_db

#本地保留最近30天的备份文件
find  /backup_db  -mtime +30 -type f -name "*.sql" -exec rm -rf {} \;

#备份服务器上也保留最近30天的文件
#生成一个脚本文件
cat >del_30days_file.sh <<EOF
find  /backup_db  -mtime +30 -type f -name "*.sql" -exec rm -rf {} \;
EOF

#上传脚本文件到备份服务器
scp del_30days_file.sh root@192.168.0.136:/root

#远程执行脚本
ssh root@192.168.0.136 bash /root/del_30days_file.sh

物理备份和逻辑备份

物理备份由存储数据库内容的目录和文件的原始副本组成。这种类型的备份适用于需要在出现问题时快速恢复的大型、重要的数据库。

逻辑备份保存以逻辑数据库结构(CREATE DATABASE、 CREATE TABLE语句)和内容(INSERT语句或分隔文本文件)表示的信息。这种类型的备份适用于较小的数据量,您可以在其中编辑数据值或表结构,或者在不同的机器架构上重新创建数据。

物理备份: 直接是数据 --》鱼
逻辑备份: 备份是表结构和产生数据的过程(create,insert)  --》工艺(方法)和流程--》可以产生想要的数据 --》渔

物理的: 硬件的
    磁盘对拷:
    
逻辑的: 软件的

远程备份rsync

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。已支持跨平台,可以在Windows与Linux间进行数据同步。

参考:https://blog.csdn.net/qq_36045024/article/details/105072818

实验步骤 


rsync命令的使用
scp

[root@sc-mysql backup]# ssh-keygen -t rsa
[root@sc-mysql backup]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.2.197
[root@sc-mysql backup]# ssh 'root@192.168.2.197'  mkdir /backup
[root@sc-mysql backup]# ssh 'root@192.168.2.197'  mkdir /backup/fengdeyong
[root@sc-mysql backup]# ls
all_db.sql  hunan_liangliang.sql  tennis_player.sql  ws.sql
[root@sc-mysql backup]# scp ws.sql root@192.168.2.197:/backup
ws.sql                                                                                     100% 2024   454.2KB/s   00:00    
[root@sc-mysql backup]# 

每天的晚上2点30分钟备份所有的数据库,然后scp到备份服务器上

[root@sc-mysql backup]# cat backup_db.sh 
#!/bin/bash

#导出数据
mysqldump  -uroot -p'Sanchuang1234#' --databases wangshuai >/backup/$(date +%F)_wangshuai.sql

#scp到远程的备份服务器
scp /backup/$(date +%F)_wangshuai.sql  root@192.168.2.197:/backup


[root@sc-mysql backup]# bash backup_db.sh 
mysqldump: [Warning] Using a password on the command line interface can be insecure.
2022-08-18_wangshuai.sql                                                                   100% 2077   660.9KB/s   00:00    
[root@sc-mysql backup]# 
[root@sc-mysql backup]# crontab -e
[root@sc-mysql backup]# crontab -l
30 2 * * *  bash /backup/bacup_db.sh

[root@sc-mysql backup]# 
======================

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。
已支持跨平台,可以在Windows与Linux间进行数据同步。


raid
	1 5 6 10
	镜像卷: raid1
	2块,可以坏一块,两块磁盘里存放相同的数据

	mirror 镜像,镜子

rsync 全称 remote synchronize,即 远程同步。
使用 rsync 进行数据同步时,第一次进行完全备份,以后则是增量备份,利用 rsync 算法(差分编码),只传输差异部分数据。

====

rsync+sersync文件实时同步
	原文链接:https://blog.csdn.net/qq_36045024/article/details/105072818
一:什么是Rsync?
  Rsync(Remote Synchronize)是一款开源的、快速的、多功能的、可以实现全量及增量的本地或远程数据同步备份的优秀工具,并且支持多种操作系统平台运行。
二:什么Sersync?
	1、sersync是基于inotify开发的,类似于inotify-tools的工具,Sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或者某一个目录的名字,然后使用rsync同步的时候,只同步发生变化的文件或者目录,因此效率更高。

	2、主要应用场景为数据体积大,并且文件很多。

	小结:Rsync+sersync
	1、sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字;
	2、rsync在同步的时候,只同步发生变化的这个文件或者这个目录(每次发生变化的数据相对整个同步目录数据来说是很小的,rsync在遍历查找比对文件时,速度很快),因此,效率很高。

三:环境
	备份服务器:192.168.2.197  操作系统:Centos7.9  
	数据源服务器:192.168.2.196 操作系统:Centos7.9
	[root@sc-mysql2 backup]# cat /etc/centos-release
	CentOS Linux release 7.9.2009 (Core)
	[root@sc-mysql2 backup]#

四:备份服务器操作
	1、关闭 selinux #永久关闭linux防火墙

	[root@sc-mysql2 backup]# getenforce 
	Permissive
	[root@sc-mysql2 backup]# vim /etc/selinux/config 
	SELINUX=disabled

	2、关闭防火墙
	[root@sc-mysql2 backup]# service firewalld stop
	Redirecting to /bin/systemctl stop firewalld.service
	3、安装rsync服务端软件
	[root@sc-mysql2 backup]# yum install rsync xinetd -y
	[root@sc-mysql2 backup]# vi /etc/rc.d/rc.local        # #设置开机启动
	/usr/bin/rsync --daemon --config=/etc/rsyncd.conf # 添加开机启动

	[root@sc-mysql2 backup]# chmod +x /etc/rc.d/rc.local 

	[root@sc-mysql2 backup]# systemctl start xinetd     #启动xinetd

	xinetd是一个提供保姆服务的进程,rsync是它照顾的进程
	独立的服务:ssh,dhcp,mysql
	非独立的服务,非独立的服务需要依赖其他的服务来管理,rsync就是一个非独立的服务,依赖xinetd来管理

4、创建rsyncd.conf配置文件
[root@sc-mysql2 backup]# vim /etc/rsyncd.conf  添加下面的配置
uid = root
gid = root
use chroot = yes
max connections = 0
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
secrets file = /etc/rsync.pass
motd file = /etc/rsyncd.Motd
[back_data]  #配置项名称(自定义)
     path = /backup  #备份文件存储地址
     comment = A directory in which data is stored
     ignore errors = yes
     read only = no
     hosts allow = 192.168.2.196     #允许的ip地址(数据源服务器地址)
5、创建用户认证文件
$ vi /etc/rsync.pass    # 配置文件,添加以下内容,添加允许传输用户和密码
    sunline:sunline   # 格式,用户名:密码,可以设置多个,每行一个用户名:密码
	sc:sc123456
6、设置文件权限
$ chmod 600 /etc/rsyncd.conf  #设置文件所有者读取、写入权限
$ chmod 600 /etc/rsync.pass  #设置文件所有者读取、写入权限
7、启动rsync和xinetd
[root@sc-mysql2 backup]# /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
[root@sc-mysql2 backup]# ps aux|grep rsync
root      9455  0.0  0.0 114844   584 ?        Ss   16:13   0:00 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
root      9457  0.0  0.0 112824   988 pts/0    S+   16:13   0:00 grep --color=auto rsync
[root@sc-mysql2 backup]#
[root@sc-mysql2 backup]# systemctl start xinetd
[root@sc-mysql2 backup]# ps aux|grep xinetd
root      9425  0.0  0.0  25044   584 ?        Ss   16:00   0:00 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
root      9465  0.0  0.0 112824   988 pts/0    S+   16:14   0:00 grep --color=auto xinetd
[root@sc-mysql2 backup]# 
8.查看rsync监听的端口号
[root@sc-mysql2 backup]# netstat -anplut
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      9455/rsync          
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1040/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1256/master         
tcp        0     36 192.168.2.197:22        192.168.2.105:58059     ESTABLISHED 3556/sshd: root@pts 
tcp6       0      0 :::873                  :::*                    LISTEN      9455/rsync          
tcp6       0      0 :::3306                 :::*                    LISTEN      2597/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      1040/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1256/master         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           675/chronyd         
udp6       0      0 ::1:323                 :::*                                675/chronyd         
[root@sc-mysql2 backup]# 

=================
五:数据源服务器操作
(1)安装rsync客户端软件
	1、关闭 selinux #永久关闭linux防火墙

	[root@sc-mysql2 backup]# getenforce 
	Permissive
	[root@sc-mysql2 backup]# vim /etc/selinux/config 
	SELINUX=disabled

	2、关闭防火墙
	[root@sc-mysql2 backup]# service firewalld stop
	Redirecting to /bin/systemctl stop firewalld.service
	3、安装rsync服务端软件
	[root@sc-mysql2 backup]# yum install rsync xinetd -y
	[root@sc-mysql2 backup]# vi /etc/rc.d/rc.local        # #设置开机启动
	/usr/bin/rsync --daemon --config=/etc/rsyncd.conf # 添加开机启动

	[root@sc-mysql2 backup]# chmod +x /etc/rc.d/rc.local 

	[root@sc-mysql2 backup]# systemctl start xinetd     #启动xinetd
[root@sc-mysql backup]# vim /etc/rsyncd.conf 
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
motd file = /etc/rsyncd.Motd
[Sync]
    comment = Sync
    uid = root
    gid = root
    port= 873
$ systemctl start xinetd  #启动(CentOS中是以xinetd来管理rsync服务的)

4、创建认证密码文件
[root@sc-mysql backup]# vim /etc/passwd.txt
sc123456   #编辑文件,添加以下内容,该密码应与目标服务器中的/etc/rsync.pass中的密码一致  
[root@sc-mysql backup]#
[root@sc-mysql backup]# chmod 600 /etc/passwd.txt   #设置文件权限,只设置文件所有者具有读取、写入权限即可
[root@sc-mysql backup]# 
5、测试数据同步
数据源服务器192.168.2.196 到备份服务器192.168.2.197之间的数据同步
$ rsync -avH --port=873 --progress --delete  /var/www/data(要备份的数据源目录 ) root@***.***.***.222::back_data(rsyncd.conf文件配置名称)  --password-file=/etc/passwd.txt


$ rsync -avH --port=873 --progress --delete  /backup  root@192.168.2.197::back_data --password-file=/etc/passwd.txt

rsync --help


[root@sc-mysql backup]# rsync -avH --port=873 --progress --delete  /backup  root@192.168.2.197::back_data --password-file=/etc/passwd.txt

sending incremental file list
backup/
backup/2022-08-18_wangshuai.sql
          2,077 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=5/7)
backup/all_db.sql
        936,290 100%   34.34MB/s    0:00:00 (xfr#2, to-chk=4/7)
backup/backup_db.sh
            222 100%    8.34kB/s    0:00:00 (xfr#3, to-chk=3/7)
backup/hunan_liangliang.sql
         19,833 100%  717.34kB/s    0:00:00 (xfr#4, to-chk=2/7)
backup/tennis_player.sql
          3,106 100%  112.34kB/s    0:00:00 (xfr#5, to-chk=1/7)
backup/ws.sql
          2,024 100%   73.21kB/s    0:00:00 (xfr#6, to-chk=0/7)

sent 964,284 bytes  received 134 bytes  1,928,836.00 bytes/sec
total size is 963,552  speedup is 1.00
[root@sc-mysql backup]# 

增加文件,或者删除文件,测试是否可以增量备份
[root@sc-mysql backup]# ls
2022-08-18_wangshuai.sql  all_db.sql  backup_db.sh  hunan_liangliang.sql  passwd  tennis_player.sql  ws.sql
[root@sc-mysql backup]# rm -rf passwd 
[root@sc-mysql backup]# cp /etc/hosts .
[root@sc-mysql backup]# ls
2022-08-18_wangshuai.sql  all_db.sql  backup_db.sh  hosts  hunan_liangliang.sql  tennis_player.sql  ws.sql
[root@sc-mysql backup]# rsync -avH --port=873 --progress --delete  /backup  root@192.168.2.197::back_data --password-file=/etc/passwd.txt

sending incremental file list
deleting backup/passwd
backup/
backup/hosts
            158 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=3/8)

sent 472 bytes  received 56 bytes  1,056.00 bytes/sec
total size is 963,710  speedup is 1,825.21

目前为止,只是实现了手工的去同步数据

还没有实现自动的实时的同步
===
(2)安装sersync工具,实时触发rsync进行同步 --》安装到数据源服务器上
备注:Linux下支持inotify的内核最小为2.6.13,可以输入命令:#uname -a查看内核
CentOS 7.0内核为3.10.0,默认已经支持inotify

inotify已经默认在内核里安装了,不需要安装

1、修改inotify默认参数(inotify默认内核参数值太小) 修改参数:
[root@sc-mysql backup]# sysctl -w fs.inotify.max_queued_events="99999999"
fs.inotify.max_queued_events = 99999999
[root@sc-mysql backup]# sysctl -w fs.inotify.max_user_watches="99999999"
fs.inotify.max_user_watches = 99999999
[root@sc-mysql backup]# sysctl -w fs.inotify.max_user_instances="65535"
fs.inotify.max_user_instances = 65535
[root@sc-mysql backup]# 
永久修改参数
[root@sc-mysql backup]# vim /etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535

2、安装sersync
[root@sc-mysql backup]# yum install wget -y
[root@sc-mysql backup]# wget  http://down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@sc-mysql backup]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz 
[root@sc-mysql backup]# mv GNU-Linux-x86/ /usr/local/sersync
3、创建rsync
[root@sc-mysql backup]# cd /usr/local/sersync/
[root@sc-mysql sersync]# ls
confxml.xml  sersync2
[root@sc-mysql sersync]# 
备份配置文件,防止修改错了,不知道哪里出错,好还原
[root@sc-mysql sersync]# cp confxml.xml confxml.xml.bak
[root@sc-mysql sersync]# cp confxml.xml data_configxml.xml
[root@sc-mysql sersync]# ls
confxml.xml  confxml.xml.bak  data_configxml.xml  sersync2
[root@sc-mysql sersync]#
data_configxml.xml 是后面需要使用的配置文件
4、修改配置 data_configxml.xml 文件

第24行后的配置
<localpath watch="/backup">
            <remote ip="192.168.2.197" name="back_data"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>
            <auth start="false" users="root" passwordfile="/etc/passwd.txt"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="false" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
5、启动服务

[root@sc-mysql sersync]# PATH=/usr/local/sersync/:$PATH
[root@sc-mysql sersync]# which sersync2
/usr/local/sersync/sersync2
[root@sc-mysql sersync]# 

[root@sc-mysql sersync]# echo 'PATH=/usr/local/sersync/:$PATH'  >>/root/.bashrc 
[root@sc-mysql sersync]# sersync2 -d -r -o  /usr/local/sersync/data_configxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d 	run as a daemon
option: -r 	rsync all the local files to the remote servers before the sersync work
option: -o 	config xml name:  /usr/local/sersync/data_configxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost	host port: 8008
daemon start,sersync run behind the console 
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /backup && rsync -artuz -R --delete ./ 192.168.2.197::back_data >/dev/null 2>&1 
run the sersync: 
watch path is: /backup
[root@sc-mysql sersync]#
[root@sc-mysql backup]# ps aux|grep sersync
root     25655  0.0  0.0  92324   704 ?        Ssl  17:47   0:00 sersync2 -d -r -o /usr/local/sersync/data_configxml.xml
root     25673  0.0  0.0 112824   988 pts/1    S+   17:48   0:00 grep --color=auto sersync
[root@sc-mysql backup]# 
验证:去/backup目录下新建一些文件或者文件夹,测试是否在备份服务器上可以看到


6、设置sersync监控开机自动执行
[root@sc-mysql backup]# vim /etc/rc.local 
/usr/local/sersync/sersync2 -d -r -o  /usr/local/sersync/data_configxml.xml


密码不正确或者用户名不正确,也可以实时同步文件,思考底层是否利用了我们建立的ssh免密通道?


熟悉rsync+sersync实现文件的实时同步

=====
错误的问题:
	1.配置文件没有写内容,或者打错
	2.两边的服务器没有新建目录/backup -->特别是备份服务器上没有新建/backup

[root@sc-mysql2 backup]# vim /etc/rsyncd.conf 
uid = root
gid = root
use chroot = yes
max connections = 0
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
secrets file = /etc/rsync.pass
motd file = /etc/rsyncd.Motd
[back_data]
     path = /backup2  #存放备份文件的目录
     comment = A directory in which data is stored
     ignore errors = yes
     read only = no
     hosts allow = 192.168.2.196

备份服务器里的备份目录是/backup2,但是这个文件没有创建,导致不能备份过去
在备份服务器上需要我们去创建mkdir /backup2

修改了rsyncd.conf配置文件,需要重启xinetd服务,会帮我们去重启rsync进程
[root@sc-mysql2 backup]# service xinetd restart
Redirecting to /bin/systemctl restart xinetd.service
[root@sc-mysql2 backup]# 

排错查看日志
[root@sc-mysql2 backup]# cat /var/log/rsyncd.log 
2022/08/18 16:13:19 [9455] rsyncd version 3.1.2 starting, listening on port 873
2022/08/18 16:35:08 [9472] name lookup failed for 192.168.2.196: Name or service not known
2022/08/18 16:35:08 [9472] connect from UNKNOWN (192.168.2.196)
2022/08/18 17:16:37 [9532] rsync: chroot /backup2 failed: No such file or directory (2)  错误信息
[root@sc-mysql2 backup]# 


[root@sc-mysql backup]# rsync -avH --port=873 --progress --delete  /backup  root@192.168.2.197::back_data --password-file=/etc/passwd.txt

@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1649) [sender=3.1.2]
[root@sc-mysql backup]# 

还原

[root@Sanchuang backup]# mysql -uroot -p'Sanchuang123#' <tennis.sql 

基于时间:https://dev.mysql.com/doc/refman/5.7/en/point-in-time-recovery-binlog.html

基于位置号:https://dev.mysql.com/doc/refman/5.7/en/point-in-time-recovery-positions.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/993271.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

分享一个python基于数据可视化的智慧社区服务平台源码

&#x1f495;&#x1f495;作者&#xff1a;计算机源码社 &#x1f495;&#x1f495;个人简介&#xff1a;本人七年开发经验&#xff0c;擅长Java、Python、PHP、.NET、Node.js、微信小程序、爬虫、大数据等&#xff0c;大家有这一块的问题可以一起交流&#xff01; &#x1…

【rust/egui】(九)使用painter绘制一些图形—基本使用

说在前面 rust新手&#xff0c;egui没啥找到啥教程&#xff0c;这里自己记录下学习过程环境&#xff1a;windows11 22H2rust版本&#xff1a;rustc 1.71.1egui版本&#xff1a;0.22.0eframe版本&#xff1a;0.22.0上一篇&#xff1a;这里 painter 定义pub struct Painter {///…

领域驱动设计:DDD分层架构

文章目录 DDD 分层架构DDD 分层架构最重要的原则DDD 分层架构推动架构演进三层架构如何演进到 DDD 分层架构 微服务架构模型有好多种&#xff0c;例如整洁架构、CQRS 和六边形架构等等。每种架构模式虽然提出的时代和背景不同&#xff0c;但其核心理念都是为了设计出“高内聚低…

gpt测试

已知a地一石头售价80&#xff0c;b地售价112&#xff0c;小明初始资金8000&#xff0c;在a地全仓购入后&#xff0c;去b地出售&#xff0c;然后小明又回到a地&#xff0c;再次全仓购入然后去b地出售&#xff0c;这样继续出售10次后&#xff0c;小明有多少钱&#xff1f;石头是不…

Java中wait和notify详解

线程的调度是无序的&#xff0c;随机的&#xff0c;但是也是有一定的需求场景&#xff0c;希望能够有序执行&#xff0c;join算是一种控制顺序的方式&#xff08;功能有限&#xff09;——》一个线程执行完&#xff0c;才能执行另一个线程&#xff01; 本文主要讲解的&#xf…

C++---类和对象

这里写目录标题 封装简介语法二级目录二级目录二级目录二级目录二级目录二级目录二级目录二级目录二级目录二级目录二级目录二级目录二级目录 封装 简介语法 类 &#xff1a;抽象的 共性的 对象&#xff1a;实例化的 具体的 个性的 封装 就是把属性和行为放在一起 加一些访问权…

CCRC-PIPA个人信息保护评估师

个人信息保护评估师 (Personal InformationProtec-tion Assessor&#xff0c;简称 “PIPA”) 是由中国网络安全审查技术与认证中心(简称CCRC) 推出的面向个人信息保护领域的培训认证。CCRC-PIPA课程以《个人信息保护法》、法规、部门规章、相关国家标准和行业最佳实践为基础&am…

代理IP在海外SEO优化中有哪些关键作用?

代理IP在海外SEO优化业务中的应用越来越受到企业的重视。它为企业提供了大量不同地区的IP地址&#xff0c;帮助企业模拟不同地区、不同设备的用户行为&#xff0c;有助于更准确地了解当地的搜索引擎规则和优化策略&#xff0c;更好地评估网站的排名和流量。 一、代理IP的优势 …

【Stable Diffusion XL】huggingface diffusers 官方教程解读

文章目录 01 TutorialDeconstruct a basic pipelineDeconstruct the Stable Diffusion pipelineAutopipelineTrain a diffusion model 相关链接&#xff1a; GitHub&#xff1a; https://github.com/huggingface/diffusers 官方教程&#xff1a;https://huggingface.co/docs/di…

第2章_瑞萨MCU零基础入门系列教程之面向过程与面向对象

本教程基于韦东山百问网出的 DShanMCU-RA6M5开发板 进行编写&#xff0c;需要的同学可以在这里获取&#xff1a; https://item.taobao.com/item.htm?id728461040949 配套资料获取&#xff1a;https://renesas-docs.100ask.net 瑞萨MCU零基础入门系列教程汇总&#xff1a; ht…

thinkphp6 入门(6)--中间件是什么 怎么用

一、什么是中间件&#xff1f; 当客户端发送请求至服务器时&#xff0c;HTTP请求会经过多个中间件&#xff0c;最后返回响应给客户端。中间件可以 在请求到达目标控制器或动作之前对请求进行操作 可以在响应离开目标控制器或动作之前对响应进行操作 二、中间件的作用 我们可…

【Python】conda虚拟环境下使用pyinstaller打包程序为exe

文章目录 一、为什么要用conda虚拟环境二、pyinstaller用法2.1 安装 PyInstaller2.2 基本用法打包一个 Python 脚本2.21 打包一个 Python 项目2.22 打包选项 2.3 打包依赖项2.31 导出依赖项列表2.32 配置依赖项 2.4 自定义打包选项2.5 打包完成后的文件2.6 注意事项 三、打包示…

RabbitMQ 知识点解读

1、AMQP 协议 1.1、AMQP 生产者的流转过程 当客户端与Broker 建立连接的时候&#xff0c;会调用factory .newConnection 方法&#xff0c;这个方法会进一步封装成Protocol Header 0-9-1 的报文头发送给Broker &#xff0c;以此通知Broker 本次交互采用的是AMQPO-9-1 协议&…

文件上传漏洞案例

目录 1.案例一 1&#xff09;案例源码 2&#xff09;创建web.php文件 3&#xff09;使用抓包软件 2.案例二 1&#xff09;案例代码 2&#xff09; 案例分析 3&#xff09;copy命令生成图片马 4&#xff09;上传图片马到服务器 5&#xff09;解析 文件图片 3.案例三 …

Error running ‘xxx‘: Command line is too long. Shorten command line for xxxx

完整报错信息&#xff1a;Error running ArticleFreemarkerTest.test: Command line is too long. Shorten command line for ArticleFreemarkerTest.test or also for JUnit default configuration. 翻译为运行“ArticleFreemarkerTest.test”时出错&#xff0c;命令行太长。…

计网第四章(网络层)(八)

在第七节&#xff08;计网第四章&#xff08;网络层&#xff09;&#xff08;七&#xff09;_永无魇足的博客-CSDN博客&#xff09;我们总结了路由信息协议RIP。在最后我们提到了RIP协议有坏消息传的慢的问题&#xff0c;这是距离向量算法的本质决定的&#xff0c;所以这种问题…

成都青溪电商:抖店精选联盟怎么绑定?

随着抖音平台的快速发展&#xff0c;越来越多的商家希望利用抖音的流量红利来实现品牌曝光和销量增长。抖音精选联盟作为抖音平台的重要合作计划&#xff0c;为商家提供了更多的机会和资源支持。下面将详细介绍如何绑定抖店精选联盟并讨论解绑情况。 1.绑定抖店选定联盟 满足入…

蓝桥杯官网练习题(数字三角形)

题目描述 上图给出了一个数字三角形。从三角形的顶部到底部有很多条不同的路径。对于每条路径&#xff0c;把路径上面的数加起来可以得到一个和&#xff0c;你的任务就是找到最大的和。 路径上的每一步只能从一个数走到下一层和它最近的左边的那个数或者右 边的那个数。此外&a…

AlwaysUp10.5.0.93安装和使用说明

安装包 安装 解压 双击exe 点击完成&#xff0c;完成安装 安装完成自动启动程序

基于串口的BLE模组CC2640R2使用总结

之前写过蓝牙控制芯片nRF52832的一篇概述&#xff0c;里面主要记录了蓝牙的分层结构&#xff0c;需要的话可参考&#xff1a;nRF52832蓝牙概述_路溪非溪的博客-CSDN博客 这篇文章记录的是蓝牙模组的基本使用。 二者有何区别呢&#xff1f; nRF52832是一款基于蓝牙的主控芯片…