Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-11-2008, 02:58 PM   #1
LQ Newbie
Registered: Jun 2006
Posts: 26

Rep: Reputation: 0
Lightbulb move files without overwriting files


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

Any good (short) ideas ?

Old 04-11-2008, 05:01 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,274
Blog Entries: 10

Rep: Reputation: 847Reputation: 847Reputation: 847Reputation: 847Reputation: 847Reputation: 847Reputation: 847
Have a look at the rsync command. Specifically it has a -b (--backup) flag that will likely do the trick.

Haven't used that particular flag but rsync is something I've used many other options on for similar purposes - duplicating files from one location to another. Note that rsync allows for copies between machines but doesn't require that (you can do copies between directories on a single machine).

Type "man rsync" for more details.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 01:01 PM
upload using FTP WITHOUT overwriting existing/newer files HyperBlade Linux - Software 1 04-06-2008 12:10 AM
How do I move files without overwrite exitng files? nadavvin Linux - General 10 11-03-2006 03:49 PM
Please Help! Ubuntu keeps overwriting system files! ckr Ubuntu 2 07-13-2006 06:51 PM
php/ftp overwriting files.. prob. collen Programming 1 03-14-2005 05:56 AM

All times are GMT -5. The time now is 04:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration