/*------------------------------------------------------------------------- * * pg_probackup.h: Backup/Recovery manager for PostgreSQL. * * Copyright (c) 2009-2013, NIPPON TELEGRAPH AND TELEPHONE CORPORATION * *------------------------------------------------------------------------- */ #ifndef PG_PROBACKUP_H #define PG_PROBACKUP_H #include "postgres_fe.h" #include #include "libpq-fe.h" #include "pgut/pgut.h" #include "access/xlogdefs.h" #include "access/xlog_internal.h" #include "catalog/pg_control.h" #include "utils/pg_crc.h" #include "parray.h" #include "datapagemap.h" #include "storage/bufpage.h" #include "storage/block.h" #include "storage/checksum.h" /* Query to fetch current transaction ID */ #define TXID_CURRENT_SQL "SELECT txid_current();" #define TXID_CURRENT_IF_SQL "SELECT txid_snapshot_xmax(txid_current_snapshot());" /* Directory/File names */ #define DATABASE_DIR "database" #define BACKUPS_DIR "backups" #define PG_XLOG_DIR "pg_xlog" #define PG_TBLSPC_DIR "pg_tblspc" #define BACKUP_INI_FILE "backup.conf" #define PG_RMAN_INI_FILE "pg_probackup.conf" #define MKDIRS_SH_FILE "mkdirs.sh" #define DATABASE_FILE_LIST "file_database.txt" #define PG_BACKUP_LABEL_FILE "backup_label" #define PG_BLACK_LIST "black_list" /* Direcotry/File permission */ #define DIR_PERMISSION (0700) #define FILE_PERMISSION (0600) /* backup mode file */ typedef struct pgFile { time_t mtime; /* time of last modification */ mode_t mode; /* protection (file type and permission) */ size_t size; /* size of the file */ size_t read_size; /* size of the portion read (if only some pages are backed up partially, it's different from size) */ size_t write_size; /* size of the backed-up file. BYTES_INVALID means that the file existed but was not backed up because not modified since last backup. */ pg_crc32 crc; /* CRC value of the file, regular file only */ char *linked; /* path of the linked file */ bool is_datafile; /* true if the file is PostgreSQL data file */ char *path; /* path of the file */ char *ptrack_path; int segno; /* Segment number for ptrack */ volatile uint32 lock; datapagemap_t pagemap; } pgFile; #define IsValidTime(tm) \ ((tm.tm_sec >= 0 && tm.tm_sec <= 60) && /* range check for tm_sec (0-60) */ \ (tm.tm_min >= 0 && tm.tm_min <= 59) && /* range check for tm_min (0-59) */ \ (tm.tm_hour >= 0 && tm.tm_hour <= 23) && /* range check for tm_hour(0-23) */ \ (tm.tm_mday >= 1 && tm.tm_mday <= 31) && /* range check for tm_mday(1-31) */ \ (tm.tm_mon >= 0 && tm.tm_mon <= 11) && /* range check for tm_mon (0-23) */ \ (tm.tm_year + 1900 >= 1900)) /* range check for tm_year(70-) */ /* Effective data size */ #define MAPSIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData)) /* Backup status */ /* XXX re-order ? */ typedef enum BackupStatus { BACKUP_STATUS_INVALID, /* the pgBackup is invalid */ BACKUP_STATUS_OK, /* completed backup */ BACKUP_STATUS_RUNNING, /* running backup */ BACKUP_STATUS_ERROR, /* aborted because of unexpected error */ BACKUP_STATUS_DELETING, /* data files are being deleted */ BACKUP_STATUS_DELETED, /* data files have been deleted */ BACKUP_STATUS_DONE, /* completed but not validated yet */ BACKUP_STATUS_CORRUPT /* files are corrupted, not available */ } BackupStatus; typedef enum BackupMode { BACKUP_MODE_INVALID = 0, BACKUP_MODE_DIFF_PAGE, /* differential page backup */ BACKUP_MODE_DIFF_PTRACK, /* differential page backup with ptrack system*/ BACKUP_MODE_FULL /* full backup */ } BackupMode; /* * pg_probackup takes backup into the directroy $BACKUP_PATH//