Case
00 per night. Package backup system configuration files, file program directories, and access logs on Web server A and push to Server B for backup retention via the rsync command (backup ideas can be packaged locally by date and then pushed to B), the Web server is packaged for 7 days, and the backup server is retained for 6 months
192.168.88.72--A---Web server
192.168.88.67--b---Backup server
Mkdir/var/html/www/app/logs-p//Create 2 folders in 72, note: WWW is the Service Site directory, logs is 72 access log path
Yum Install rsync//Set rsync on two machines, respectively
I. Creating an RSYNC profile (server 67)
vi/etc/rsyncd.conf//Create Rsync profile and enter the following
#rsync_config_______________start
# #rsyncd. conf start##
UID = rsync
GID = rsync
Use chroot = no
Max connections = 200
Timeout = 300
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
Log file =/var/log/rsyncd.log
Ignore errors
Read Only = False
List = False
Hosts allow = 192.168.88.0/24
Hosts Deny = 0.0.0.0/32
Auth users = Rsync_backup
Secrets file =/etc/rsync.password
[Backup]
Path =/backup
#rsync_config_______________end
: Wq//Save exit
MKDIR/BACKUP-P//Create backup directory
Useradd rsync//Create rsync user
Chown-r rsync.rsync/backup///For backup authorization
Rsync--daemon//start-up service
Lsof-i: 873//Check whether the service is started
echo "Rsync_backup:oldboy" >>/etc/rsync.password//Create password file, note: Rsync_backup,/etc/ Rsync.password must be consistent with configuration file contents (clipping information is recommended), Oldboy as password
chmod 600/etc/rsync.password//Set permissions for password files to 600
Second, client configuration password file 192.168.88.72 (client 72)
echo "Oldboy" >>/etc/rsync.password//Create password file, note: Rsync_backup,/etc/ Rsync.password must be consistent with configuration file contents (clipping information is recommended), Oldboy as password
chmod 600/etc/rsync.password//Set permissions for password files to 600
MKDIR/BACKUP-P//Create backup directory
rsync-avz/backup/[Email protected]::backup--password-file=/etc/rsync.password//test can be pushed, and then 67 to see if the backup directory is pushed successfully
Iii. creating scripts and timed tasks on the client (client 72)
Mkdir/server/scripts//Create a directory to store scripts
Cd/server/scripts//Enter the storage script directory
1, Script (function: Package, push, add successful identity, delete after 7 days of compression package)
VI bak.sh//Common packaging script, fill in the following content
#!/bin/sh
ip=$ (ifconfig eth0|sed-n ' 2p ' |awk-f "[:]+" ' {print $4} ')
[!-d/backup/$ip] && mkdir-p/backup/$ip
cd/backup/$ip &&\
Tar zcf bak_$ (date +%f). tar.gz/var/www/html//app/logs/access_$ (date +%f-d ' -1day '). log/var/spool/cron//etc/
rsync-az/backup/[email protected]::backup--password-file=/etc/rsync.password && Touch ${ip}_flag_$ (Date +% F
rsync-az/backup/[Email Protected]::backup--password-file=/etc/rsync.password
Find/backup-type f-name "*.tar.gz"-mtime +7|xargs rm-f
: Wq//Save exit
See if there is an IP-based directory under both server backup directories
2. Scheduled Tasks
CRONTAB-E//Create a timed task, add the sentence below
XX * * * */bin/sh/server/scripts/bak.sh >/dev/null 2>&1
Iv. creating scripts and timed tasks on the server side (server 67)
Save 60 days after deletion
Mkdir/server/scripts//Create a directory to store scripts
Cd/server/scripts//Enter the storage script directory
1, vi bak.sh//Create a script, add the sentence below
find/backup/-type f-name "*.tar.gz"-mtime +180|xargs rm-f//Remove 6 months of compression pack
2. Scheduled Tasks
CRONTAB-E//Create a timed task, add the sentence below
XX * * 6/bin/sh/server/scripts/bak.sh >/dev/null 2>&1//Every Saturday execution script
Five, timing record backup results check
1, vi/rsyncup.sh//Create a script, add the sentence below
/usr/bin/du-sh/backup/* >>/tmp/rsyncup.log//Check write to Rsyncup.log for timing record backup results
2, CRONTAB-E//Create a timed task, add the sentence below
XX * * 1/bin/sh/server/scripts/rsyncup.sh >/dev/null 2>&1//Every Monday execution script
Note: This content is self-study note, record more casual, for reference only, thank you;
This article is from the "11104762" blog, please be sure to keep this source http://11114762.blog.51cto.com/11104762/1826453
Rsync timed Backup case