2

I want to move files from server1 to server2.

A producer on server1 will keep generating the files, and a consumer on server2 will keep processing them.

I can copy files using the following shell script:

rsync path/*.txt server2:/path

The extension of the files on the destination (server2) will be changed from .txt to .done once they are processed, so if I run the command again, the files will once again copied (and processed) to the destination.

Hence, I want to delete (or rename or move) the original files so that they won't be transferred again.

I am using rsync version 2.6.3, which does not have --remove-source-files option.

I am new to shell scripting, so please give an example.

2 Answers 2

2

use rsync --remove-source-files option

from man rsync

--remove-source-files
This  tells  rsync  to  remove  from  the sending side the files
(meaning non-directories) that are a part of  the  transfer  and
have been successfully duplicated on the receiving side.

You can always perform a trial run with no changes made using --dry-run option and If you like output run the final command without --dry-runoption

for example:rsync --remove-source-files -options /path/to/src/ computerB:/path/to/dest and also take a look at this question before proceeding.

2
  • rsync version 2.6.3 does not have this option. I don't think I have permission to update rsync.
    – atripathi
    Jan 14, 2013 at 10:34
  • 1
    You can use tee and process substitution for this. for eg: use find to find your files and use tee to send the output to both rsync and rm see this Jan 14, 2013 at 11:14
1

According to the man-page, you should be able to use --remove-source-files for rsync

--remove-source-files

This tells rsync to remove from the sending side the files (meaning non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side.

2
  • rsync version 2.6.3 does not have this option. I don't think I have permission to update rsync.
    – atripathi
    Jan 14, 2013 at 10:35
  • @prodigy2050 Hmm, I do not have an alternative for you in that case.
    – Bernhard
    Jan 14, 2013 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .