2013-01-24 09:35:48 +03:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2017-04-19 15:47:41 +02:00
|
|
|
* init.c: - initialize backup catalog.
|
2013-01-24 09:35:48 +03:00
|
|
|
*
|
2017-03-01 15:50:07 +02:00
|
|
|
* Portions Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
|
|
|
* Portions Copyright (c) 2015-2017, Postgres Professional
|
2013-01-24 09:35:48 +03:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2016-11-16 19:34:21 +02:00
|
|
|
#include "pg_probackup.h"
|
2013-01-24 09:35:48 +03:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* selects function for scandir.
|
2017-04-18 10:41:02 +02:00
|
|
|
* Select all files except hidden.
|
2013-01-24 09:35:48 +03:00
|
|
|
*/
|
|
|
|
static int selects(const struct dirent *dir)
|
|
|
|
{
|
2017-04-05 18:48:55 +02:00
|
|
|
return dir->d_name[0] != '.';
|
2013-01-24 09:35:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize backup catalog.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
do_init(void)
|
|
|
|
{
|
2017-04-05 18:48:55 +02:00
|
|
|
char path[MAXPGPATH];
|
|
|
|
char arclog_path_dir[MAXPGPATH];
|
2013-01-24 09:35:48 +03:00
|
|
|
|
|
|
|
struct dirent **dp;
|
|
|
|
int results;
|
2017-04-19 15:47:41 +02:00
|
|
|
pgBackupConfig *config = pgut_new(pgBackupConfig);
|
2017-02-01 14:40:47 +02:00
|
|
|
|
|
|
|
/* PGDATA is always required */
|
|
|
|
if (pgdata == NULL)
|
|
|
|
elog(ERROR, "Required parameter not specified: PGDATA "
|
|
|
|
"(-D, --pgdata)");
|
|
|
|
|
2016-01-14 09:36:39 +02:00
|
|
|
if (access(backup_path, F_OK) == 0)
|
|
|
|
{
|
2013-01-24 09:35:48 +03:00
|
|
|
results = scandir(backup_path, &dp, selects, NULL);
|
2016-01-14 09:36:39 +02:00
|
|
|
if (results != 0)
|
2016-11-28 15:33:13 +02:00
|
|
|
elog(ERROR, "backup catalog already exist and it's not empty");
|
2013-01-24 09:35:48 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 18:48:55 +02:00
|
|
|
/* Read system_identifier from PGDATA */
|
2017-04-19 15:47:41 +02:00
|
|
|
system_identifier = get_system_identifier();
|
2017-04-05 18:48:55 +02:00
|
|
|
|
2013-01-24 09:35:48 +03:00
|
|
|
/* create backup catalog root directory */
|
|
|
|
dir_create_dir(backup_path, DIR_PERMISSION);
|
|
|
|
|
|
|
|
/* create directories for backup of online files */
|
2016-11-07 16:35:53 +02:00
|
|
|
join_path_components(path, backup_path, BACKUPS_DIR);
|
2013-01-24 09:35:48 +03:00
|
|
|
dir_create_dir(path, DIR_PERMISSION);
|
|
|
|
|
2017-02-12 22:42:10 +02:00
|
|
|
/* Create "wal" directory */
|
|
|
|
join_path_components(arclog_path_dir, backup_path, "wal");
|
|
|
|
dir_create_dir(arclog_path_dir, DIR_PERMISSION);
|
2013-01-24 09:35:48 +03:00
|
|
|
|
2017-04-19 15:47:41 +02:00
|
|
|
/*
|
|
|
|
* Wite initial config. system-identifier and pgdata are set in
|
|
|
|
* init subcommand and will never be updated.
|
|
|
|
*/
|
|
|
|
pgBackupConfigInit(config);
|
|
|
|
config->system_identifier = system_identifier;
|
|
|
|
config->pgdata = pgdata;
|
|
|
|
writeBackupCatalogConfigFile(config);
|
2013-01-24 09:35:48 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|