I believe that you will not be able to do this with scp alone. Your best bet would be to use rsync over ssh with something like the following additional options:
--backup --suffix=_`date +"%m%d%Y_%H%M"` --backup-dir=DIR
Some relevant sections of the man pages for rsync:
-b, --backup
With this option, preexisting destination files are renamed as each file is
transferred or deleted. You can control where the backup file goes and what
(if any) suffix gets appended using the --backup-dir and --suffix options.
--suffix=SUFFIX
This option allows you to override the default backup suffix used with the
--backup (-b) option. The default suffix is a ~ if no --backup-dir was speci-
fied, otherwise it is an empty string.
--backup-dir=DIR
In combination with the --backup option, this tells rsync to store all backups
in the specified directory on the receiving side. This can be used for incre-
mental backups. You can additionally specify a backup suffix using the --suf-
fix option (otherwise the files backed up in the specified directory will keep
their original filenames).
This should be able to be massaged to fit your needs. Below is a basic test, you will doubtless have other options including ssh, to add in:
rsync -av --backup --suffix=_`date +"%m%d%Y_%H%M"` --backup-dir=backup test1/ test2/
So with this in place:
- A file is transferred from
test1 to test2
- If this file already exists on
test2, but the transferred file is newer, the 'remote' file is updated, and importantly:
- The original file on
test2 is backed up to test2/backup with an incremental date and time suffix added
Pretty cool? And I suspect exactly what you are looking for. Note that I have used a relative path for the backup directory, an absolute path can also be used...