Rsync + renaming the copied files

file-copyrenamersync

Is it possible to change the name of the destination file (add some timestamp as a prefix) when copy is done by rsync ?

For example, I can use the following command to change the name of the destination file using suffix:

rsync --append  -arzvv --backup --suffix='_2015_09_10' /path/to/src/file /path/to/dst

But I would like to attach the time stamp as a prefix, so in the destination we will have some thing like: 2015_09_10_file instead of file_2015_09_10.

Best Answer

Actually you can, but kind of hacky.. and only as suffix.

As you have read in the comments, --suffix is for backups of overwritten files. So you rsync the same files from source to destination, kind of forcing rsync to overwrite (-I) - but only if the source file is (-u) newer (which it never is) and using the -b, --backup option and define a backup directory and a suffix.

rsync -Iu --backup --suffix='_2015_09_10' --backup-dir=/path/to/dst /path/to/src/file /path/to/src/file

Related Question