LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices



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

Rep: Reputation: 0
Lightbulb 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
 
Old 04-11-2008, 05:01 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,028
Blog Entries: 5

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
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.
 
  


Reply


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 06:10 PM.

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