From: Art Cancro Date: Wed, 26 Jul 2023 14:26:33 +0000 (-0900) Subject: ctdlvisor: remove migrate mode, add export and import modes X-Git-Url: https://code.citadel.org/?p=citadel-docker.git;a=commitdiff_plain;h=41d8d610dac307150076e8d7aff685d7a0b75697 ctdlvisor: remove migrate mode, add export and import modes --- diff --git a/ctdlvisor.c b/ctdlvisor.c index 25a2311..c97509d 100644 --- a/ctdlvisor.c +++ b/ctdlvisor.c @@ -29,7 +29,7 @@ char *logging_flag = "-x1"; // Call this instead of exit() just for common diagnostics etc. void ctdlvisor_exit(int code) { - printf("ctdlvisor: exit code %d\n", code); + fprintf(stderr, "ctdlvisor: exit code %d\n", code); exit(code); } @@ -182,8 +182,10 @@ void main_loop(void) { int main(int argc, char **argv) { int a; - int migrate_mode = 0; + int export_mode = 0; + int import_mode = 0; int database_cleanup_mode = 0; + char bin[1024]; fprintf(stderr, "ctdlvisor: Welcome to the Citadel System running in a container.\n"); fprintf(stderr, "ctdlvisor: command line arguments: "); @@ -213,7 +215,7 @@ int main(int argc, char **argv) { symlink(CTDL_DIR "/keys", "/usr/local/webcit/keys"); /* parse command-line arguments */ - while ((a=getopt(argc, argv, "cmdx:")) != EOF) switch(a) { + while ((a=getopt(argc, argv, "ceidx:")) != EOF) switch(a) { // test this binary for compatibility and exit case 'c': @@ -221,9 +223,14 @@ int main(int argc, char **argv) { exit(0); break; - // run ctdlmigrate only - case 'm': - migrate_mode = 1; + // export your database + case 'e': + export_mode = 1; + break; + + // import your database + case 'i': + import_mode = 1; break; // run database_cleanup.sh only @@ -239,30 +246,27 @@ int main(int argc, char **argv) { // any other parameter makes it crash and burn default: - fprintf(stderr, "%s: usage: %s [-c] [-m] [-d] [-x log_level]\n"); + fprintf(stderr, "%s: usage: %s [-c] [-e] [-i] [-d] [-x log_level]\n", argv[0], argv[0]); exit(1); } signal(SIGHUP, signal_handler); - // "migrate mode" means we just start the server and then run ctdlmigrate interactively. - if (migrate_mode) { - citserver_pid = start_citadel(); - fprintf(stderr, "ctdlvisor: waiting a moment for citserver to initialize...\n"); - sleep(5); - char bin[1024]; - sprintf(bin, "/usr/local/citadel/ctdlmigrate -h %s", CTDL_DIR); + // "export mode" means we only run ctdldump + if (export_mode) { + sprintf(bin, "/usr/local/citadel/ctdldump -y -h %s", CTDL_DIR); + system(bin); + } + + // "import mode" means we only run ctdlload + if (export_mode) { + sprintf(bin, "/usr/local/citadel/ctdlload -y -h %s", CTDL_DIR); system(bin); - kill(citserver_pid, SIGTERM); } // "database cleanup mode" means we just start the server and then run database_cleanup.sh interactively else if (database_cleanup_mode) { - citserver_pid = start_citadel(); - fprintf(stderr, "ctdlvisor: waiting a moment for citserver to initialize...\n"); - sleep(5); - char bin[1024]; sprintf(bin, "/usr/local/citadel/database_cleanup.sh -h %s", CTDL_DIR); system(bin); kill(citserver_pid, SIGTERM);