I am trying to come up with a Shell script that can tar a file and copy (scp?) it from Host A to a remote host B at a particular destination
/foo, and rename it to a particular time format we use let's say YYYY-MM-DD.
Now to add to this functionality let's say there's a file
foo.txt that is copied from Host A to a path on Host B on a particular date, this of course accomplished by the script. Now in case this script is run twice on the same day, instead of overwriting the existing file on remote Host B this script has to identify that a version already exists on Host B and instead of overwriting it, has to append the timestamp on the file being copied by let's say "1" and hence copy it as a different file.
For example, if
foo.txt already exists on Remote Host B, the script that's run from Host A should rename the file to
foo.txt.1 and copy it onto the same path on remote host B.
Since it's only one file I am fine using SCP over rsync.