- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ideas on how to archive a log that cant be cleared...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 06:50 AM
08-31-2004 06:50 AM
ideas on how to archive a log that cant be cleared...
I am running into a jam here.
I have a log lets call it log.log for an application that is running 24/7. Of course the log logs live.
Now the issue is that I need to archive the log every 1 - 4 hours. But I can not clear out the live log.
Here is what i was running everyhour.
for SWITCHID in 1 2
do
cd /var/apps/log
cd $SWITCHID
nice -n 3 tar -cvf - log.log |nice -n 3 gzip | nice -n 3 remsh lv_a
rchive -l archive "cat > /archive/dbsvr1/$SWITCHID/logs-`date +%Y%m%d.%H%M`.tar.
gz"
sed 'd' log.log > log.log
cd ..
done
But it clears out log.log every hour. And I was asked not to clear out log.log but archive every hour.
Is there a good way to do this?
Thanks
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 07:03 AM
08-31-2004 07:03 AM
Re: ideas on how to archive a log that cant be cleared...
If the requirement is to just archive the additional entries in that log in the hour since the last archive without clearing it, then you could probably use the diff command for that. Have an offline copy of the log from the previous hour, make copy of active log (to avoid it changing between comparison and copy to offline version), do diff to the hourly archive, then rotate the offline logs to use in comparison the next hour.
Is that close to what you're trying to accomplish?
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 07:18 AM
08-31-2004 07:18 AM
Re: ideas on how to archive a log that cant be cleared...
ARCHIVE_TIME=$(date +%C%y%m%d%H%M)
cp logfile logfile.${ARCHIVE_TIME}cat /dev/null > logfile
You may want to compress the archive.
either
gzip logfile.${ARCHIVE_TIME}
or
compress logfile.${ARCHIVE_TIME}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 07:43 AM
08-31-2004 07:43 AM
Re: ideas on how to archive a log that cant be cleared...
If the log file is write intensive it will be difficult not to miss data.
As noted
1. Make a copy.
then
2. wc the copy and only delete those lines 1,X
from the active file.
Hope to see a better solution here.
Best of luck.
regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 10:35 AM
08-31-2004 10:35 AM
Re: ideas on how to archive a log that cant be cleared...
#checkpoint the file
print "Checkpoint for archiving ..." >> log.log
#now you want to archive the data between the
#last two checkpoints
#use awk, grep, perl to get the line numbers
#of the last two checkpoints
firstCheck=#checkpoint 2nd to the end of log.log
lastCheck=#last checkpoint in file
#if you don't want the checkpoint lines
firstCheck= firstCheck +1
lastCheck=lastCheck -1
#then use awk, sed, perl to get those line
# to your archive
sed "firstCheck,lastCheck p" > archive.log
I haven't done all the details put I'm sure it won't be to hard to complete if your interesting in using this method
myself I won't suggest keeping a log file without ever clearing it. if the application stays up long enough your going to fill up your disk space. (I hope your log is on a seperate file system from /var) and as the file size increases your performance is going to decrease. just how much is hard to say.
i'd suggest doing something like this
#copy log file
cp log.log log.bck
#do your archiving, compressing, backup to tape, etc
#if all that completed successfully
#get number of lines in log.bck
numLines=$(awk 'END {print NR;}')
#use ex, perl to to delete numLines from the begining of log.log
ex -s +"$numLines dd | wq!" log.log
rm log.bck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2004 07:10 PM
08-31-2004 07:10 PM
Re: ideas on how to archive a log that cant be cleared...
NUMLINES=$(cat log.log | wc -l)
OLDNL=0$(cat lastcheckpoint)
if [ $NUMLINES -gt $OLDNL ]
then
awk -v NL=$NUMLINES -v ONL=$OLDNL '
NR>ONL && NR <= NUMLINES { print }' log.log >>archive
elif [ $NUMLINES -eq $OLDNL ]
then
: # No new logging
else
head -$NUMLINES log.log >> archive
fi
echo $NUMLINES > lastcheckpoint