2019-02-05 23:36:40 -05:00
|
|
|
extern "C" {
|
|
|
|
#include "rio.h"
|
|
|
|
#include "server.h"
|
|
|
|
}
|
2019-02-06 00:09:39 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
2019-02-05 23:36:40 -05:00
|
|
|
|
|
|
|
/* Save the DB on disk. Return C_ERR on error, C_OK on success. */
|
|
|
|
extern "C" int rdbSaveS3(char *s3bucket, rdbSaveInfo *rsi)
|
|
|
|
{
|
2019-02-06 00:09:39 -05:00
|
|
|
int fd[2];
|
|
|
|
if (pipe(fd) != 0)
|
|
|
|
return C_ERR;
|
|
|
|
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0)
|
|
|
|
{
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
return C_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
// child process
|
|
|
|
dup2(fd[1], STDIN_FILENO);
|
|
|
|
execlp("aws", "s3", "cp", "-", s3bucket, nullptr);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
close(fd[1]);
|
|
|
|
rdbSaveFd(fd[0], rsi);
|
|
|
|
int status;
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd[0]);
|
|
|
|
|
|
|
|
|
2019-02-05 23:36:40 -05:00
|
|
|
// NOP
|
|
|
|
return C_ERR;
|
|
|
|
}
|