Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-29-2011, 05:37 AM   #1
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 )

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
LQ Guru
Registered: Apr 2005
Posts: 5,818

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
How about something like this?
cd $input
for filename in *
  tar -cvzpf $logfile $filename
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.


Old 03-29-2011, 07:39 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,569

Rep: Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426
You could use logrotate to not only rotate new log files eg each day, but to also tar & gzip the old files automatically.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:01 PM.

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