futriix-old/src/rdb-s3.cpp
John Sully d2aa6471e5 Merge branch 'unstable' of https://github.com/antirez/redis into unstable
Former-commit-id: d8741595aea1f07b0c5ffdf63a086df2ca4e6b1b
2019-02-06 00:09:39 -05:00

43 lines
772 B
C++

extern "C" {
#include "rio.h"
#include "server.h"
}
#include <unistd.h>
#include <sys/wait.h>
/* Save the DB on disk. Return C_ERR on error, C_OK on success. */
extern "C" int rdbSaveS3(char *s3bucket, rdbSaveInfo *rsi)
{
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]);
// NOP
return C_ERR;
}