[英]rsync : dont delete few files in source after upload
I want to write a shell script to use rsync to transfer files between folders called source
and destination
.我想编写一个 shell 脚本来使用rsync在名为
source
和destination
文件夹之间传输文件。
Contents of source folder源文件夹的内容
A
B
C
test1.log
test2.json
I would like to transfer all files from source to destination , and want to delete all source files except test1.log
and test2.json
我想将所有文件从源传输到目标,并想删除除
test1.log
和test2.json
之外的所有源文件
ie after uploading all files to destination, Content of source folder should be :即在将所有文件上传到目标后,源文件夹的内容应为:
test1.log
test2.json
Contents of destination folder should be :目标文件夹的内容应该是:
A
B
C
test1.log
test2.json
I experimented with我尝试过
rsync -aP --timeout=120 --remove-source-files -e "ssh -o StrictHostKeyChecking=no -i /id" source user@1.1.1.1:/destination_path/ --exclude=test1.log --exclude=test2.json
But in that case, test1.log
and test2.json
are excluded from uploading itself.但在这种情况下,
test1.log
和test2.json
被排除在上传本身之外。
But I want all files to be uploaded to destination, most of them deleted from source after upload, but want to keep few files in source.但我希望所有文件都上传到目的地,上传后大部分文件从源中删除,但希望在源中保留很少的文件。
Is there any way to do it with rsync
?有没有办法用
rsync
做到这一点?
As user1934428
pointed out,if I use --remove-source-files
there is no way to keep some files not deleted after transfer.正如
user1934428
指出的那样,如果我使用--remove-source-files
,则无法在传输后保留某些文件不被删除。 So I ended up in using the below solution, which is not efficient since rsync
has to be called twice.所以我最终使用了下面的解决方案,因为
rsync
必须被调用两次,所以效率不高。
rsync -aP --timeout=120 --remove-source-files -e "ssh -o StrictHostKeyChecking=no -i /id" source user@1.1.1.1:/destination_path/ --exclude=test1.log --exclude=test2.json
rsync -aP --timeout=120 -e "ssh -o StrictHostKeyChecking=no -i /id" source user@1.1.1.1:/destination_path/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.