Pull data regularly rsync

Server A (main) 10.12.237.234

Server B (slave) 10.12.237.232

Requirements: Server B regularly pulls and backs up the data of Server A.

Implementation method: rsync

1. Install rsync on both servers

1) Check whether to install rpm -aq rsync installation command yum -y install rsync

2) The backup server B starts the service

rsync --daemon

3) View service

ps -ef |grep rsync #or netstat -lnutp |grep rsync

Second, the main server A configures users

New users

useradd rget

set password

echo '123456' | passwd --stdin rget

Setting permissions

setfacl -R -m user:rget:rwx /tmp

Set default permissions in time for future directory changes

setfacl -R -m default:rget:rwx /tmp

Check if the permissions are correct

getfacl /tmp

 

 

Three, backup server B generates a key

1) Generate the key (just press Enter all the time)

ssh-keygen -t rsa

2) Copy the key, here you need to enter the password just configured by server A

ssh-copy-id   [email protected]

3) Test login server A (main)

ssh     [email protected]

4) After logging in successfully, exit and exit

 

Fourth, the backup server B performs synchronization

1) Execute the command

rsync  -azP  --delete  [email protected]:/tmp   /data/backup

# --delete delete data that is not in the source file

If there are files in /tmp in the backup directory, the synchronization is successful.

2) Write script

vi rsync_back.sh

#!/bin/bash

rsync  -az  [email protected]:/tmp   /data/backup

 

#When backing up regularly, you can remove the P in -azP without looking at the progress.

Delete should also be removed to prevent accidental deletion.

Execute chmod +x rsync_back.sh

 

3) Timing synchronization every Friday at 23:00

Command crontab -e

0 23 0 0 5  /home/rsync_back.sh &

#Regular backup

tar -zcvf  backup_`date +%Y-%m-%d`.tar.gz /data/backup/

Of course, it is extremely insecure to implement backups in this way. Rget users can log in to the system, which means they can perform various operations, even elevation of privileges, so you need to give proper permissions.

Guess you like

Origin blog.csdn.net/Doudou_Mylove/article/details/108337995