Automatic file synchronization between two Linux servers

Automatic file synchronization between two Linux servers

When server B (172.17.166.11) is powered on or restarted, it will automatically pull all the files in the specified directory on server A (172.17.166.10)

1. Create mutual trust between server B and server A

(1) Execute ssh-keygen -t rsa on Server B and press Enter all the way. (2) Execute ssh-copy-id -i 172.17.166.10 on Server B and press Enter to enter the password of Server A. (3) Execute ssh 172.17.166.10 on Server B to verify whether you can log in to Server A without a password.

2. On Server B

Create the following directory structure

[root@w-11 home]# tree shell
shell
├── logs ----directory └── pull_170.sh ----script

The script is as follows:

#!/bin/bash
#pull_
#author:whz
#date:20200805
#The non-existent variable terminates the script execution set -o nounset
# Execution error terminates script execution set -o errexit
# define restricted path
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
# adirname - return absolute dirname of a given file
adirname() { odir=`pwd`; cd `dirname $1`; pwd; cd "${odir}"; }
MYNAM=`basename "$0"`
MYDIR=`adirname "$0"`
MYLOG_PATH="${MYDIR}/logs"
MYLOG="${MYLOG_PATH}/${MYNAM}_`date +%F`.log"
echo "`which rsync` -avtW --progress --delete [email protected]:/home/iis/ /home/iis/" >> ${MYLOG}
`which rsync` -avtW --progress --delete [email protected]:/home/iis/ /home/iis/ >> ${MYLOG}
exit 0

3. Crontab plan on server B

crontab -e
@reboot /home/shell/pull_10.sh

That’s it, done.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Linux uses the scp command to copy files to the local computer and copy local files to the remote server
  • How to delete folders, files, and decompress commands on Linux servers
  • How to use Samba to build a shared file service on a Linux server
  • How to upload and download files between Linux server and Windows system
  • Python reads files on Linux server
  • Realization of real-time file synchronization between Linux servers
  • How to upload files and folders to Linux server via SSH
  • How to transfer files between Linux local and server and write commands for uploading and downloading files on Linux server

<<:  Summary of knowledge points about covering index in MySQL

>>:  Comprehensive interpretation of MySQL master-slave replication, from principle to installation and configuration

Recommend

Axios secondary encapsulation example Demo in the project

1. Why do packaging? Facilitates overall code cal...

What to do if you forget your Linux/Mac MySQL password

What to do if you forget your Linux/Mac MySQL pas...

Linux MySQL root password forgotten solution

When using the MySQL database, if you have not lo...

How to create a Pod in Kubernetes

Table of contents How to create a Pod? kubectl to...

Detailed steps to install MySQL 5.7 via YUM on CentOS7

1. Go to the location where you want to store the...

Specific example of MySQL multi-table query

1. Use the SELECT clause to query multiple tables...

Box-shadow and drop-shadow to achieve irregular projection example code

When we want to add a shadow to a rectangle or ot...

Web page header optimization suggestions

Logo optimization: 1.The logo image should be as ...

Use of Docker image storage overlayfs

1. Overview The image in Docker is designed in la...

Complete steps to build a squid proxy server in linux

Preface This article mainly introduces the releva...

A brief discussion on several ways to implement front-end JS sandbox

Table of contents Preface iframe implements sandb...

jQuery simulates picker to achieve sliding selection effect

This article shares the specific code of jQuery t...

A brief discussion on whether too many MySQL data queries will cause OOM

Table of contents Impact of full table scan on th...

JavaScript to add and delete messages on the message board

This article shares a small example of adding and...

Vue's Render function

Table of contents 1. Nodes, trees, and virtual DO...