首先,对数据库在 file system level 做一个 backup (PostgreSQL 是首先用 pg_start_backup('label')命令,然后用 tar 直接 tar 整个 data 目录,假设命名为 base.tar, 然后 pg_stop_backup(); 结束热备。Oracle 首先是用 alter tablespace xxx begin backup, 然后直接 cp 数据文件);
然后,备份相关的配置文件(PostgreSQL 只需备份 postgresql.conf, pg_hba.conf, pg_ident.conf 就可以了,其实,前面的 tar 已经将这些文件备份了,Oracle 需要 alter database backup control file......);
#############################################################
# hotBackup.pl
# Use to hot backup the PostgreSQL database.
# Author:Seamus Dean
# Date:2005-04-11
##############################################################
sub mail_user()
{
my($msg) =@_;
open(MAIL,"|/bin/mail -s backup-result $receiver") or die("can not talk to:mail command.\n");
print MAIL $msg;
close(MAIL);
}
###################################
# tell psql begin our backup
###################################
&begin_backup();
###################################
# do tar
###################################
&do_backup();
####################################
# tell psql end backup
####################################
&end_backup();
####################################
# mail the user about the result
####################################
&mail_user("PostgreSQL backup successfully.");