/*------------------------------------------------------------------------- * * pg_arman.h: Backup/Recovery manager for PostgreSQL. * * Copyright (c) 2009-2013, NIPPON TELEGRAPH AND TELEPHONE CORPORATION * *------------------------------------------------------------------------- */ #ifndef PG_RMAN_H #define PG_RMAN_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" /* Query to fetch current transaction ID */ #define TXID_CURRENT_SQL "SELECT txid_current();" /* Directory/File names */ #define DATABASE_DIR "database" #define RESTORE_WORK_DIR "backup" #define PG_XLOG_DIR "pg_xlog" #define PG_TBLSPC_DIR "pg_tblspc" #define BACKUP_INI_FILE "backup.ini" #define PG_RMAN_INI_FILE "pg_arman.ini" #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; datapagemap_t pagemap; } pgFile; typedef struct pgBackupRange { time_t begin; time_t end; /* begin +1 when one backup is target */ } pgBackupRange; #define pgBackupRangeIsValid(range) \ (((range)->begin != (time_t) 0) || ((range)->end != (time_t) 0)) #define pgBackupRangeIsSingle(range) \ (pgBackupRangeIsValid(range) && (range)->begin == ((range)->end)) #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-) */ /* 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, BACKUP_MODE_DIFF_PAGE, /* differential page backup */ BACKUP_MODE_DIFF_PTRACK, /* differential page backup with ptrack system*/ BACKUP_MODE_FULL /* full backup */ } BackupMode; /* * pg_arman takes backup into the directroy $BACKUP_PATH//