初始化服务器:必须要将时间同步
数据传送:
全量备份: scp是全量备份(小而多的文件打包然后使用scp传输)
-r:递归
-p:权限
全量备份:
增量备份:
差量备份:
详情请见个人博客:https://blog.csdn.net/qq_42508901/article/details/100833961
rsync:增量备份
-a:不跳过目录
-v:显示详细内容
-z:压缩传送
–delete:相当于rm,但是必须要有一个空文件作为参照
–bwlimit=100:限制带宽
DNS域名解析:
阿里:223.5.5.5 223.6.6.6
谷歌:8.8.8.8 8.8.4.4
114.114.114.114
关闭防火墙:
[root@localhost yum.repos.d]# systemctl stop firewalld
关闭selinux防火墙:
[root@localhost yum.repos.d]# setenforce 0
[root@localhost yum.repos.d]# geten
getenforce getent
[root@localhost yum.repos.d]# getenforce
Permissive——————————————————>关闭
[root@localhost yum.repos.d]# setenforce 1
[root@localhost yum.repos.d]# getenforce
Enforcing————————————————>开启
永久关闭:在/etc/sysconfig/selinux 把enforcing改成disabled
对A—server服务端进行配置:
首先要把配置文件备份一下
[root@localhost ~]# cp -p /etc/rsyncd.conf{,.bak}
使用egrep查看配置文件内容
[root@localhost etc]# egrep -v "^#|^$" /etc/rsyncd.conf
修改配置文件:
[root@localhost etc]# vim /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root
gid = root
use chroot = no
max connections = root
pid file = /var/run/rsyncd.pid
exclude = lost+found/
# transfer logging = yes
timeout = 300
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
# [ftp]
# path = /home/ftp
# comment = ftp export area
[backup]
path = /backup/
ignore errors
read only = false
list = false
hosts allow = 192.168.15.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
添加虚拟用户且设置为不能登录:
[root@localhost etc]# useradd -M -s /sbin/nologin rsync
创建共享文件夹:
[root@localhost etc]# mkdir /backup
启动服务:
[root@localhost etc]# rsync --daemon
修改共享文件夹的属主属组:
[root@localhost etc]# chown -R rsync:rsync /backup/
修改共享文件夹的权限:
[root@localhost etc]# chmod -R 755 /backup/
[root@localhost etc]# ls -ld /backup/
drwxr-xr-x. 2 rsync rsync 6 Sep 15 11:01 /backup/
将虚拟用户的密码写进文件:
[root@localhost etc]# echo "rsync_backup:123456" > /etc/rsync.password
修改虚拟用户密码文件权限:——(必须修改,否则失败)
[root@localhost etc]# chmod 600 /etc/rsync.password
[root@localhost etc]# ll /etc/rsync.password
-rw-------. 1 root root 20 Sep 15 11:05 /etc/rsync.password
修改/etc/rc.local文件:加入rsync服务为开机自启动:
[root@localhost etc]# vim /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
rsync --daemon
对B—客户端的进行配置:
将服务端虚拟用户密码写入/etc/rsync.password:
[root@localhost backup]# echo "123456" > /etc/rsync.password
修改密码文件权限:
[root@localhost backup]# chmod 600 /etc/rsync.password
进行传送文件:
[root@localhost backup]# rsync -avz /root/———>客户端需要传送的文件 rsync_backup@192.168.15.111::backup --password-file=/etc/rsync.password
将启动脚本放在/etc/init.d/命名文件。
从客户端往服务器端传文件:
[root@localhost backup]# rsync -avz /backup/opt.tar.gz rsync_backup@192.168.15.111::backup --password-file=/etc/rsync.password
从服务器端往回拉文件:
[root@localhost backup]#rsync -avz rsync_backup@192.168.15.111::backup/opt.tar.gz /backup/ --password-file=/etc/rsync.password
排除服务器端部分文件:
[root@localhost backup]# rsync -avz --exclude-from=*** rsync_backup@192.168.15.111::backup /backup/ --password-file=/etc/rsync.password
***表示/root/exclude.txt(文件不限地点,但必须是全路径)里边的内容
–exclude=排除文件名称。
把服务器端的文件同步到客户端:
[root@localhost backup]# ls
opt.tar.gz test
[root@localhost backup]# rsync -avz --delete rsync_backup@192.168.15.111::backup /backup --password-file=/etc/rsync.password
receiving incremental file list
deleting test
./
file
sent 50 bytes received 266 bytes 632.00 bytes/sec
total size is 3,565 speedup is 11.28
[root@localhost backup]# ls
file opt.tar.gz
把客户端内容同步到服务器端:
[root@localhost backup]# rsync -avz --delete /backup/ rsync_backup@192.168.15.111::backup --password-file=/etc/rsync.password
不同步客户端的某个特定文件:
[root@localhost backup]# rsync -avz --delete --exclude=** rsync_backup@192.168.15.111::backup /backup/ --password-file=/etc/rsync.password
将hosts文件同步到/opt目录下
rsync /etc/hosts /opt
将/opt目录拷贝到/mnt
rsync -avz /opt /mnt
cp -ap /opt /mnt
删除功能,相当于rm命令
rsync -avz --delete /old /tmp
对比文件是否相同,使用校验码: