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

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.

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..

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';
}

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.

#!/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;

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..