Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Common commands of rsync and the realization of remote backup

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report