rsync - 备份/复制

markdown
阅读 34 收藏 0 点赞 0 评论 0

Backup-Copy-rsync .md
# 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

```
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号