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

Commit356ebd3

Browse files
committed
Add checksums database support.
1 parent6cb6b3a commit356ebd3

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

‎backup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ do_backup(pgBackupOption bkupopt)
461461
current.wal_block_size=XLOG_BLCKSZ;
462462
current.recovery_xid=0;
463463
current.recovery_time= (time_t)0;
464+
current.checksum_version=get_data_checksum_version(true);
464465

465466
/* create backup directory and backup.ini */
466467
if (!check)

‎catalog.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
329329
backup->data_bytes);
330330
fprintf(out,"BLOCK_SIZE=%u\n",backup->block_size);
331331
fprintf(out,"XLOG_BLOCK_SIZE=%u\n",backup->wal_block_size);
332+
fprintf(out,"CHECKSUM_VERSION=%u\n",backup->checksum_version);
332333

333334
fprintf(out,"STATUS=%s\n",status2str(backup->status));
334335
}
@@ -383,6 +384,7 @@ catalog_read_ini(const char *path)
383384
{'I',0,"data-bytes",NULL,SOURCE_ENV },
384385
{'u',0,"block-size",NULL,SOURCE_ENV },
385386
{'u',0,"xlog-block-size",NULL,SOURCE_ENV },
387+
{'u',0,"checksum_version",NULL,SOURCE_ENV },
386388
{'s',0,"status",NULL,SOURCE_ENV },
387389
{0 }
388390
};
@@ -405,6 +407,7 @@ catalog_read_ini(const char *path)
405407
options[i++].var=&backup->data_bytes;
406408
options[i++].var=&backup->block_size;
407409
options[i++].var=&backup->wal_block_size;
410+
options[i++].var=&backup->checksum_version;
408411
options[i++].var=&status;
409412
Assert(i==lengthof(options)-1);
410413

‎data.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include"libpq/pqsignal.h"
1818
#include"storage/block.h"
1919
#include"storage/bufpage.h"
20+
#include"storage/checksum_impl.h"
2021

2122
typedefstructBackupPageHeader
2223
{
@@ -299,7 +300,8 @@ backup_data_file(const char *from_root, const char *to_root,
299300
void
300301
restore_data_file(constchar*from_root,
301302
constchar*to_root,
302-
pgFile*file)
303+
pgFile*file,
304+
pgBackup*backup)
303305
{
304306
charto_path[MAXPGPATH];
305307
FILE*in;
@@ -386,6 +388,10 @@ restore_data_file(const char *from_root,
386388
blknum,file->path,strerror(errno));
387389
}
388390

391+
/* update checksum because we are not save whole */
392+
if(backup->checksum_version)
393+
((PageHeader)page.data)->pd_checksum=pg_checksum_page(page.data,header.block);
394+
389395
/*
390396
* Seek and write the restored page. Backup might have holes in
391397
* differential backups.

‎pg_arman.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"datapagemap.h"
2424
#include"storage/bufpage.h"
2525
#include"storage/block.h"
26+
#include"storage/checksum.h"
2627

2728
/* Query to fetch current transaction ID */
2829
#defineTXID_CURRENT_SQL"SELECT txid_current();"
@@ -140,6 +141,7 @@ typedef struct pgBackup
140141
/* data/wal block size for compatibility check */
141142
uint32block_size;
142143
uint32wal_block_size;
144+
uint32checksum_version;
143145
}pgBackup;
144146

145147
typedefstructpgBackupOption
@@ -288,7 +290,7 @@ extern int pgFileCompareMtimeDesc(const void *f1, const void *f2);
288290
externboolbackup_data_file(constchar*from_root,constchar*to_root,
289291
pgFile*file,constXLogRecPtr*lsn);
290292
externvoidrestore_data_file(constchar*from_root,constchar*to_root,
291-
pgFile*file);
293+
pgFile*file,pgBackup*backup);
292294
externboolcopy_file(constchar*from_root,constchar*to_root,
293295
pgFile*file);
294296

@@ -306,6 +308,7 @@ extern const char *status2str(BackupStatus status);
306308
externvoidremove_trailing_space(char*buf,intcomment_mark);
307309
externvoidremove_not_digit(char*buf,size_tlen,constchar*str);
308310
externXLogRecPtrget_last_ptrack_lsn(void);
311+
externuint32get_data_checksum_version(boolsafe);
309312

310313
/* in status.c */
311314
externboolis_pg_running(void);

‎restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ restore_files(void *arg)
437437

438438
/* restore file */
439439
if (!check)
440-
restore_data_file(from_root,pgdata,file);
440+
restore_data_file(from_root,pgdata,file,arguments->backup);
441441

442442
/* print size of restored file */
443443
if (!check)

‎util.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ get_current_timeline(bool safe)
111111
returnControlFile.checkPointCopy.ThisTimeLineID;
112112
}
113113

114+
uint32
115+
get_data_checksum_version(boolsafe)
116+
{
117+
ControlFileDataControlFile;
118+
char*buffer;
119+
size_tsize;
120+
121+
/* First fetch file... */
122+
buffer=slurpFile(pgdata,"global/pg_control",&size,safe);
123+
if (buffer==NULL)
124+
return0;
125+
digestControlFile(&ControlFile,buffer,size);
126+
pg_free(buffer);
127+
128+
returnControlFile.data_checksum_version;
129+
}
130+
131+
114132
/*
115133
* Convert time_t value to ISO-8601 format string
116134
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp