备份方式
- 本地备份
- 远程备份
- 全量备份
- 增量备份
备份软件
- cp
- scp
- rsync
- lvm
- drbd
- cwrsync
https://www.itefix.net/cwrsync
rsync
https://rsync.samba.org/documentation.html
https://www.samba.org/ftp/rsync/rsync.html
特点: 支持本地,远程,全量,增量备份
rsync工作方式
- 本地模式
Local: rsync [OPTION...] SRC... [DEST]
- 远程模式
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
- 守护进程
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
rsync选项
选项 | 含义 |
---|---|
-a, --archive | archive mode; equals -rlptgoD |
-r, --recursive | 对子目录以递归模式处理 |
-l | 只传输链接文件 |
-p, --perms | 保持文件权限 |
-t, --times | 保持文件时间信息 |
-g, --group | 保持文件属组信息 |
-o, --owner | 保持文件属主信息 |
-D, --devices | 保持设备文件信息 |
-v, --verbose | 详细过程 |
-z, --compress | 传输过程中压缩 |
-L | 传输链接文件,并将源文件中的内容放入链接文件中 |
-P, --partial | 断点续传 |
-e, --rsh=command | 指定使用rsh、ssh方式进行数据同步 |
–delete | 删除那些DST中SRC没有的文件 |
–bwlimit= | limit I/O bandwidth |
–exclude=PATTERN | 指定排除不需要传输的文件模式 |
–exclude-from=FILE | 排除FILE中指定模式的文件 |
–password-file=FILE | 从FILE中得到密码 |
rsync守护进程方式
服务端
配置文件
/etc/rsyncd.conf
/etc/sysconfig/rsyncd
主配置文件 /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
path = /backup
密码文件 /etc/rsync.password (权限600)
rsync_backup:123
备份目录 /backup (授权 rsync.rsync)
启动
systemctl start rsyncd.service
客户端
密码文件 /etc/rsync.password (权限600)
123
测试
Pull
rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push
rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
rsync无认证配置
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = true
list = true
[yum]
path = /usr/share/nginx/html
rsync指定配置文件运行
vim /usr/lib/systemd/system/rsyncd.service
[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/tmp/rsyncd.conf
[Service]
EnvironmentFile=/etc/sysconfig/rsyncd
ExecStart=/usr/bin/rsync --daemon --config=/tmp/rsyncd.conf --no-detach "$OPTIONS"
[Install]
WantedBy=multi-user.target
vim /tmp/rsyncd.conf
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = true
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
path = /backup
[wuxing]
path = /wuxing
rsync使用其它端口
服务端
vim /tmp/rsyncd.conf
uid = rsync
gid = rsync
port = 874
fake super = yes
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = true
hosts allow = 172.16.1.0/24
#auth users = rsync_backup
#secrets file = /etc/rsync.password
[backup]
path = /backup
[wuxing]
path = /wuxing
客户端操作
rsync -avz rsync://172.16.1.41:874/backup
rsync -avz --port=874 172.16.1.41::backup
rsync环境变量
strings /usr/bin/rsync |grep "^RSYNC_"
RSYNC_RSH
RSYNC_ICONV
RSYNC_PROTECT_ARGS
RSYNC_PARTIAL_DIR
RSYNC_PROXY
RSYNC_CONNECT_PROG
RSYNC_MODULE_NAME
RSYNC_HOST_NAME
RSYNC_HOST_ADDR
RSYNC_USER_NAME
RSYNC_MODULE_PATH
RSYNC_PID
RSYNC_RAW_STATUS
RSYNC_EXIT_STATUS
RSYNC_REQUEST
RSYNC_ARG%d=%s
RSYNC_PASSWORD
rsync同步公网yum源
/usr/bin/rsync -zrLptgoDP --delete --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://mirrors.tuna.tsinghua.edu.cn/centos/7 /usr/share/nginx/html/centos/
排除文件
/usr/share/nginx/html/rsync_exclude.txt
atomic/
configmanagement/
cr/
cloud/
dotnet/
fasttrack/
isos/
nfv/
opstools/
paas/
rt/
sclo/
storage/
virt/
附
邮件配置
/etc/mail.rc
set from=123456@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=123456@qq.com
set smtp-auth-password=ihppxhssqsiqbfie
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/