| 6513 | } |
| 6514 | |
| 6515 | static int clusterManagerCommandImport(int argc, char **argv) { |
| 6516 | int success = 1; |
| 6517 | int port = 0, src_port = 0; |
| 6518 | char *ip = NULL, *src_ip = NULL; |
| 6519 | char *invalid_args_msg = NULL; |
| 6520 | sds cmdfmt = NULL; |
| 6521 | if (!getClusterHostFromCmdArgs(argc, argv, &ip, &port)) { |
| 6522 | invalid_args_msg = CLUSTER_MANAGER_INVALID_HOST_ARG; |
| 6523 | goto invalid_args; |
| 6524 | } |
| 6525 | if (config.cluster_manager_command.from == NULL) { |
| 6526 | invalid_args_msg = "[ERR] Option '--cluster-from' is required for " |
| 6527 | "subcommand 'import'.\n"; |
| 6528 | goto invalid_args; |
| 6529 | } |
| 6530 | char *src_host[] = {config.cluster_manager_command.from}; |
| 6531 | if (!getClusterHostFromCmdArgs(1, src_host, &src_ip, &src_port)) { |
| 6532 | invalid_args_msg = "[ERR] Invalid --cluster-from host. You need to " |
| 6533 | "pass a valid address (ie. 120.0.0.1:7000).\n"; |
| 6534 | goto invalid_args; |
| 6535 | } |
| 6536 | clusterManagerLogInfo(">>> Importing data from %s:%d to cluster %s:%d\n", |
| 6537 | src_ip, src_port, ip, port); |
| 6538 | |
| 6539 | clusterManagerNode *refnode = clusterManagerNewNode(ip, port); |
| 6540 | if (!clusterManagerLoadInfoFromNode(refnode, 0)) return 0; |
| 6541 | if (!clusterManagerCheckCluster(0)) return 0; |
| 6542 | char *reply_err = NULL; |
| 6543 | redisReply *src_reply = NULL; |
| 6544 | // Connect to the source node. |
| 6545 | redisContext *src_ctx = redisConnect(src_ip, src_port); |
| 6546 | if (src_ctx->err) { |
| 6547 | success = 0; |
| 6548 | fprintf(stderr,"Could not connect to Redis at %s:%d: %s.\n", src_ip, |
| 6549 | src_port, src_ctx->errstr); |
| 6550 | goto cleanup; |
| 6551 | } |
| 6552 | // Auth for the source node. |
| 6553 | char *from_user = config.cluster_manager_command.from_user; |
| 6554 | char *from_pass = config.cluster_manager_command.from_pass; |
| 6555 | if (cliAuth(src_ctx, from_user, from_pass) == REDIS_ERR) { |
| 6556 | success = 0; |
| 6557 | goto cleanup; |
| 6558 | } |
| 6559 | |
| 6560 | src_reply = reconnectingRedisCommand(src_ctx, "INFO"); |
| 6561 | if (!src_reply || src_reply->type == REDIS_REPLY_ERROR) { |
| 6562 | if (src_reply && src_reply->str) reply_err = src_reply->str; |
| 6563 | success = 0; |
| 6564 | goto cleanup; |
| 6565 | } |
| 6566 | if (getLongInfoField(src_reply->str, "cluster_enabled")) { |
| 6567 | clusterManagerLogErr("[ERR] The source node should not be a " |
| 6568 | "cluster node.\n"); |
| 6569 | success = 0; |
| 6570 | goto cleanup; |
| 6571 | } |
| 6572 | freeReplyObject(src_reply); |
nothing calls this directly
no test coverage detected