Back up log files using tar


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Back up log files using tar
# 1  
Old 05-28-2014
Back up log files using tar

Hi,
I need some help writing a perl script to tar all log file to a directory and then delete the log files. Can some one please help me on this? I m Not very good with perl scripting...

Thanks

KK
# 2  
Old 05-28-2014
Quote:
Originally Posted by karthikk0508
Hi,
I need some help writing a perl script to tar all log file to a directory and then delete the log files. Can some one please help me on this? I m Not very good with perl scripting...

Thanks

KK
C'mon, karthikk, certainly you can do better than this. Show us a minimal effort.
It really doesn't take much. People, here are willing to help you, but not if you don't show even an iota of effort.
Just start searching. The web is full of examples, since your case is not that unique.
# 3  
Old 05-28-2014
Hi Aia,

I did write a piece of code but not quite confident with it as I m not entirely into coding...but nt really sure if I had put it together exactly right..


Code:
sub take_backup

{
	$dir= 'cd /apps/XEServer';
       $cmd= 'tar -cvf backup/backup_$(date +%y%m%d).tar  *.log';
}

sub delete_logs
{
 $dir= ' cd /apps/XEServer'; 
 $cmd= 'rm *.log';
}


Last edited by Don Cragun; 05-29-2014 at 12:46 AM.. Reason: Add CODE tags.
# 4  
Old 05-28-2014
Quote:
Originally Posted by karthikk0508
Hi Aia,

I did write a piece of code but not quite confident with it as I m not entirely into coding...but nt really sure if I had put it together exactly right..
[...]
It is troublesome to solicit and use other people's code without having knowledge of what it is.

Unfortunately, there was not much in what you posted to work with, it just helped me to use the specific path and timestamp to hard code in my snippet.

You have to have installed the perl module Archive::Tar from CPAN or from your distro repo.

Code:
#!/usr/bin/perl

# Author: Aia
# Date: 5/28/2014
# perl_tar.pl
# No guaranties that this will work or that it will not destroy your data

use strict;
use warnings;
use Archive::Tar;

my @file_list = glob "/apps/XEServer/*.log";
my $dir = "/apps/XEServer";

my @now = localtime;
my $date = sprintf("%02d%02d%02d", $now[5]+1900, $now[4]+1, $now[3]);

my $tar_job = Archive::Tar->new();
$tar_job->add_files(@file_list);
$tar_job->write("backup/backup_$date.tar");

# un-comment this line below if you feel confident and want to delete any original file used to make the tar
#unlink @files_list;


Last edited by Aia; 05-28-2014 at 10:55 PM..
# 5  
Old 05-29-2014
Thank you Aia....I just used some basic perl variable declarationsf rom one of our scripts. just delete XE Server log files..Thank you so much for helping me on this...appreciate your help..will try out these steps..Or i could use the one line command to tar and remove in a shell command..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

2. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

3. UNIX for Advanced & Expert Users

Back up of recent modified files

Hi, I want to identify the files that are recently modified or with in a specified period (15 Days) in UNIX box. After identifying the files should be transferred to windows machine through FTP. The files should be overwritten in windows if it is already available. Please help... (1 Reply)
Discussion started by: lathish
1 Replies

4. UNIX for Dummies Questions & Answers

how to get my files back..

hi all using unix (hp-ux) i created patches Directory under /tmp ... inside the /tmp, i fired these commands: # mv patch_file1 /patches # mv patch_file2 /patches there was no error then i realized that this command will move the files to patches Dir on the root which was NOT... (2 Replies)
Discussion started by: neemoze
2 Replies

5. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

6. Shell Programming and Scripting

Script to tar up old log files

Hell All! I need help writing a script for my job. I never really wrote alot of scripts but I guess it a first time for everything. I need to write a simple script that goes out to our log file directory on our servers and tar and compress them. I need to know how to add an date time stamp to tell... (5 Replies)
Discussion started by: aojmoj
5 Replies

7. Filesystems, Disks and Memory

Can I back up all the files I work with each day using tar?

Can I back up all the files I work with each day using tar? (2 Replies)
Discussion started by: jo calamine
2 Replies

8. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies

9. UNIX for Dummies Questions & Answers

tar to tape and back

Howdy, I'm trying to tar some directories to tape and then extract them from tape on another machine. I was hoping someone could help me with the syntax of the tar commands. Both machines are running Solaris 8. Need to get all files and directories under the following: ... (6 Replies)
Discussion started by: pmetal
6 Replies

10. UNIX for Dummies Questions & Answers

Bring back removed files

Dear People I have removed some of my files and directories( by using rm and rmdir commands) by mistake. I wish to bring them back. How is it possible?( I am using solaris 2.6) best regards Reza Nazarian:( (2 Replies)
Discussion started by: Reza Nazarian
2 Replies
Login or Register to Ask a Question