LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2011, 04:37 AM   #1
profi81
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Rep: Reputation: 0
How to automate archiving of log files using tar?


i would need help ,
i need to tar this logs, but i dont how to make it simplier to me. Everyday there are created this five logs. I need to make five tar files from every day from this files at the end of the month
for example
wlp-process_dump.log.tar.gz ( will contain every wlp-process_dump.log from this month )
wlp-cxf.log.tar.gz
wlp-jamon.log.tar.gz
wlp-refresher.log.tar.gz
wlp.log.tar.gz

33819 Mar 21 19:20 wlp-process_dump.log.2011-03-21
5144882 Mar 21 23:52 wlp-cxf.log.2011-03-21
1106593 Mar 21 23:59 wlp-jamon.log.2011-03-21
2192832 Mar 21 23:59 wlp-refresher.log.2011-03-21
2405037 Mar 21 23:59 wlp.log.2011-03-21


till now i have tar it manualy ( copied every file )

Thanks in advance
 
Old 03-29-2011, 08:03 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
How about something like this?
Code:
#!/bin/sh
input=/home/casper/logdir/
output=/home/casper/TEMP/
logfile=""
tempdir=`pwd`
cd $input
for filename in *
do
  logfile=$output$filename".tar.gz"
  tar -cvzpf $logfile $filename
done
cd $tempdir
I coded it so you can run it from any directory, and it will tar the log files located in the locations in the script. You just need to modify the directories where the log files are located. Hope this helps, and let me know if it does what you need it to do or not.

Cheers,

Josh
 
Old 03-29-2011, 06:39 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You could use logrotate to not only rotate new log files eg each day, but to also tar & gzip the old files automatically.
http://linux.die.net/man/8/logrotate
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] archiving log files chandkur Linux - Newbie 28 03-01-2011 02:06 PM
[SOLVED] automate copying files to multiple directories with log file for admin simransab Linux - Newbie 6 10-01-2009 07:09 PM
archiving rotated log files tjainsworth Linux - Security 4 07-12-2006 01:00 PM
Webserver Log Rotation, Stats and Archiving. graq Linux - Enterprise 1 02-24-2006 06:57 PM
update bsd tar for archiving jyoti100in *BSD 2 11-02-2005 03:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 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
Open Source Consulting | Domain Registration