markdown rsync - 备份/复制

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown rsync - 备份/复制相关的知识,希望对你有一定的参考价值。

# Copy all files that have changed

1. Option 1: Don't include hidden file

```bash

rsync -r --exclude=".*" source/ destination/

```

2. Option 2: Include hidden file

```bash

rsync -avz source/ destination/

```

*Note the slashes at the end of both paths. Any other syntax may lead to unexpected results!*

--------

**The advantages of rsync are:**

- *After the initial sync, it will then copy only the files that have changed.*

- *You can use it over a network, convenient for files in $HOME, especially config files.*


# How to `rsync` a single file?

## Same server:

```bash

rsync -avz /var/www/public_html/source/.htaccess /var/www/public_html/dest/

```


## Different Server:

```bash

rsync -avz /var/www/public_html/.htaccess root@<remote-ip>:/var/www/public_html/

```

3. How to use rsync to backup a directory without git subdirectory

```bash

rsync -avz --exclude='.git/' source/ destination/

```

4. Copying files using rsync from remote server to local machine: 

## From your local machine:

```bash 

rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage

```


## From your local machine with a non standard ssh port:

```shell

rsync -chavzP -e "ssh -p $portNumber" user@remote.host:/path/to/copy /local/path

```


## Or from the remote host, assuming you really want to work this way and your local machine is listening on SSH:

```shell

rsync -chavzP --stats /path/to/copy user@host.remoted.from:/path/to/local/storage

```

以上是关于markdown rsync - 备份/复制的主要内容,如果未能解决你的问题,请参考以下文章

12,RSYNC远程同步复制服务

Linux三阶段之二:备份服务(rsync)

rsync存储服务器-全网备份

开源服务专题之-------rsync数据备份

rsync服务

数据同步服务Rsync