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

js implementation of verification code case

This article example shares the specific code of ...

MySQL PXC builds a new node with only IST transmission (recommended)

Demand scenario: The existing PXC environment has...

HTML Web Page List Tags Learning Tutorial

HTML web page list tag learning tutorial. In HTML ...

Solution to no Chinese input method in Ubuntu

There is no solution for Chinese input method und...

In-depth explanation of the principle of MySQL Innodb index

introduction Looking back four years ago, when I ...

Semantic web pages XHTML semantic markup

Another important aspect of separating structure ...

Use of hasOwnProperty method of js attribute object

Object's hasOwnProperty() method returns a Bo...

How to install Nginx and configure multiple domain names

Nginx Installation CentOS 6.x yum does not have n...

JavaScript using Ckeditor + Ckfinder file upload case detailed explanation

Table of contents 1. Preparation 2. Decompression...

VMware Workstation 14 Pro installs CentOS 7.0

The specific method of installing CentOS 7.0 on V...

JavaScript Dom implements the principle and example of carousel

If we want to make a carousel, we must first unde...

In-depth explanation of nginx location priority

location expression type ~ indicates to perform a...

Solve the problem of managing containers with Docker Compose

In Docker's design, a container runs only one...