How to delete source files, copied using scp?
I want to copy Apache log files from a remote machine and delete them afterwards – if copying was successful.
Solution 1: rsync --remove-source-files
ssh and tell it to remove synchronized files (non-dir):
rsync -avz --remove-source-files server:log/yyyymmdd.gz myfile
Thanks to tc0nn.
Solution 2: scp && ssh rm
After a successful
ssh to server with
scp server:foo . && ssh server rm foo
After having copied the source file, copy an empty source file back to the original source file. This frees space, but leaves a filename on the server though.
# Copy is successful? if scp server:log/yyyymmdd.gz myfile; then # Yes, copy is successful; # Create empty file touch empty_file # Copy empty file to server source file scp empty_file server:log/yyyymmdd.gz fi
Someone submitted (and withdrew) an scp patch to delete source files after copy.
Perhaps I could schedule the copy on the client.