[BUGS] scripting: moving/renaming log files

harry harry at woodward-clarke.com
Sun Nov 11 13:32:51 EST 2007


Hi JLM,

> as the subject suggests, i'd like to scp (and rename the files
> to name+date of creation into another directory and/or
> another:/directory/tree/some/where that would have to be
> created on teh fly.
> 

not -exactly- sure what you're asking here... but let me try and
guess :')

1 - you have some log files - e.g. /var/log/messages
2 - you would (after a logrotate) like to archive these so that the
"date" is encoded in the file name, but leaving the "filename" mostly
intact - thus "2007-11-11-messages"

Well, "date +%F" will give us the date portion ok. Now to copy/rename
the file with leaving the rest of it intact...

let's assume that we have the filename stored in our variable "files",
we can do something like this...

# cp /var/log/$files /mnt/backups/`date +%F`-$files

Now. the bit about "creation date" worries me a little. AFAIK, the FS
doesn't keep track of "creation date". There is 'file last
accessed' (atime), 'file contents last modified' (mtime) & 'file's inode
last changed' (ctime).

No "create" time.

Now, if you run this on a daily basis, then you can use date to give you
(say) yesterday's date "date +%F -d yesterday".

To do a number of files (e.g. all the files in /var/log) you could do
something like:

for files in $(ls /var/log); \
   do scp /var/log/$files /mnt/backups/`date +%F -d yesterday`-$files; \
done

further questions? just ask.

reg's,

.h

-- 
harry [at] woodward-clarke [dot] com
imago Dei in quolibet hominé inveniartur



More information about the BUGS mailing list