4-10.2 Linux 中的文件同步传输 --- rsync

2021-07-27  本文已影响0人  捌千里路雲和月
[root@localhost test]# 
[root@localhost test]# mkdir backups_b    ## test 目录下新建 backups_b 目录
[root@localhost test]# mkdir SRC    ## test 目录下新建 SRC 目录
[root@localhost test]# cd SRC/
[root@localhost SRC]# 

## SRC 目录下新建 demo1.txt、demo2.txt 和 demo3.txt 三个文件
[root@localhost SRC]# touch demo1.txt ; touch demo2.txt ; touch demo3.txt    
[root@localhost test]# tree
.
├── backups_b
└── SRC
    ├── demo1.txt
    ├── demo2.txt
    └── demo3.txt

2 directories, 3 files
[root@localhost test]# 
## 把 SRC 目录下的 demo1.txt 文件备份到 backups_b/ 目录下

[root@localhost test]# rsync -b SRC/demo1.txt backups_b/
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_b
│   └── demo1.txt    ## 首个备份文件 demo1.txt 不会带 ~ 符号标识。
└── SRC
    ├── demo1.txt
    ├── demo2.txt
    └── demo3.txt

2 directories, 4 files
[root@localhost test]# ll backups_b/
total 0

## backups_b/ 目录下的 demo1.txt 时间是跟系统时间 10:28。
-rw-r--r--. 1 root root 0 Jul 24 10:28 demo1.txt    
[root@localhost test]# 
[root@localhost test]# ll SRC/
total 0
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo1.txt    ## SRC源文件 demo1.txt 时间 22:44
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo2.txt
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo3.txt
## 把 SRC 目录下的 demo1.txt文件再一次备份到 backups_b/ 目录下。
[root@localhost test]# rsync -b SRC/demo1.txt backups_b/
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_b
│   ├── demo1.txt    ## 新文件
│   └── demo1.txt~   ## 原来的同名文件会加上 ~ 符号,作为备份文件 
└── SRC
    ├── demo1.txt
    ├── demo2.txt
    └── demo3.txt

2 directories, 5 files
[root@localhost test]# 
[root@localhost test]# ll backups_b/
total 0
-rw-r--r--. 1 root root 0 Jul 24 10:47 demo1.txt    ## 新文件
-rw-r--r--. 1 root root 0 Jul 24 10:28 demo1.txt~    ## 旧文件
[root@localhost test]# 

[root@localhost test]# 
[root@localhost test]# mkdir backups_backup
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_backup
└── SRC
    ├── demo1.txt
    ├── demo2.txt
    └── demo3.txt

2 directories, 3 files
[root@localhost test]# rsync --backup SRC/demo2.txt backups_backup/
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_backup
│   └── demo2.txt
└── SRC
    ├── demo1.txt
    ├── demo2.txt
    └── demo3.txt

2 directories, 4 files
[root@localhost test]# ll backups_backup/
total 0
-rw-r--r--. 1 root root 0 Jul 24 15:12 demo2.txt    ## 系统时间
[root@localhost test]# 
[root@localhost test]# ll SRC/
total 0
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo1.txt     
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo2.txt    ## 源文件创建时间
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo3.txt
[root@localhost test]# rsync --backup SRC/demo2.txt backups_backup/
[root@localhost test]# 
[root@localhost test]# tree
.
├── backups_backup
│   ├── demo2.txt     ## 新文件
│   └── demo2.txt~    ## 原来的同名文件会加上 ~ 符号,作为备份文件
└── SRC
    ├── demo1.txt
    ├── demo2.txt
    └── demo3.txt

2 directories, 5 files
[root@localhost test]# 
[root@localhost test]# ll backups_backup/
total 0
-rw-r--r--. 1 root root 0 Jul 24 15:13 demo2.txt    ## 新文件
-rw-r--r--. 1 root root 0 Jul 24 15:12 demo2.txt~     ## 旧文件
[root@localhost test]# 
[root@localhost test]# ll SRC/
total 0
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo1.txt     
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo2.txt    ## 源文件创建时间
-rw-r--r--. 1 root root 0 Jul 22 22:44 demo3.txt
[root@localhost test]# 
上一篇 下一篇

猜你喜欢

热点阅读