Linux Server Data Migration-Full network backup

Source: Internet
Author: User
Tags rsync

    1. Project Requirement Description:

1) The backup directory for all servers must be/backup.

2) The system configuration files to be backed up include, but are not limited to:

A. Scheduled Task service configuration file (/var/spool/cron/root) (for Web and Server for NFS).

B. Boot-up configuration file (/etc/rc.local) (for Web and NFS servers).

C. Directory of daily Scripts (/server/scripts).

D. Firewall iptables configuration file (/etc/sysconfig/iptables).

E. What else do you need to back up when you think about it?

3) The WEB Server site Directory is assumed to be (/VAR/HTML/WWW).

4) WEB Server A Access log path assumed to be (/app/logs)

5) The WEB server retains the packaged 7 days of backup data (local retention cannot be more than 7 days, because too many hard drives are full)

6) on the backup server, keep all copies of the data for every Monday, and the other to retain a copy of the data for 6 months.

7) on the backup server to the backup data server on the intranet IP for the directory to save the backup, the backup file is saved by the time name.

8) need to ensure that the backed up data is as complete and correct as possible, and the backup data is checked on the backup server, and the success and failure results of the backup

2. Installing the Rsync service on the backup server

1) Installing the Rsync service

[Email protected] scripts]# pwd

/server/scripts

[Email protected] scripts]# vim rsyncserver_install.sh

#!/bin/sh

Rsync_judge= ' Rpm-qa|grep rsync|wc-l ' #定义判断的变量

If [$rsync _judge-eq 1] #判断rsync服务是否安装

Then

echo "Rsync in Installed"

Else

Yum Install Rsync-y

Fi

Touch/etc/rsyncd.conf #创建rsync配置文件

/bin/cat >/etc/rsyncd.conf<<eof #导入配置文件

Lock file =/var/run/rsync.lock

Log file =/var/log/rsyncd.log

Ignore errors

Read Only = False

List = False

Auth users = Rsync_backup

Secrets file =/etc/rsync.password

[Backup]

Comment = "Backup dir by Oldboy"

Path =/backup

UID = rsync

GID = rsync

Hosts allow = 172.16.1.0/24

Hosts Deny = 0.0.0.0/32

Eof

[-d/backup]| | Mkdir/backup-p #创建备份目录

Useradd rsync-s/sbin/nologin-m >/dev/null 2>&1 #创建rsync授权用户

Chown-r Rsync.rsync/backup #对备份目录进行授权

echo "rsync_backup:oldboy123" >/etc/rsync.password #创建密码文件

If [' Netstat-lntup|grep rsync|wc-l '-ne 2] #判断rsync服务是否启动

Then

Rsync--daemon

Else

echo "Rsync is running"

Fi

2) Testing

[Email protected] scripts]# sh rsyncserver_install.sh

Rsync in installed

Rsync is running

3. Client Rsync service and test

1) scripting

[Email protected] scripts]# pwd

/server/scripts

[Email protected] scripts]# vim rsyncclient_install.sh

#!/bin/sh

Rsync_judge= ' Rpm-qa|grep rsync|wc-l ' #定义变量


If [$rsync _judge-eq 1] #判断rsync服务是否安装

Then

echo "Rsync in Installed"

Else

Yum Install Rsync-y

Fi

[-d/backup]| | Mkdir/backup-p #创建备份目录

echo "oldboy123" >/etc/rsync.password #指定rsync的密码

Cd/backup #创建123文件进行推送测试

Touch 123.txt

rsync-az/backup/[Email Protected]::backup--password-file=/etc/rsync.password

2) to test

[Email protected] scripts]# sh rsyncclient_install.sh

Rsync in installed

[email protected] backup]# ls #backup服务器被推送过来了

123.txt

4. Executing the client installation script on the Web server

[Email protected] scripts]# sh rsyncclient_install.sh

5. Write a backup script on the NFS01 server

1) Go to the script directory for editing

[Email protected] scripts]# pwd

/server/scripts

[Email protected] scripts]# vim backup_web01.sh

#!/bin/sh

local_ip= ' Ifconfig eth1|awk-f "[:]+" ' Nr==2{print $4} ' #定义本机IP地址

remote_ip= "172.16.1.41" #rsync服务器IP

Cron=/var/spool/cron/root #定义备份路径

Rc=/etc/rc.local

Scripts=/server/scripts

Iptable_rules=/etc/sysconfig/iptables

back_path=/backup/

Time= ' Date +%f_%w-d ' -1day ' #定义时间 because it is 12 o'clock backup at night, so it should be the content of the previous day

If [-D $Back _path] #判断备份目录是否存在, can not do

Then

echo "Backup file is exist"

Else

mkdir $Back _path-p

Fi

Tar zchfp/$Back _path/sysinfo_${time}.tar.gz $Cron $RC $Scripts $Iptable _rules #备份重要文件

Sleep 3

CD $Back _path

md5sum sysinfo_${time}.tar.gz >${back_path}/finger.log #通过md5生成认证日志


Rsync-az $Back _path [email protected]${remote_ip}::backup/${local_ip}--password-file=/etc/rsync.password # Push the contents of the backup directory to the backup server and save it as a directory with its own IP address


Find./-type f-name "*.tar.gz"-mtime +7-exec rm-rf {} \; #删除7天前的内容

6. Write a backup script on WEB01

[Email protected] scripts]# pwd

/server/scripts

[[email protected] scripts]# vim backup_web01.sh #和nfs的备份脚本一样, just a two more directories

#!/bin/sh

local_ip= ' Ifconfig eth1|awk-f "[:]+" ' Nr==2{print $4} '

remote_ip= "172.16.1.41"

Cron=/var/spool/cron/root

Rc=/etc/rc.local

Scripts=/server/scripts

Iptable_rules=/etc/sysconfig/iptables

back_path=/backup/

Time= ' Date +%f_%w-d ' -1day '

Log=/app/logs #log日志目录

Www_backup=/var/html/www #站点目录


If [-D $Back _path]

Then

echo "Backup file is exist"

Else

mkdir $Back _path-p

Fi

Tar zchfp/${back_path}/sysinfo_${time}.tar.gz $Cron $RC $Scripts $Iptable _rules

Tar zchfp/${back_path}/log_${time}.tar.gz $Log

Tar zchfp/${back_path}/www_${time}.tar.gz $www _backup

CD $Back _path

md5sum sysinfo_${time}.tar.gz log_${time}.tar.gz www_${time}.tar.gz >finger.log

#md5sum log_${time}.tar.gz >>finger.log

#md5sum www_${time}.tar.gz >>finger.log

Rsync-az ${back_path} [email protected]::backup/${local_ip}--password-file=/etc/rsync.password

Find $Back _path-type f-mtime +7-exec rm-rf {} \;

7. Server-side configuration

1) first configure the mailbox service

[[email protected] backup]# vim/etc/mail.rc append the following to the end of the document

Set [email protected] smtp=smtp.163.com <-mail server domain name, here is the sending server domain name of 163 mailbox

Set [email protected] smtp-auth-password=xxx #是授权码 Smtp-auth=login

Restart Postfix Service

[Email protected] backup]#/etc/init.d/postfix restart

Shutting down postfix: [OK]

starting postfix: [OK]

2) Edit Script

[Email protected] backup]# cd/server/scripts/

[Email protected] scripts]# vim check_info.sh

#!/bin/sh

. /etc/init.d/functions #加载函数库

Back_path=/backup

src_address1=172.16.1.31

src_address2=172.16.1.8

Time= ' Date +%f_%w-d ' -1day '

#nfs_md5 = ' Md5sum-c md5_2017-08-30_3.log|awk-f ' [:]+ ' ' {print $} '

If [-D $Back _path] #判断备份目录是否存在

Then

echo "Backup file is exist"

Else

mkdir $Back _path-p

Fi

CD ${back_path}/${src_address1}

If [' Md5sum-c finger.log|awk-f ' [:]+ ' ' {print $} ' = = ' OK '] #判断md5校验是否出错

Then

The action "NFS01 backup data is correct"/bin/true

echo "nfs01 backup data is correct" >check_info.log #如果正确就将次信息重定向到Log文件中

Else

The action "NFS01 backup data is correct"/bin/false

echo "nfs01 Backup Data Error" >check_info.log #如果错误就将次信息重定向到Log文件中

Fi

#将结果发送到邮箱

/bin/mail-s "Check_data Mail" [Email protected] <${back_path}/${src_address1}/check_info.log

#删除180天之前的备份结果并保留每周一的内容

Find ${back_path}/${src_address1}-type f-name "*.gz"-mtime +180! -name "*1.tar.gz"-exec rm-rf {} \;

#下面的结果和上面一样

CD ${back_path}/${src_address2}

If [' Md5sum-c finger.log|awk-f ' [:]+ ' nr==1{print $} ' = = ' OK '-a ' md5sum-c finger.log|awk-f ' [:]+ ' \

' Nr==2{print ' = ' = ' OK '-a ' md5sum-c finger.log|awk-f ' [:]+ ' ' nr==3{print $} ' = = ' OK ']

Then

Action "WEB01 Backup data OK"/bin/true

echo "WEB01 backup data OK" >check_info.log

Else

Action "Error WEB01 backup Data"/bin/false

echo "WEB01 Backup data Error" >check_info.log

Fi

/bin/mail-s "Check_data Mail" [Email protected] <${back_path}/${src_address2}/check_info.log

Find ${back_path}/${src_address2}-type f-name "*.tar.gz"-mtime +180! -name "*1.tar.gz"-exec rm-rf {} \;

3) test [[email protected] scripts]# sh check_info.sh

Backup file is exist

NFS01 backup data is correct [OK]

WEB01 backup Data normal [OK]

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/A4/7C/wKioL1mssk7zmFOOAAAbTb7gKP8310.png-wh_500x0-wm_ 3-wmp_4-s_1100637125.png "title=" message. png "alt=" wkiol1mssk7zmfooaaabtb7gkp8310.png-wh_50 "/>

This article is from the "10997527" blog, please be sure to keep this source http://11007527.blog.51cto.com/10997527/1962425

Linux Server Data Migration-Full network backup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.