Rsync 同步备份服务器重要配置文件

步骤:

1.确定备份目标服务器list 

2.确定备份目标文件路径

3.制订备份策略

4.搭建rsync server

5.生成执行备份脚本

6.saltstack分发脚本到备份目标服务器

7.saltstack批量配置cron计划任务到备份目标服务器

8.在rsync server配置cron计划任务定时生成tar包存储到指定路径

 

一、确定备份目标服务器list

  PMC PMS LS

二、确定备份目标文件路径

  /etc/lis  /etc/logstash  /lib/systemd/system

三、备份策略

  每天23点同步备份到rsync server

  每天23::50 rsync server 打包备份文件 转移到目录 /opt/backup_tar/ 下

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#rsync tool 

#rsync server installation

yum -y install rsync 

vi /etc/rsyncd.conf

#####################################################

uid = rsync 

gid = rsync 

user chroot = no 

max connections = 200

pid file = /var/run/rsyncd.pid

timeout = 300

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

 

[backup]

path = /backup/

ignore errors 

read only = false 

list = false 

auth users = rsync_backup

secrets file = /etc/rsync.passwd

#####################################################

echo 'rsync_passwd' > /etc/rsync.passwd

chmod 600 /etc/rsync.passwd

systemctl restart rsyncd && systemctl enable rsyncd

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

chmod +x config_backup.sh

#scripts for client

#!/bin/bash

#location /root/config_backup.sh

yum -y install rsync 

systemctl restart rsyncd && systemctl enable rsyncd

if [ ! -f /etc/rsync.passwd ]; then 

  touch /etc/rsync.passwd

  echo 'rsync_passwd' > /etc/rsync.passwd

else 

  echo 'rsync_passwd' /etc/rsync.passwd

fi 

chmod 600 /etc/rsync.passwd

rsync -avzP /etc/lis rsync_backup@rsyncserver::backup/$HOSTNAME --password-file=/etc/rsync.passwd

rsync -avzP /lib/systemd/system rsync_backup@rsyncserver::backup/$HOSTNAME --password-file=/etc/rsync.passwd

rsync -avzP /etc/logstash rsync_backup@rsyncserver::backup/$HOSTNAME --password-file=/etc/rsync.passwd

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#file and script delivery(clients)

salt-cp '*' config_backup.sh /root/config_backup.sh

salt '*' cron.set_job root '0' '23' '*' '*' '*' '/usr/bin/bash /root/config_backup.sh'

 

#rsync server tar 

50 23 * * * /usr/bin/bash /root/config_tar.sh

 

chmod +x /root/config_tar.sh

#####################################################

#!/bin/bash

cd /opt/backup_tar

tar -czPf `date +%Y-%m-%d`_config_backup.tar /backup

#####################################################

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

posted @ 2018-06-16 16:58  Tyrone_y  阅读(148)  评论(0编辑  收藏  举报