Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit78eed96

Browse files
author
t.katsumata1122
committed
revised for pg_rman1.2.2
git-svn-id:http://pg-rman.googlecode.com/svn/trunk@48 182aca00-e38e-11de-a668-6fd11605f5ce
1 parentae6c0e0 commit78eed96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1940
-1615
lines changed

‎COPYRIGHT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
1+
Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
22

33
Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
44
Portions Copyright (c) 1994, The Regents of the University of California

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ OBJS = $(SRCS:.c=.o)
2424
PG_CPPFLAGS = -I$(libpq_srcdir)
2525
PG_LIBS =$(libpq_pgport)
2626

27-
REGRESS = option init show_validate backup_restore snapshot
27+
REGRESS = option init show_validate backup_restore
2828

2929
ifdefUSE_PGXS
3030
PG_CONFIG = pg_config

‎SPECS/pg_rman90.spec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Set general information for pg_rman.
1010
Summary: Backup and Recovery Tool for PostgreSQL
1111
Name: pg_rman
12-
Version: 1.2.1
12+
Version: 1.2.0
1313
Release: 1%{?dist}
1414
License: BSD
1515
Group: Applications/Databases
@@ -58,7 +58,6 @@ rm -rf %{buildroot}
5858

5959
# History of pg_rman.
6060
%changelog
61-
* Mon Jun 20 2011 - Tomonari Katsumata <t.katsumata1122@gmail.com> 1.2.1-1
6261
* Wed Nov 10 2010 - NTT OSS Center <tomonari.katsumata@oss.ntt.co.jp> 1.2.0-1
6362
* Wed Dec 9 2009 - NTT OSS Center <itagaki.takahiro@oss.ntt.co.jp> 1.1.1-1
6463
-Initial cut for 1.1.1

‎backup.c

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* backup.c: backup DB cluster, archived WAL, serverlog.
44
*
5-
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
5+
* Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
66
*
77
*-------------------------------------------------------------------------
88
*/
@@ -41,6 +41,7 @@ static void pg_start_backup(const char *label, bool smooth, pgBackup *backup);
4141
staticvoidpg_stop_backup(pgBackup*backup);
4242
staticvoidpg_switch_xlog(pgBackup*backup);
4343
staticvoidget_lsn(PGresult*res,TimeLineID*timeline,XLogRecPtr*lsn);
44+
staticvoidget_xid(PGresult*res,uint32*xid);
4445

4546
staticvoiddelete_arclog_link(void);
4647
staticvoiddelete_online_wal_backup(void);
@@ -75,8 +76,26 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
7576
XLogRecPtr*lsn=NULL;
7677
charprev_file_txt[MAXPGPATH];/* path of the previous backup list file */
7778

78-
if (!HAVE_DATABASE(&current))
79-
returnNULL;
79+
if (!HAVE_DATABASE(&current)) {
80+
/* check if arclog backup. if arclog backup and no suitable full backup, */
81+
/* take full backup instead. */
82+
if (HAVE_ARCLOG(&current)) {
83+
pgBackup*prev_backup;
84+
85+
/* find last completed database backup */
86+
prev_backup=catalog_get_last_data_backup(backup_list);
87+
if (prev_backup==NULL)
88+
{
89+
elog(ERROR_SYSTEM,_("There is indeed a full backup but it is not validated."
90+
"So I can't take any arclog backup."
91+
"Please validate it and retry."));
92+
///elog(INFO, _("no previous full backup, performing a full backup instead"));
93+
///current.backup_mode = BACKUP_MODE_FULL;
94+
}
95+
}
96+
else
97+
returnNULL;
98+
}
8099

81100
elog(INFO,_("database backup start"));
82101

@@ -89,6 +108,16 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
89108
strncat(label," with pg_rman",lengthof(label));
90109
pg_start_backup(label,smooth_checkpoint,&current);
91110

111+
/* If backup_label does not exist in $PGDATA, stop taking backup */
112+
snprintf(path,lengthof(path),"%s/backup_label",pgdata);
113+
make_native_path(path);
114+
if (!fileExists(path)) {
115+
if (verbose)
116+
printf(_("backup_label does not exist, stop backup\n"));
117+
pg_stop_backup(NULL);
118+
elog(ERROR_SYSTEM,_("backup_label does not exist in PGDATA."));
119+
}
120+
92121
/*
93122
* list directories and symbolic links with the physical path to make
94123
* mkdirs.sh
@@ -127,10 +156,13 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
127156

128157
/* find last completed database backup */
129158
prev_backup=catalog_get_last_data_backup(backup_list);
130-
if (prev_backup==NULL)
159+
if (prev_backup==NULL||prev_backup->tli!=current.tli)
131160
{
132-
elog(INFO,_("no previous full backup, do a full backup instead"));
133-
current.backup_mode=BACKUP_MODE_FULL;
161+
elog(ERROR_SYSTEM,_("There is indeed a full backup but it is not validated."
162+
"So I can't take any incremental backup."
163+
"Please validate it and retry."));
164+
///elog(INFO, _("no previous full backup, performing a full backup instead"));
165+
///current.backup_mode = BACKUP_MODE_FULL;
134166
}
135167
else
136168
{
@@ -440,7 +472,7 @@ do_backup_arclog(parray *backup_list)
440472
*/
441473
prev_backup=catalog_get_last_arclog_backup(backup_list);
442474
if (verbose&&prev_backup==NULL)
443-
printf(_("no previous full backup,do a full backup instead\n"));
475+
printf(_("no previous full backup,performing a full backup instead\n"));
444476

445477
if (prev_backup)
446478
{
@@ -564,7 +596,7 @@ do_backup_srvlog(parray *backup_list)
564596
*/
565597
prev_backup=catalog_get_last_srvlog_backup(backup_list);
566598
if (verbose&&prev_backup==NULL)
567-
printf(_("no previous full backup,do a full backup instead\n"));
599+
printf(_("no previous full backup,performing a full backup instead\n"));
568600

569601
if (prev_backup)
570602
{
@@ -695,6 +727,8 @@ do_backup(bool smooth_checkpoint,
695727
current.write_bytes=0;/* write_bytes is valid always */
696728
current.block_size=BLCKSZ;
697729
current.wal_block_size=XLOG_BLCKSZ;
730+
current.recovery_xid=0;
731+
current.recovery_time= (time_t)0;
698732

699733
/* create backup directory and backup.ini */
700734
if (!check)
@@ -708,6 +742,9 @@ do_backup(bool smooth_checkpoint,
708742

709743
/* get list of backups already taken */
710744
backup_list=catalog_get_backup_list(NULL);
745+
if(!backup_list){
746+
elog(ERROR_SYSTEM,_("can't process any more."));
747+
}
711748

712749
/* set the error processing function for the backup process */
713750
pgut_atexit_push(backup_cleanup,NULL);
@@ -893,6 +930,12 @@ wait_for_archive(pgBackup *backup, const char *sql)
893930
elog(LOG,"%s() wait for %s",__FUNCTION__,ready_path);
894931

895932
PQclear(res);
933+
934+
res=execute(TXID_CURRENT_SQL,0,NULL);
935+
if(backup!=NULL){
936+
get_xid(res,&backup->recovery_xid);
937+
backup->recovery_time=time(NULL);
938+
}
896939
disconnect();
897940

898941
/* wait until switched WAL is archived */
@@ -960,6 +1003,26 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
9601003
lsn->xrecoff+=off_upper <<24;
9611004
}
9621005

1006+
/*
1007+
* Get XID from result of txid_current() after pg_stop_backup().
1008+
*/
1009+
staticvoid
1010+
get_xid(PGresult*res,uint32*xid)
1011+
{
1012+
if(res==NULL||PQntuples(res)!=1||PQnfields(res)!=1)
1013+
elog(ERROR_PG_COMMAND,
1014+
_("result of txid_current() is invalid: %s"),
1015+
PQerrorMessage(connection));
1016+
1017+
if(sscanf(PQgetvalue(res,0,0),"%u",xid)!=1)
1018+
{
1019+
elog(ERROR_PG_COMMAND,
1020+
_("result of txid_current() is invalid: %s"),
1021+
PQerrorMessage(connection));
1022+
}
1023+
elog(LOG,"%s():%s",__FUNCTION__,PQgetvalue(res,0,0));
1024+
}
1025+
9631026
/*
9641027
* Return true if the path is a existing regular file.
9651028
*/
@@ -1055,6 +1118,11 @@ backup_files(const char *from_root,
10551118

10561119
pgFile*file= (pgFile*)parray_get(files,i);
10571120

1121+
/* If current time is rewinded, abort this backup. */
1122+
if(tv.tv_sec<file->mtime){
1123+
elog(ERROR_SYSTEM,_("current time may be rewound. Please retry with full backup mode."));
1124+
}
1125+
10581126
/* check for interrupt */
10591127
if (interrupted)
10601128
elog(ERROR_INTERRUPTED,_("interrupted during backup"));
@@ -1101,8 +1169,9 @@ backup_files(const char *from_root,
11011169
chardirpath[MAXPGPATH];
11021170

11031171
join_path_components(dirpath,to_root,JoinPathEnd(file->path,from_root));
1104-
if (!check)
1172+
if (!check){
11051173
dir_create_dir(dirpath,DIR_PERMISSION);
1174+
}
11061175
if (verbose)
11071176
printf(_("directory\n"));
11081177
}
@@ -1143,7 +1212,7 @@ backup_files(const char *from_root,
11431212
prev_file=*p;
11441213
}
11451214

1146-
if (prev_file&&prev_file->mtime>=file->mtime)
1215+
if (prev_file&&prev_file->mtime==file->mtime)
11471216
{
11481217
/* record as skipped file in file_xxx.txt */
11491218
file->write_size=BYTES_INVALID;
@@ -1158,7 +1227,8 @@ backup_files(const char *from_root,
11581227
* file should contain all modifications at the clock of mtime.
11591228
* timer resolution of ext3 file system is one second.
11601229
*/
1161-
if (tv.tv_sec <=file->mtime)
1230+
1231+
if (tv.tv_sec==file->mtime)
11621232
{
11631233
/* update time and recheck */
11641234
gettimeofday(&tv,NULL);

‎catalog.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* catalog.c: backup catalog opration
44
*
5-
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
5+
* Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
66
*
77
*-------------------------------------------------------------------------
88
*/
@@ -364,6 +364,12 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
364364
time2iso(timestamp,lengthof(timestamp),backup->end_time);
365365
fprintf(out,"END_TIME='%s'\n",timestamp);
366366
}
367+
fprintf(out,"RECOVERY_XID=%u\n",backup->recovery_xid);
368+
if (backup->recovery_time>0)
369+
{
370+
time2iso(timestamp,lengthof(timestamp),backup->recovery_time);
371+
fprintf(out,"RECOVERY_TIME='%s'\n",timestamp);
372+
}
367373

368374
if (backup->total_data_bytes!=BYTES_INVALID)
369375
fprintf(out,"TOTAL_DATA_BYTES="INT64_FORMAT"\n",
@@ -434,6 +440,8 @@ catalog_read_ini(const char *path)
434440
{'s',0,"stop-lsn",NULL,SOURCE_ENV },
435441
{'t',0,"start-time",NULL,SOURCE_ENV },
436442
{'t',0,"end-time",NULL,SOURCE_ENV },
443+
{'u',0,"recovery-xid",NULL,SOURCE_ENV },
444+
{'t',0,"recovery-time",NULL,SOURCE_ENV },
437445
{'I',0,"total-data-bytes",NULL,SOURCE_ENV },
438446
{'I',0,"read-data-bytes",NULL,SOURCE_ENV },
439447
{'I',0,"read-arclog-bytes",NULL,SOURCE_ENV },
@@ -445,6 +453,10 @@ catalog_read_ini(const char *path)
445453
{0 }
446454
};
447455

456+
if (access(path,F_OK)!=0){
457+
returnNULL;
458+
}
459+
448460
backup=pgut_new(pgBackup);
449461
catalog_init_config(backup);
450462

@@ -457,6 +469,8 @@ catalog_read_ini(const char *path)
457469
options[i++].var=&stop_lsn;
458470
options[i++].var=&backup->start_time;
459471
options[i++].var=&backup->end_time;
472+
options[i++].var=&backup->recovery_xid;
473+
options[i++].var=&backup->recovery_time;
460474
options[i++].var=&backup->total_data_bytes;
461475
options[i++].var=&backup->read_data_bytes;
462476
options[i++].var=&backup->read_arclog_bytes;
@@ -601,6 +615,8 @@ catalog_init_config(pgBackup *backup)
601615
backup->stop_lsn.xrecoff=0;
602616
backup->start_time= (time_t)0;
603617
backup->end_time= (time_t)0;
618+
backup->recovery_xid=0;
619+
backup->recovery_time= (time_t)0;
604620
backup->total_data_bytes=BYTES_INVALID;
605621
backup->read_data_bytes=BYTES_INVALID;
606622
backup->read_arclog_bytes=BYTES_INVALID;

‎clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* clean.c: cleanup backup files.
44
*
5-
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
5+
* Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
66
*
77
*-------------------------------------------------------------------------
88
*/

‎data.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* data.c: compress / uncompress data pages
44
*
5-
* Copyright (c) 2009-2010, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
5+
* Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
66
*
77
*-------------------------------------------------------------------------
88
*/
@@ -756,6 +756,14 @@ restore_data_file(const char *from_root,
756756
elog(ERROR_SYSTEM,_("can't change mode of \"%s\": %s"),to_path,
757757
strerror(errno_tmp));
758758
}
759+
//aaaif (chown(to_path, file->uid, file->gid) == -1)
760+
//aaa{
761+
//aaaint errno_tmp = errno;
762+
//aaafclose(in);
763+
//aaafclose(out);
764+
//aaaelog(ERROR_SYSTEM, _("can't change owner of \"%s\": %s"), to_path,
765+
//aaastrerror(errno_tmp));
766+
//aaa}
759767

760768
fclose(in);
761769
fclose(out);
@@ -992,6 +1000,14 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
9921000
elog(ERROR_SYSTEM,_("can't change mode of \"%s\": %s"),to_path,
9931001
strerror(errno_tmp));
9941002
}
1003+
//aaaif (chown(to_path, file->uid, file->gid) == -1)
1004+
//aaa{
1005+
//aaaerrno_tmp = errno;
1006+
//aaafclose(in);
1007+
//aaafclose(out);
1008+
//aaaelog(ERROR_SYSTEM, _("can't change owner of \"%s\": %s"), to_path,
1009+
//aaastrerror(errno_tmp));
1010+
//aaa}
9951011

9961012
fclose(in);
9971013
fclose(out);
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# configuration
2-
BACKUP_MODE=FULL
3-
WITH_SERVERLOG=NO
4-
COMPRESS_DATA=NO
5-
# result
6-
TIMELINEID=1
7-
START_LSN=0/0b40c800
8-
STOP_LSN=0/0b4c8020
9-
START_TIME='2009-05-31 17:05:53'
10-
END_TIME='2009-05-31 17:09:13'
11-
TOTAL_DATA_BYTES=1242102558
12-
READ_DATA_BYTES=1024
13-
READ_ARCLOG_BYTES=9223372036854775807
14-
READ_SRVLOG_BYTES=-1
15-
WRITE_BYTES=242102558
16-
BLOCK_SIZE=8192
17-
XLOG_BLOCK_SIZE=8192
18-
STATUS=DONE
1+
# configuration
2+
BACKUP_MODE=FULL
3+
WITH_SERVERLOG=NO
4+
COMPRESS_DATA=NO
5+
# result
6+
TIMELINEID=1
7+
START_LSN=0/0b40c800
8+
STOP_LSN=0/0b4c8020
9+
START_TIME='2009-05-31 17:05:53'
10+
END_TIME='2009-05-31 17:09:13'
11+
TOTAL_DATA_BYTES=1242102558
12+
READ_DATA_BYTES=1024
13+
READ_ARCLOG_BYTES=9223372036854775807
14+
READ_SRVLOG_BYTES=-1
15+
WRITE_BYTES=242102558
16+
BLOCK_SIZE=8192
17+
XLOG_BLOCK_SIZE=8192
18+
STATUS=DONE
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
PG_VERSION f 4 4277607361 0600 2009-08-06 18:40:18
1+
PG_VERSION f 4 4277607361 0600 2009-08-06 18:40:18

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp