Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Common commands of rsync and the realization of remote backup

Shulou Source: shulou.com Published: 2022-06-01 01:43:01 09月19日 Update

Rsync

Rsync not only transmits fast, but also can compare the difference between the content to be copied and the local data, if there is any difference.

Only the data with differences is backed up. If there is no difference, there is no need for backup.

Two ways of working:

1. Run on the local machine, same as the cp command; for example: rsync-av / etc / tmp

two。 Run between two hosts through ssh; for example: rsync-av-e ssh root@192.168.50.163:/etc / tmp

Common commands:

-v: view mode, which can list a lot of information

-Q: in contrast to-v, quiet mode skips the normal message and displays only the error content

-r: recursive replication. It is very important that you can deal with the catalog.

-u: update only. If the target file is newer, the new file will not be overwritten.

-a: retain various attributes of the original file

Common combinations:

-av

Example: write a script to back up remote data through ssh, and realize daily automatic backup through cron.

# ssh-keygen-t rsa

# ssh-copy-id-I / root/.ssh/id_rsa.pub root@192.168.50.163

Log in as a key so that you don't need to enter a password when you back up remotely

# vim back.sh (write backup script)

#! / bin/bash

Localdir=/tmp/backup

Remotedir= "/ etc / boot / home"

Remoteip= "192.168.50.163"

[- d ${localdir}] | | mkdir ${localdir}

For dir in ${remotedir}; do

Rsync-av-e ssh root@$ {remoteip}: ${dir} ${localdir}

Done

# chmod + x backup.sh (add execution permissions to scripts)

Join the mission plan

# crontab-e

The test was executed successfully

Tags: Backup difference data file method script command common information content mode transfer run quiet important success two host between task Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi MySQL OPPO Reno Microsoft