“This is the third day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021.”
The first problem in the script is that backup data of different servers needs to be managed separately. Implementation method: Create different directories to back up data of different servers
mkdir /backup/$ip_info -p
tar zchf /backup/$ip_info/www_backup_${date_info}.tar.gz ./var/html/www/
Copy the code
The second problem with the script is that you need to keep the data of Each Monday
$(date +%F_week%w -d -1day)
Copy the code
The third problem with the script: the need to verify data integrity
[root @ backup 172.16.1.8]# md5sum -c finger.txt / backup / 172.16.1.8 / sysconfig_iptables_2020-10-31 _week6. Tar. Gz: OK/backup / 172.16.1.8 / sysconfig_spool_2020-10-31 _week6. Tar. Gz: OK/backup / 172.16.1.8 / www_backup_2020-10-31 _week6. Tar. Gz: OK/backup / 172.16.1.8 / sysconfig_scripts_2020-10-31 _week6. Tar. Gz: OK/backup / 172.16.1.8 / sysconfig_local_2020-10-31 _week6. Tar. Gz: OK# Step 1: Read the fingerprint file information
# step 2: Generate MD5 value information for each file based on the known file information
# step 3: Compare the MD5 value information generated locally with the MD5 value information in the fingerprint file
Step 4: If the comparison results are consistent, the complete file verification is successful; otherwise, the verification failsThe find/backup / 172.16.1.7 / -type f -name ".tar.gz"| xargs md5sum > / backup / 172.16.1.7 / finger. TXTCopy the code
Question 4: How do I send an email to the relevant o&M personnel
Ps: Run vim /etc/mail.rc on the backup serversetForm = email address @163.com smtp=smtp.163.com <- mail indicates the domain name of the email server. The value is the domain name of the email serversetSmtp-auth-user = email account smtp-auth-password= email authorization password SMtp-auth-login Specifies the public email address from which emails are sent, the domain name of the email sending server, and the public email account and passwordset [email protected] smtp=smtp.163.com
set[email protected] smtp-auth-password=AHPYEWCFLZDOXSPK smtp-auth=login /etc/init.d/postfix start Enabling the Email service You can send emails as follows:echo "There is an abnormal problem in the system. Please check the system."|mail -s"Abnormal Alarm"[email protected]:echoIt is followed by the information of the email to be sent, followed by the title of the email, and finally indicates the name of the email to be sent"Exception Warning" [email protected] </etc/hosts
Copy the code
Client script information:
#! /bin/bash
date_info=$(date +%F_week%w -d -1day)
ip_info=$(hostname -i)
mkdir /backup/$ip_info -p
cd /
#tar zchf /backup/sysconfigfile_backup_${date_info}tar.gz ./var/spool/cron/root ./etc/rc.local ./etc/sysconfig/iptables ./server/scripts/
# -h Package source file information specified by link file
tar zchf /backup/$ip_info/sysconfig_spool_${date_info}.tar.gz ./var/spool/cron/root
tar zchf /backup/$ip_info/sysconfig_local_${date_info}.tar.gz ./etc/rc.local
tar zchf /backup/$ip_info/sysconfig_iptables_${date_info}.tar.gz ./etc/sysconfig/iptables
tar zchf /backup/$ip_info/sysconfig_scripts_${date_info}.tar.gz ./server/scripts/
mkdir /var/htmL/www /app/Logs -p
tar zchf /backup/$ip_info/www_backup_${date_info}.tar.gz ./var/html/www/
tar zchf /backup/$ip_info/www_backup_${date_info}.tar.gz ./app/log/ find/backup / 172.16.1.8 / -type f -name ".tar.gz"|xargs md5sum >/backup/$ip_info/finger.txt
rsync -az /backup/$ip_info [email protected]::backup --password-file=/etc/rsync.password
find /backup/ -type f -name "*.tar.gz" -mtime +7|xargs rm &>/dev/null
[root@web01 ~]CD /server/scripts/ CD to the backup directory
[root@web01 scripts]# ll /backup
[root@web01 scripts]Sh Execute the script file
[root@web01 scripts]# vim backup_data.sh Write the script file
Copy the code