Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

One-click deployment of rysnc to achieve full network backup

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The tool you need: ansible bulk Management tool

Train of thought:

Realize automatic installation of rysnc backup server with one click, and realize full network backup.

The rysnc configuration file is pushed to our rysnc server on the management machine, so we can modify the configuration file on our rysnc server at any time on the management machine.

Rysnc configuration file writes two modules backup nfsbakcup is the directory shared by the two backups

Backup shared directory is the data that stores the backup of the whole network.

The nfsbackup shared directory is to back up the data on our NFS server for real-time synchronization.

The client needs to push data to the rsync backup server. Once a day, two scripts are written, one is to back up the system configuration files of all machines in the network, and the other is to back up the script of the program files on the web server.

The client backup program script is placed on the management machine, which is executed at 00:00 every night by copying it to the client and adding scheduled tasks.

Manage catalog planning on the machine:

Script catalog: / etc/ansible/playbook/

One-click deployment backup server script file name: rsyncserver.yml

Rsyncserver.yml the main function of this script: to build a rsync backup server.

Script directory: server/script/

Script file name: sysconf-backup.sh packages the main files of the backup system and pushes the backed up files to the backup server

Configuration file directory: / server/configfile/

Main configuration file for rsync service: rsyncd.conf

Configuration file of mail.rc mail to check the integrity of backup data this time mainly by QQ Mail

Using ansible to build rsync with one click

[root@m01 playbook] # vim rsyncserver.yml

-hosts: rsyncserver

Tasks:

-name: 1: install rysnc

Yum: "name=rsyncstate=installed"

-name: 2:rsync configuration file

Copy: "src='/server/configfile/rsyncd.conf' dest='/etc'"

-name: 3: create a virtual user for rsync service

User: "name='rsync'shell=/sbin/nologin createhome=no"

-name: 4: create a shared directory backup and modify the group primary permissions

File: "path=/backupstate=directory owner=rsync group=rsync"

-name: 5: create a shared directory nfsbackup and modify the group primary permissions

File: "path=/nfsbackup state=directory owner=rsync group=rsync"

-name: 6: create a virtual authenticated user password file and modify permissions

Shell: "echorsync_backup:123456 > / etc/rsync.password & & chmod 600/etc/rsync.password"

-name: 7: start rsync

Shell: "rsync--daemon"

-name: 8: add to boot self-boot

Shell: "[`egrep'rsync-- daemon' / etc/rc.local | wc-l`-eq 1] | | echo-e'# rsync start\\ nrsync--daemon' > > / etc/rc.local"

-name: 9:rsync server configuration is complete

Shell: "echo rsync configuration complete"

-name: mailbox configuration file to check the integrity of network-wide backup data and send it to mailbox

Copy: "src=/server/configfile/mail.rc dest=/etc"

1.1 the client backs up the system configuration file to the backup directory, and then pushes the script to the backup server

The second script is mainly to push our M01 backup system configuration file script to the client server, and then add scheduled tasks to push our backed-up system configuration file to the backup server at 00:00 every night.

M01 server configuration script

[root@m01 playbook] # vim rsync-client-sysconf-backup.yml

-hosts: client-sysconf-backup

Tasks:

-name: 1:rsync client password file and modify password file permissions

Shell: "echo'123456' > / etc/rsync.password & & chmod 600 / etc/rsync.password"

-name: 2: create backup directory backup and script directory

Shell: "mkdir-p/backup & & mkdir-p / server/script"

-name: 3: push system configuration file packaging script

Copy: "src=/server/script/sysconf-backup.sh dest=/server/script/"

-name: 4: pack the backup files at 0: 00 p.m. Every night and push them to the backup server

Cron: "name='Everyday 00 backup sysconfig to rsync by Kaile' minute=00 hour=

00 job='/bin/sh / server/script/sysconf-backup.sh' "

1.1.1 client backup system profile data is pushed to the backup server script

This script is a system configuration file backup script, which can implement all machines and back up system configuration files.

The main role is to back up the common configuration files of the system.

Encrypt the backed-up configuration files with md5

Send the system configuration files and encrypted md5 files that we back up every day to the backup server at 00:00 every day.

Delete local data from 7 days ago

[root@m01 script] # vim sysconf-backup.sh

#! / bin/bash

IP= `hostname-I | cut-d ""-f2`

IPDIR= "/ backup/$ {IP}"

# create a packaged backup directory

Mkdir-p $IPDIR

# backup sysconfig

Cd / & tar-czPhf $IPDIR/sysconfig_$ (date+%F-week0%w). Tar.gz. / var/spool/cron/root

. / etc/rc.local./server/scripts. / etc/sysconfig/iptables > / dev/null 2 > & 1

# check backup sysconfig

Find $IPDIR/-type f-name "* $(date +% F-week0%w) .tar.gz" | xargs md5sum > ${IPDIR} / md

5 summation $(date +% F-week0%w) .txt

# Push push sysconfig to rsync backup server

Rsync-az / backup/$IP rsync_backup@172.16.1.41::backup-- password-file=/etc/rsync.pa

Ssword

# delete + 7 day backup data

Rm-rf $(find $IPDIR-type f-mtime + 7)

1.2 client backup website service script

M01 script backup web program

[root@m01 playbook] # vim rsync-client-website-backup.yml

-hosts: client-website-backup

Tasks:

-name: 1:rsync client password file and modify password file permissions

Shell: "echo'123456' > / etc/rsync.password & & chmod 600 / etc/rsync.password"

-name: 2: create backup directory backup and script directory

Shell: "mkdir-p/backup & & mkdir-p / server/script"

-name: 3: push website program file packaging script

Copy: "src=/server/script/website-backup.sh dest=/server/script/"

-name: 4: pack the backup files at 0: 00 p.m. Every night and push them to the backup server

Cron: "name='Everyday 00 backup website to rsync by Kaile' minute=00 hour=00 job='/bin/sh/server/script/website-backup.sh'"

1.2.1 client backup website program file data is pushed to the backup server script

The client backup directory is: web172.16.1.8 is pushed to the backup server. This is the same directory.

[root@web01 script] $vim website-backup.sh

#! / bin/bash

IP= `hostname-I | cut-d ""-f2`

IPDIR= "/ backup/web$ {IP}"

# create a packaged backup website directory

Mkdir-p $IPDIR

# backup website data

Cd / & tar-czPhf $IPDIR/nginx_$ (date +% F-week0%w) .tar.gz/application/nginx/html/

# backup website log

Cd / & tar-czPhf $IPDIR/web_log_$ (date +% F-week0%w) .tar.gz/application/nginx/logs/

# check backup website

Find $IPDIR/-type f-name "* $(date+%F-week0%w) .tar.gz" | xargs md5sum > ${IPDIR} / md5sum_$ (date+%F-week0%w) .txt

# Push push website to rsync backupserver

Rsync-az $IPDIR rsync_backup@172.16.1.41::backup-- password-file=/etc/rsync.password

# delete + 7 day backup data

Rm-rf $(find $IPDIR-type f-mtime + 7)

1.3 backup server checks the integrity of the data backed up every day

Configuration files for the system, and web server program files, and email notifications are sent every day

[root@backup script] # vim check-sysconfig-backup.sh

#! / bin/bash

# check sysconfig website data

Find / backup/-type f-name "* $(date+%F-week0%w) .txt" | xargs md5sum-c > / tmp/md5-$ (date+%F-week0%w) .txt

# email Notification

Mail-s "backup date" 10206334@qq.com / dev/null 2 > & 1

# delete + 180 day 01

Rm-rf $(find / backup/-type f-mtime + 180!-name "* $(date+%F-week01) .tar.gz")

1.4QQ Mailbox profile

# mail config

Set bsdcompat

Set from=10206334@qq.com

Set smtp=smtp.qq.com

Set smtp-auth-user=10206334@qq.com

Set smtp-auth-password=odigxgzaschvbijd

Set smtp-auth=login

Set smtp-use-starttls

Set ssl-verify=ignore

Set nss-config-dir=/etc/pki/nssdb

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report