]> code.citadel.org Git - citadel.git/blobdiff - citadel/utils/ctdlload.c
It is the current year. (c)-2024
[citadel.git] / citadel / utils / ctdlload.c
index 45e68536eb4b85eabb3044cf68e4db0f4f952de7..c0cf91a8ccb912717beee3e27a91e6af7bd521aa 100644 (file)
@@ -1,6 +1,6 @@
-// Don't run this.  It doesn't work and if you try to run it you will immediately die.
+// Load (restore) the Citadel database from a flat file created by ctdldump
 //
-// Copyright (c) 2023 by Art Cancro citadel.org
+// Copyright (c) 2024 by Art Cancro citadel.org
 //
 // This program is open source software.  Use, duplication, or disclosure
 // is subject to the terms of the GNU General Public License, version 3.
@@ -722,58 +722,54 @@ void ingest(void) {
 
 // Main entry point
 int main(int argc, char **argv) {
-       char dst_dir[PATH_MAX];
        int confirmed = 0;
+       char *ctdldir = CTDLDIR;
 
        // display the greeting
        fprintf(stderr, "\033[44m\033[33m\033[1m \033[K\033[0m\n"
                        "\033[44m\033[33m\033[1m DB Load utility for Citadel \033[K\033[0m\n"
-                       "\033[44m\033[33m\033[1m Copyright (c) 2023 by citadel.org et al.  \033[K\033[0m\n"
+                       "\033[44m\033[33m\033[1m Copyright (c) 2023-2024 by citadel.org et al.  \033[K\033[0m\n"
                        "\033[44m\033[33m\033[1m This program is open source software.  Use, duplication, or disclosure \033[K\033[0m\n"
                        "\033[44m\033[33m\033[1m is subject to the terms of the GNU General Public license v3. \033[K\033[0m\n"
                        "\033[44m\033[33m\033[1m \033[K\033[0m\n");
 
-       // Default destination directory unless overridden
-       snprintf(dst_dir, sizeof(dst_dir), "%s/data", CTDLDIR);
-
        // Parse command line
        int a;
        while ((a = getopt(argc, argv, "h:y")) != EOF) {
                switch (a) {
                case 'h':
-                       snprintf(dst_dir, sizeof(dst_dir), "%s/data", optarg);
+                       ctdldir = optarg;
                        break;
                case 'y':
                        confirmed = 1;
                        break;
                default:
-                       fprintf(stderr, "%s: usage: %s -h dest_dir [<dumpfile]\n", argv[0], argv[0]);
+                       fprintf(stderr, "%s: usage: %s -h citadel_dir [<dumpfile]\n", argv[0], argv[0]);
                        exit(2);
                }
        }
 
-       if (dst_dir == NULL) {
-               fprintf(stderr, "ctdlload: no destination directory was specified.\n");
-               exit(1);
-       }
-
        if (confirmed == 1) {
                fprintf(stderr, "ctdlload: You have specified the [-y] flag, so processing will continue.\n");
        }
        else {
-               fprintf(stderr, "ctdlload: usage: ctdlload -y -h[data_dir] <[dump_file]\n");
-               fprintf(stderr, "          [data_dir] is your database directory, usually /usr/local/citadel/data\n");
+               fprintf(stderr, "ctdlload: usage: ctdlload -y -h[citadel_dir] <[dump_file]\n");
+               fprintf(stderr, "          -y : yes, I know this program can do damage and I want to run it anyway.\n");
+               fprintf(stderr, "          -h : [citadel_dir] is your server directory, usually /usr/local/citadel\n");
                fprintf(stderr, "          Please read [ https://www.citadel.org/dump-and-load.html ] to learn how to proceed.\n");
                exit(1);
        }
 
+       if (chdir(ctdldir) != 0) {
+               fprintf(stderr, "ctdlload: unable to change directory to [%s]: %m", ctdldir);
+               exit(2);
+       }
+
        // backend modules use syslog -- redirect to stderr
        openlog("ctdlload", LOG_PERROR , LOG_DAEMON);
 
        // Remove any database that is already in the target directory (yes, delete it, be careful)
-       char cmd[PATH_MAX];
-       snprintf(cmd, sizeof cmd, "rm -fv %s/cdb.* %s/log.*", dst_dir, dst_dir);
-       system(cmd);
+       system("rm -fv ./data/*");
 
        // initialize the database backend
        cdb_init_backends();