Reputation: 455
I want to write a shell script to use rsync to transfer files between folders called source
and 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
i.e 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 [email protected]:/destination_path/ --exclude=test1.log --exclude=test2.json
But in that case, test1.log
and test2.json
are excluded from uploading itself.
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
?
Upvotes: 0
Views: 880
Reputation: 455
As user1934428
pointed out,if I use --remove-source-files
there is no way to keep some files not deleted after transfer.
So I ended up in using the below solution, which is not efficient since rsync
has to be called twice.
rsync -aP --timeout=120 --remove-source-files -e "ssh -o StrictHostKeyChecking=no -i /id" source [email protected]:/destination_path/ --exclude=test1.log --exclude=test2.json
rsync -aP --timeout=120 -e "ssh -o StrictHostKeyChecking=no -i /id" source [email protected]:/destination_path/
Upvotes: 1