jojo's blog--快乐忧伤都与你同在
为梦想而来,为自由而生。 性情若水,风起水兴,风息水止,故时而激荡,时又清平……
posts - 11,  comments - 30,  trackbacks - 0
#!/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

只有注册用户登录后才能发表评论。


网站导航:
 

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿(6)

随笔档案

文章分类

文章档案

新闻分类

新闻档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜