LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 05: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, 09:03 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
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, 07:39 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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


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 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 03:06 PM
[SOLVED] automate copying files to multiple directories with log file for admin simransab Linux - Newbie 6 10-01-2009 08:09 PM
archiving rotated log files tjainsworth Linux - Security 4 07-12-2006 02:00 PM
Webserver Log Rotation, Stats and Archiving. graq Linux - Enterprise 1 02-24-2006 07:57 PM
update bsd tar for archiving jyoti100in *BSD 2 11-02-2005 04:46 PM

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

All times are GMT -5. The time now is 05:20 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration