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 01:06:48 -05:00
|
|
|
int status = EXIT_FAILURE;
|
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
|
2019-02-06 01:06:48 -05:00
|
|
|
dup2(fd[0], STDIN_FILENO);
|
|
|
|
close(fd[1]);
|
|
|
|
close(fd[0]);
|
|
|
|
execlp("aws", "aws", "s3", "cp", "-", s3bucket, nullptr);
|
2019-02-06 00:09:39 -05:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-06 01:06:48 -05:00
|
|
|
close(fd[0]);
|
|
|
|
if (rdbSaveFd(fd[1], rsi) != C_OK)
|
|
|
|
{
|
|
|
|
close(fd[1]);
|
|
|
|
return C_ERR;
|
|
|
|
}
|
2019-02-06 00:09:39 -05:00
|
|
|
close(fd[1]);
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
}
|
|
|
|
|
2019-02-06 01:06:48 -05:00
|
|
|
if (status != EXIT_SUCCESS)
|
|
|
|
serverLog(LL_WARNING, "Failed to save DB to AWS S3");
|
|
|
|
else
|
|
|
|
serverLog(LL_NOTICE,"DB saved on AWS S3");
|
|
|
|
|
|
|
|
return (status == EXIT_SUCCESS) ? C_OK : C_ERR;
|
2019-02-05 23:36:40 -05:00
|
|
|
}
|