move files without overwriting files
Hi,
i'd like to move logfiles to a backup location.
The backup-files looks like log<YYYYYMMDD>.gz
YYYY .. year, MM month DD date, created by logrotate
It can happen, that there will be more than one file created with the same name (same day)
So the first file is moved to backup location, ok.
But a second one will just overwrite the first one.
i tried
mv -b --backup-type=numbered log*.gz /backup
which works quite fine, gving me the old one as log<DATE>.gz~1~
log<DATE>.gz~2~ and so one, nicely lined up.
But this disrupts the original extension (.gz)
What i would like to have is something like
log<DATE>-<n>.gz, with n = 1..
So the first backuped file should be named log<DATE>.gz (just moved)
if a second arrives at backup-location it should be renamed to
log<DATE>-1.gz and the new one should have the name
log<DATE>-2.gz
Any good (short) ideas ?
Thanks
Robert
|