#!/usr/bin/perl -w
#
# Created by: JOJO
# Created Date: 10 June 2009
# Desc: To backup ps corresponding databases for Point System
#
use strict;
use DateTime;
main();
sub main {
# Get date
my $dt = DateTime->now;
my $year = $dt->year;
my $month = sprintf "%02d", $dt->month;
my $day = sprintf "%02d", $dt->day;
my $ts = $dt->epoch();
`mkdir /home/mdrop/PSBackupDB` if (! -d "/home/mdrop/PSBackupDB" );
`mkdir /home/mdrop/PSBackupDBLog` if (! -d "/home/mdrop/PSBackupDBLog" );
`mkdir /home/mdrop/PSBackupDB/$year$month` if (! -d "/home/mdrop/PSBackupDB/$year$month" );
my $dbpath = "/home/mdrop/PSBackupDB";
my $logpath = "/home/mdrop/PSBackupDBLog";
my $backlog = "$logpath/backup.log";
my $user = "root";
my $pwd = "password";
#open log file for writing, append purpose
open(MYLOGFILE, ">>$backlog");
# Export ps db to dump file
print MYLOGFILE "mysqldump -u$user -p$pwd pointsystem_sd at $dt"n";
!`mysqldump -u$user -p$pwd pointsystem_sd > $dbpath/pointsystem_sd.sql-$year$month$day` || die print "Cannot export pointsystem_sd database."n" >> $backlog;
print MYLOGFILE "mysqldump -u$user -p$pwd pointsystem_off at $dt"n";
!`mysqldump -u$user -p$pwd pointsystem_off > $dbpath/pointsystem_off.sql-$year$month$day` || die print "Cannot export pointsystem_off database."n" >> $backlog;
print MYLOGFILE "mysqldump -u$user -p$pwd pointsys_log_db at $dt"n";
!`mysqldump -u$user -p$pwd pointsys_log_db > $dbpath/pointsys_log_db.sql-$year$month$day` || die print "Cannot export pointsys_log_db database."n" >> $backlog;
print MYLOGFILE "mysqldump -u$user -p$pwd glassfishtimer at $dt"n";
!`mysqldump -u$user -p$pwd glassfishtimer > $dbpath/glassfishtimer.sql-$year$month$day` || die print "Cannot export glassfishtimer database."n" >> $backlog;
print MYLOGFILE "mysqldump -u$user -p$pwd obcart at $dt"n";
!`mysqldump -u$user -p$pwd obcart > $dbpath/obcart.sql-$year$month$day` || die print "Cannot export obcart database."n" >> $backlog;
#gzip ps db backup file
!`cd $dbpath; gzip pointsystem_sd.sql-$year$month$day` || die print "Cannot gzip pointsystem_sd.sql-$year$month$day file."n";
!`cd $dbpath; gzip pointsystem_off.sql-$year$month$day` || die print "Cannot gzip pointsystem_off.sql-$year$month$day file."n";
!`cd $dbpath; gzip pointsys_log_db.sql-$year$month$day` || die print "Cannot gzip pointsys_log_db.sql-$year$month$day file."n" ;
!`cd $dbpath; gzip glassfishtimer.sql-$year$month$day` || die print "Cannot gzip glassfishtimer.sql-$year$month$day file."n";
!`cd $dbpath; gzip obcart.sql-$year$month$day`|| die print "Cannot gzip obcart.sql-$year$month$day database."n";
#move ps db backup sql file to archive folder
!`mv $dbpath/pointsystem_sd.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsystem_sd.sql-$year$month$day.gz file."n";
!`mv $dbpath/pointsystem_off.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsystem_off.sql-$year$month$day.gz file."n";
!`mv $dbpath/pointsys_log_db.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move pointsys_log_db.sql-$year$month$day.gz file."n";
!`mv $dbpath/glassfishtimer.sql-$year$month$day.gz $dbpath/$year$month` || die print "Cannot move glassfishtimer.sql-$year$month$day.gz file."n";
!`mv $dbpath/obcart.sql-$year$month$day.gz $dbpath/$year$month`|| die print "Cannot move glassfishtimer.sql-$year$month$day.gz file."n";
}
posted on 2009-06-11 14:17
Blog of JoJo 阅读(193)
评论(0) 编辑 收藏 所属分类:
每日一记 、
My Script