Rsync+SSH安全定时备份

  之前有写个linux之间的Rsync备份,现在写一份Rsync+ssh通道安全备份

  Server:   192.168.101.115

  Client:   192.168.101.116

  首先在 Client 做密钥

  [root@Client .ssh]# ssh-keygen -t rsa -P ''

  Generating public/private rsa key pair.

  Enter file in which to save the key (/root/.ssh/id_rsa):

  Your identification has been saved in /root/.ssh/id_rsa.

  Your public key has been saved in /root/.ssh/id_rsa.pub.

  The key fingerprint is:

  8d:89:b6:f2:6c:34:9c:da:7e:a7:b1:02:59:a4:8e:f6 root@Client

  The key's randomart image is:

  上传密钥到 Server

  [root@Client /]# ssh-copy-id -i /root/.ssh/id_rsa.pub "-p 22 root@192.168.101.115"

  Server和 Client 都安装 Rsync

  wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz

  tar zxvf rsync-3.0.9.tar.gz

  cd rsync-3.0.9

  ./configure –prefix=/usr && make && make install

  Server 配置Rsync

  [root@Server /]# vim /etc/rsyncd.conf

  uid = root

  gid = root

  use chroot = yes

  max connections = 3

  pid file = /var/run/rsyncd.pid

  lock file = /var/run/rsync.lock

  log file = /var/log/rsyncd.log

  port = 873

  hosts allow = 192.168.101.116

  log format = %t %a %m %f %b

  [web]

  comment = web file

  path = /data/bak

  ignore errors

  read only = no

  #write only = no

  list = no

  auth users = amei

  secrets file = /data/pad

  制作认证密码文件  和 加入开机启动

  [root@Server /]# echo 80uncle:80uncle > /etc/rsyncd.secrets

  [root@Server /]# chown root:root /etc/rsyncd.secrets //修改权限

  [root@Server /]# chmod 600 /etc/rsyncd.secrets

  Server 加入开机启动:

  [root@Server /]# chkconfig rsync on

  或者

  [root@Server /]# chkconfig –add rsync

  Server 启动 Rsync

  [root@Server /]# /usr/bin/rsync –daemon

  Client 加入开机启动:

  [root@Client /]# chkconfig rsync on

  或者

  [root@Client /]# chkconfig –add rsync

  Client 启动 Rsync

  [root@Client /]# /usr/bin/rsync –daemon

  最后在Client 编写 shell

  [root@Client /]# vim /data/shell/ssh_rsync.sh

  #!/bin/bash

  /usr/bin/rsync -avz –delete -e ssh root@192.168.101.115:/data/bak /data/abc

  ######### -e ssh 是采用ssh模式 #########

  ### root@192.168.101.115:/data/bak 是Server要同步的文件夹

  ### /data/abc 是将Server 同步到本地的文件夹

  加入crontab定时执行

  00 01 * * * /data/shell/ssh_rsync.sh

  ###每天凌晨1点定时备份###

 

发表评论

邮箱地址不会被公开。 必填项已用*标注