Save the DB on disk. Return C_ERR on error, C_OK on success. */
| 5 | |
| 6 | /* Save the DB on disk. Return C_ERR on error, C_OK on success. */ |
| 7 | int rdbSaveS3(char *s3bucket, const redisDbPersistentDataSnapshot **rgpdb, rdbSaveInfo *rsi) |
| 8 | { |
| 9 | int status = EXIT_FAILURE; |
| 10 | int fd[2]; |
| 11 | if (pipe(fd) != 0) |
| 12 | return C_ERR; |
| 13 | |
| 14 | pid_t pid = fork(); |
| 15 | if (pid < 0) |
| 16 | { |
| 17 | close(fd[0]); |
| 18 | close(fd[1]); |
| 19 | return C_ERR; |
| 20 | } |
| 21 | |
| 22 | if (pid == 0) |
| 23 | { |
| 24 | // child process |
| 25 | dup2(fd[0], STDIN_FILENO); |
| 26 | close(fd[1]); |
| 27 | close(fd[0]); |
| 28 | execlp("aws", "aws", "s3", "cp", "-", s3bucket, nullptr); |
| 29 | exit(EXIT_FAILURE); |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | close(fd[0]); |
| 34 | FILE *fp = fdopen(fd[1], "w"); |
| 35 | if (fp == NULL) |
| 36 | { |
| 37 | close (fd[1]); |
| 38 | return C_ERR; |
| 39 | } |
| 40 | |
| 41 | if (rdbSaveFp(fp, rgpdb, rsi) != C_OK) |
| 42 | { |
| 43 | fclose(fp); |
| 44 | return C_ERR; |
| 45 | } |
| 46 | fclose(fp); |
| 47 | waitpid(pid, &status, 0); |
| 48 | } |
| 49 | |
| 50 | if (status != EXIT_SUCCESS) |
| 51 | serverLog(LL_WARNING, "Failed to save DB to AWS S3"); |
| 52 | else |
| 53 | serverLog(LL_NOTICE,"DB saved on AWS S3"); |
| 54 | |
| 55 | return (status == EXIT_SUCCESS) ? C_OK : C_ERR; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | int rdbLoadS3Core(int fd, rdbSaveInfo *rsi, int rdbflags) |