-// Don't run this. It doesn't work and if you try to run it you will immediately die.
+// Dump the Citadel database to a flat file that can be restored by ctdlload on any architecture
//
-// Copyright (c) 2023 by Art Cancro citadel.org
+// Copyright (c) 2023-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.
int num_bad_rows = 0;
cdb_rewind(which_cdb);
- while (ckv = cdb_next_item(which_cdb), ckv.val.ptr!=NULL) {
+ while (ckv = cdb_next_item(which_cdb), ckv.val.ptr!=NULL) { // always read through to the end
// Call the export function registered to this table
export_functions[which_cdb](which_cdb, ckv);
}
int main(int argc, char **argv) {
int i = 0;
- char src_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 Dump 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 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 source directory unless overridden
- snprintf(src_dir, sizeof(src_dir), "%s/data", CTDLDIR);
+ fprintf(stderr,
+ "\033[44m\033[1m╔════════════════════════════════════════════════════════════════════════╗\033[0m\n"
+ "\033[44m\033[1m║ DB Dump utility for Citadel version %-4d ║\033[0m\n"
+ "\033[44m\033[1m║ Copyright (c) 2023-2024 by citadel.org et al. ║\033[0m\n"
+ "\033[44m\033[1m║ This program is open source software. Use, duplication, or disclosure ║\033[0m\n"
+ "\033[44m\033[1m║ is subject to the terms of the GNU General Public license v3. ║\033[0m\n"
+ "\033[44m\033[1m╚════════════════════════════════════════════════════════════════════════╝\033[0m\n",
+ REV_LEVEL
+ );
// Parse command line
int a;
while ((a = getopt(argc, argv, "h:y")) != EOF) {
switch (a) {
case 'h':
- snprintf(src_dir, sizeof(src_dir), "%s/data", optarg);
+ ctdldir = optarg;
break;
case 'y':
confirmed = 1;
}
}
- if (src_dir == NULL) {
- fprintf(stderr, "ctdldump: no source directory was specified.\n");
- exit(1);
- }
-
if (confirmed == 1) {
fprintf(stderr, "ctdldump: You have specified the [-y] flag, so processing will continue.\n");
}
else {
fprintf(stderr, "ctdldump: usage: ctdldump -y -h[citadel_dir] >[dump_file]\n");
- fprintf(stderr, " [citadel_dir] is your database directory, usually /usr/local/citadel\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("ctdldump", LOG_PERROR , LOG_DAEMON);