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

Commit9b6e5da

Browse files
committed
Fix configuration of reomte agent
1 parent6e261cc commit9b6e5da

File tree

4 files changed

+79
-43
lines changed

4 files changed

+79
-43
lines changed

‎src/fetch.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ slurpFile(const char *datadir, const char *path, size_t *filesize, bool safe, fi
3434
intlen;
3535
snprintf(fullpath,sizeof(fullpath),"%s/%s",datadir,path);
3636

37+
if (fio_access(fullpath,R_OK,location)!=0)
38+
{
39+
if (safe)
40+
returnNULL;
41+
else
42+
elog(ERROR,"could not open file \"%s\" for reading: %s",
43+
fullpath,strerror(errno));
44+
}
45+
3746
if ((fd=fio_open(fullpath,O_RDONLY |PG_BINARY,location))==-1)
3847
{
3948
if (safe)

‎src/pg_probackup.c

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -329,47 +329,6 @@ main(int argc, char *argv[])
329329
}
330330
canonicalize_path(backup_path);
331331

332-
/* Ensure that backup_path is an absolute path */
333-
if (!is_absolute_path(backup_path))
334-
elog(ERROR,"-B, --backup-path must be an absolute path");
335-
336-
/*
337-
* We read options from command line, now we need to read them from
338-
* configuration file since we got backup path and instance name.
339-
* For some commands an instance option isn't required, see above.
340-
*/
341-
if (instance_name)
342-
{
343-
charpath[MAXPGPATH];
344-
345-
/* Read environment variables */
346-
config_get_opt_env(instance_options);
347-
348-
/* Read options from configuration file */
349-
join_path_components(path,backup_instance_path,BACKUP_CATALOG_CONF_FILE);
350-
config_read_opt(path,instance_options,ERROR, true);
351-
}
352-
353-
if (IsSshProtocol()
354-
&& (backup_subcmd==BACKUP_CMD||backup_subcmd==ADD_INSTANCE_CMD||backup_subcmd==RESTORE_CMD||
355-
backup_subcmd==ARCHIVE_PUSH_CMD||backup_subcmd==ARCHIVE_GET_CMD))
356-
{
357-
if (remote_agent) {
358-
if (backup_subcmd!=BACKUP_CMD&&backup_subcmd!=ARCHIVE_PUSH_CMD) {
359-
fio_communicate(STDIN_FILENO,STDOUT_FILENO);
360-
return0;
361-
}
362-
fio_redirect(STDIN_FILENO,STDOUT_FILENO);
363-
}else {
364-
/* Execute remote probackup */
365-
intstatus=remote_execute(argc,argv,backup_subcmd==BACKUP_CMD||backup_subcmd==ARCHIVE_PUSH_CMD);
366-
if (status!=0||backup_subcmd==ARCHIVE_PUSH_CMD)
367-
{
368-
returnstatus;
369-
}
370-
}
371-
}
372-
373332
if (!remote_agent)
374333
{
375334
/* Ensure that backup_path is a path to a directory */
@@ -378,6 +337,11 @@ main(int argc, char *argv[])
378337
elog(ERROR,"-B, --backup-path must be a path to directory");
379338
}
380339

340+
/* Ensure that backup_path is an absolute path */
341+
if (!is_absolute_path(backup_path))
342+
elog(ERROR,"-B, --backup-path must be an absolute path");
343+
344+
381345
/* Option --instance is required for all commands except init and show */
382346
if (backup_subcmd!=INIT_CMD&&backup_subcmd!=SHOW_CMD&&
383347
backup_subcmd!=VALIDATE_CMD)
@@ -409,9 +373,46 @@ main(int argc, char *argv[])
409373
}
410374
}
411375

376+
/*
377+
* We read options from command line, now we need to read them from
378+
* configuration file since we got backup path and instance name.
379+
* For some commands an instance option isn't required, see above.
380+
*/
381+
if (instance_name&& !remote_agent)
382+
{
383+
charpath[MAXPGPATH];
384+
385+
/* Read environment variables */
386+
config_get_opt_env(instance_options);
387+
388+
/* Read options from configuration file */
389+
join_path_components(path,backup_instance_path,BACKUP_CATALOG_CONF_FILE);
390+
config_read_opt(path,instance_options,ERROR, true);
391+
}
392+
412393
/* Initialize logger */
413394
init_logger(backup_path,&instance_config.logger);
414395

396+
if (IsSshProtocol()
397+
&& (backup_subcmd==BACKUP_CMD||backup_subcmd==ADD_INSTANCE_CMD||backup_subcmd==RESTORE_CMD||
398+
backup_subcmd==ARCHIVE_PUSH_CMD||backup_subcmd==ARCHIVE_GET_CMD))
399+
{
400+
if (remote_agent) {
401+
if (backup_subcmd!=BACKUP_CMD&&backup_subcmd!=ARCHIVE_PUSH_CMD) {
402+
fio_communicate(STDIN_FILENO,STDOUT_FILENO);
403+
return0;
404+
}
405+
fio_redirect(STDIN_FILENO,STDOUT_FILENO);
406+
}else {
407+
/* Execute remote probackup */
408+
intstatus=remote_execute(argc,argv,backup_subcmd==BACKUP_CMD||backup_subcmd==ARCHIVE_PUSH_CMD);
409+
if (status!=0||backup_subcmd==ARCHIVE_PUSH_CMD)
410+
{
411+
returnstatus;
412+
}
413+
}
414+
}
415+
415416
/* command was initialized for a few commands */
416417
if (command)
417418
{

‎src/utils/configuration.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*-------------------------------------------------------------------------
99
*/
1010

11+
#include"pg_probackup.h"
1112
#include"configuration.h"
1213
#include"logger.h"
1314
#include"pgut.h"
@@ -493,8 +494,9 @@ config_get_opt(int argc, char **argv, ConfigOption cmd_options[],
493494
if (opt==NULL)
494495
opt=option_find(c,options);
495496

496-
if (opt&&
497-
opt->allowed<SOURCE_CMD&&opt->allowed!=SOURCE_CMD_STRICT)
497+
if (opt
498+
&& !remote_agent
499+
&&opt->allowed<SOURCE_CMD&&opt->allowed!=SOURCE_CMD_STRICT)
498500
elog(ERROR,"Option %s cannot be specified in command line",
499501
opt->lname);
500502
/* Check 'opt == NULL' is performed in assign_option() */

‎src/utils/remote.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,34 @@ int remote_execute(int argc, char* argv[], bool listen)
117117
}else {
118118
dst=snprintf(cmd,sizeof(cmd),"%s",pg_probackup);
119119
}
120+
120121
for (i=1;i<argc;i++) {
121122
dst=append_option(cmd,sizeof(cmd),dst,argv[i]);
122123
}
124+
123125
dst=append_option(cmd,sizeof(cmd),dst,"--agent");
124126
dst=append_option(cmd,sizeof(cmd),dst,PROGRAM_VERSION);
127+
128+
for (i=0;instance_options[i].type;i++) {
129+
ConfigOption*opt=&instance_options[i];
130+
char*value;
131+
char*cmd_opt;
132+
133+
/* Path only options from file */
134+
if (opt->source!=SOURCE_FILE)
135+
continue;
136+
137+
value=opt->get_value(opt);
138+
if (value==NULL)
139+
continue;
140+
141+
cmd_opt=psprintf("--%s=%s",opt->lname,value);
142+
143+
dst=append_option(cmd,sizeof(cmd),dst,cmd_opt);
144+
pfree(value);
145+
pfree(cmd_opt);
146+
}
147+
125148
cmd[dst]='\0';
126149

127150
SYS_CHECK(pipe(infd));
@@ -154,6 +177,7 @@ int remote_execute(int argc, char* argv[], bool listen)
154177
SYS_CHECK(close(outfd[0]));
155178
SYS_CHECK(close(errfd[1]));
156179
atexit(kill_child);
180+
157181
if (listen) {
158182
intstatus;
159183
fio_communicate(infd[0],outfd[1]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp