Search This Blog

Monday 14 October 2013

Perl script for Database backup


#Configuration params
$host = 'localhost';
$user = 'username';
$pass = 'password';
$database = 'dbname';
$backup_dir = '/home/username/backup/db_backup';
$file_prefix = 'database_backup_';

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

`mysqldump --host=$host --user=$user --pass=$pass  $database | bzip2 -c > $backup_dir/$file_prefix$database$date.sql.bz2`;


No comments:

Post a Comment