提交 a1329f92 编写于 作者: W wenduo

binlog_sender add auth

上级 baa293c7
......@@ -15,18 +15,19 @@
static void Usage()
{
fprintf(stderr,
"Usage: binlogsender [-h] [-c old2new -i input_path -o output_path -f filenumber -t offset ]\n"
"Usage: binlogsender [-h] [-t old/new -a password -i ip -p port -n input -f filenumber -s starttime -e endtime ]\n"
"\tBinlog_sender reads from pika's binlog and send to pika/redis server\n"
"\tYou can specify a unixtime because pika's new binlog(later than 2.1.0) is timestamped.\n"
"\tYou can build a new pika back to any timepoint with this tool, let's rock and roll!\n"
"\t-h -- show this help\n"
"\t-a -- password for pika server\n"
"\t-t -- log type:old or new\n"
"\t-i -- ip of pika server\n"
"\t-p -- port of pika server\n"
"\t-n -- path of input binlog files , default: ./old_log/\n"
"\t-f -- files to send, default: 0\n"
"\t-s -- start time , default: '2001-00-00 00:59:01' \n"
"\t-e -- start time , default: '2100-01-30 24:00:01' \n"
"\t-e -- end time , default: '2100-01-30 24:00:01' \n"
" example: ./binlog_sender -n /data2/wangwenduo/newlog/ -t new -i 127.0.0.1 -p 10221 -s '2001-10-11 11:11:11' -e '2020-12-11 11:11:11' -f 526,527 \n"
);
......@@ -69,6 +70,7 @@ int main(int argc, char *argv[]) {
exit(-1);
}
std::string passwd;
std::string input_path = "./old_log/";
std::string ip = "127.0.0.1";
int port = 6279;
......@@ -78,6 +80,7 @@ int main(int argc, char *argv[]) {
std::string end_time_str = "2100-01-30 24:00:01";
// for correct inputs , we use these flags to generate warning to user
bool use_passwd = false;
bool default_input_path = true;
bool default_ip = true;
bool default_port = true;
......@@ -86,11 +89,15 @@ int main(int argc, char *argv[]) {
bool default_start_time = true;
bool default_end_time = true;
char c;
while (-1 != (c = getopt(argc, argv, "hn:i:p:t:f:s:e:"))) {
while (-1 != (c = getopt(argc, argv, "hn:i:p:t:f:s:e:a:"))) {
switch (c) {
case 'h':
Usage();
exit(-1);
case 'a':
passwd = optarg;
use_passwd = true;
break;
case 'n':
input_path = optarg;
default_input_path = false;
......@@ -187,6 +194,18 @@ int main(int argc, char *argv[]) {
exit(-1);
}
if (use_passwd) {
std::string auth_str;
auth_str = "*2\r\n$4\r\nauth\r\n$";
auth_str.append(std::to_string(passwd.size()));
auth_str.append("\r\n");
auth_str.append(passwd);
auth_str.append("\r\n");
pink_s = rcli->Send(&auth_str);
pink_s = rcli->Recv(NULL);
}
std::string scratch;
scratch.reserve(1024 * 1024);
int finished_num = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册