LinuxQuestions.org
Help answer threads with 0 replies.
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 09-18-2012, 04:55 AM   #1
LittleMaster
Member
 
Registered: Jun 2012
Posts: 122
Blog Entries: 1

Rep: Reputation: Disabled
How to compress and move log older than 30 days from one folder to another


Hi

How can i compress and move the logs from one folder to another
 
Old 09-18-2012, 05:17 AM   #2
ynodelman
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Rep: Reputation: 1
Wink Find command, or logrotate utility

That is easy,

Google for find command examples on searching for files older then 30 days:

find /storage/current/dbdumps/ -type f -mtime +30 -print | xargs -I {} mv {} /storage/archive/dbdumps

or logrotate (build-in Linux utility) which does all of it for you including clean-up :-)
 
1 members found this post helpful.
Old 09-19-2012, 11:33 PM   #3
LittleMaster
Member
 
Registered: Jun 2012
Posts: 122

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
These command find and move the complete log .But im looking for a command to compress and move the logs from sorce - destination in tar.gz format

find /storage/current/dbdumps/*.logs -type f -mtime +30 -print | xargs -I {} mv {} /storage/archive/dbdumps/*.logs
 
1 members found this post helpful.
Old 09-19-2012, 11:49 PM   #4
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hi LittleMaster,

Here is a script I use to take the backup of my servers' logs monthly. You can take a look at this script and can configure according to your need:

Code:
#!/bin/bash
ssh <dest. server ip> 'mkdir /logs/Linux_Server_Logs/proxy_logs/$(date -d yesterday +%b-%Y)'

#### No need for exit since the SSH session terminates after the command completion ####

rsync -avze ssh /var/log/* root@<dest. server ip>:/logs/Linux_Server_Logs/proxy_logs/$(date -d yesterday +%b-%Y)/

#### cd /root/ eliminated and put in the tar command ####
#### Two commands combined into one so they execute one after an other if the first one is successful. ####

ssh <dest. server ip> 'cd /logs/Linux_Server_Logs/proxy_logs && tar -zvcf $(date -d yesterday +%b-%Y).tar.gz $(date -d yesterday +%b-%Y) && rm -rf $(date -d yesterday +%b-%Y)'
This script first login to destination server ip and create a directory of previous month's date name.
After that rsync command copies the mentioned logs from source to destination path.
Then client again ssh to server ip to compress the logs directory.

Good Luck!
 
Old 09-19-2012, 11:59 PM   #5
LittleMaster
Member
 
Registered: Jun 2012
Posts: 122

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Hi
In your script you have been backuping up the data to remote server. Im my server filesystem /data utilised 100 % of its utility and i have root partition with just 5 % utilised .So im trying out to find the log of /data and compress in tar .gz format to /root filesystem


find /data/*.logs -type f -mtime +30 -print | xargs -I {} mv {} -exec .tar.gz /root/logbkup/$date.tar.gz


Im trying out the above command But it never works.thanks for sharing your script really it help when i could take the log backup to remote destination server
 
Old 09-20-2012, 12:16 AM   #6
jsaravana87
Member
 
Registered: Aug 2011
Location: Chennai,India
Distribution: Redhat,Centos,Ubuntu,Dedian
Posts: 558
Blog Entries: 5

Rep: Reputation: Disabled
Hi

Little Master these the script i have been using to backup my logs to remote Nas server. I had just modfied to your need

#!/bin/bash

#Script -Purpose:Backup script
# Exits with zero if no error.


# Step -1 Function to archieve file using date and time

date=`/bin/date "+%Y.%m.%d.%H.%M.%S"`


# Step -2 Function to create folder on /root/logs with Timestamp

mkdir -p /root/logs/$date

# Step -3 Function to find & move logs from /data to /root/logs


find /data/ -type f -iname *.logs -mtime +30 -print | xargs -I {} mv {} /root/logs/$date

#Step -4 Function to compress the log Backup Content

tar -cvzf /root/log/$date /root/logarchive/$date.tar.gz

#Step -5 Function to remove the Log


rm -rf /root/log/*


#Step -4 Function to Print the logs Backup status

echo "$(date) log Backuped successfully ">>/root/logs/logbackup-status-$date.log

#Step -5 Function to call the Mail trigger to user

mailid= $@gmail.com

#Step -5 Function to trigger mail after log backup status

mail -s '$(date) Logs Moved Successfully $(hostname) - Successful' $mailid

Last edited by jsaravana87; 09-20-2012 at 12:36 AM.
 
Old 09-20-2012, 12:30 AM   #7
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
LittleMaster,

The script given by arun is the correct one. You can try out this.
 
  


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] Script: find, compress, remove original files, older than x days? blacklion Linux - General 5 02-27-2012 10:22 AM
Need to move folders older than 5 days to a bad up directory calicowboy54 Linux - Newbie 4 01-15-2012 09:27 PM
need command to move folders older than 4 days to a bad up directory calicowboy54 Linux - General 4 01-15-2012 09:24 PM
script to compress a directory and then delete older than 7 days replica88 Linux - General 3 02-03-2010 07:21 PM
How to move files older than 30 days gfem AIX 8 11-08-2006 04:58 AM

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

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