Search This Blog

Monday, 14 October 2013

Perl script for documents backup

#!/usr/bin/perl

# Configuration params
$backup_dir = '/home/username/public_html';
$file_prefix = 'doc_backup_';

# Get the timestamp for today
$date = `date "+%Y%m%d"`;
chomp($date);

chdir('/home/username/backup/doc_backup') ;

`tar -cv -f $file_prefix$date.tar $backup_dir`;

`bzip2 $file_prefix$date.tar`;

# Below line is used to remove the backups older than 5 days to free up the server space
system("find . -mtime +5 -type f -name  'doc_backup_*' -exec rm {} \\;");

No comments:

Post a Comment