2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: amadmin.c,v 1.124 2006/07/26 15:17:37 martinea Exp $
30 * controlling process for the Amanda backup system
43 #include "timestamp.h"
44 #include "server_util.h"
48 int main(int argc, char **argv);
50 static void estimate(int argc, char **argv);
51 static void estimate_one(disk_t *dp);
52 void force(int argc, char **argv);
53 void force_one(disk_t *dp);
54 void unforce(int argc, char **argv);
55 void unforce_one(disk_t *dp);
56 void force_bump(int argc, char **argv);
57 void force_bump_one(disk_t *dp);
58 void force_no_bump(int argc, char **argv);
59 void force_no_bump_one(disk_t *dp);
60 void unforce_bump(int argc, char **argv);
61 void unforce_bump_one(disk_t *dp);
62 void reuse(int argc, char **argv);
63 void noreuse(int argc, char **argv);
64 void info(int argc, char **argv);
65 void info_one(disk_t *dp);
66 void due(int argc, char **argv);
67 void due_one(disk_t *dp);
68 void find(int argc, char **argv);
69 void holding(int argc, char **argv);
70 void delete(int argc, char **argv);
71 void delete_one(disk_t *dp);
72 void balance(int argc, char **argv);
73 void tape(int argc, char **argv);
74 void bumpsize(int argc, char **argv);
75 void diskloop(int argc, char **argv, char *cmdname, void (*func)(disk_t *dp));
76 char *seqdatestr(int seq);
77 static int next_level0(disk_t *dp, info_t *info);
78 int bump_thresh(int level);
79 void export_db(int argc, char **argv);
80 void import_db(int argc, char **argv);
81 void disklist(int argc, char **argv);
82 void disklist_one(disk_t *dp);
83 void show_version(int argc, char **argv);
84 static void show_config(int argc, char **argv);
86 static char *conf_tapelist = NULL;
87 static char *displayunit;
88 static long int unitdivisor;
92 void (*fn)(int, char **);
95 { "version", show_version,
96 T_("\t\t\t\t\t# Show version info.") },
97 { "config", show_config,
98 T_("\t\t\t\t\t# Show configuration.") },
99 { "estimate", estimate,
100 T_(" [<hostname> [<disks>]* ]*\t# Print server estimate.") },
102 T_(" [<hostname> [<disks>]* ]+\t\t# Force level 0 at next run.") },
103 { "unforce", unforce,
104 T_(" [<hostname> [<disks>]* ]+\t# Clear force command.") },
105 { "force-bump", force_bump,
106 T_(" [<hostname> [<disks>]* ]+\t# Force bump at next run.") },
107 { "force-no-bump", force_no_bump,
108 T_(" [<hostname> [<disks>]* ]+\t# Force no-bump at next run.") },
109 { "unforce-bump", unforce_bump,
110 T_(" [<hostname> [<disks>]* ]+\t# Clear bump command.") },
111 { "disklist", disklist,
112 T_(" [<hostname> [<disks>]* ]*\t# Debug disklist entries.") },
114 T_(" <tapelabel> ...\t\t # re-use this tape.") },
115 { "no-reuse", noreuse,
116 T_(" <tapelabel> ...\t # never re-use this tape.") },
118 T_(" [<hostname> [<disks>]* ]*\t # Show which tapes these dumps are on.") },
119 { "holding", holding,
120 T_(" {list [ -l ] |delete} [ <hostname> [ <disk> [ <datestamp> [ .. ] ] ] ]+\t # Show or delete holding disk contents.") },
122 T_(" [<hostname> [<disks>]* ]+ # Delete from database.") },
124 T_(" [<hostname> [<disks>]* ]*\t # Show current info records.") },
126 T_(" [<hostname> [<disks>]* ]*\t # Show due date.") },
127 { "balance", balance,
128 T_(" [--days <num>]\t\t # Show nightly dump size balance.") },
130 T_(" [--days <num>]\t\t # Show which tape is due next.") },
131 { "bumpsize", bumpsize,
132 T_("\t\t\t # Show current bump thresholds.") },
133 { "export", export_db,
134 T_(" [<hostname> [<disks>]* ]* # Export curinfo database to stdout.") },
135 { "import", import_db,
136 T_("\t\t\t\t # Import curinfo database from stdin.") },
138 #define NCMDS (int)(sizeof(cmdtab) / sizeof(cmdtab[0]))
148 config_overrides_t *cfg_ovr = NULL;
151 * Configure program for internationalization:
152 * 1) Only set the message locale for now.
153 * 2) Set textdomain for all amanda related programs to "amanda"
154 * We don't want to be forced to support dozens of message catalogs.
156 setlocale(LC_MESSAGES, "C");
157 textdomain("amanda");
162 set_pname("amadmin");
164 /* Don't die when child closes pipe */
165 signal(SIGPIPE, SIG_IGN);
167 dbopen(DBG_SUBDIR_SERVER);
169 add_amanda_log_handler(amanda_log_stderr);
171 cfg_ovr = extract_commandline_config_overrides(&argc, &argv);
173 if(argc < 3) usage();
175 set_config_overrides(cfg_ovr);
176 config_init(CONFIG_INIT_EXPLICIT_NAME, argv[1]);
178 if(strcmp(argv[2],"version") == 0) {
179 show_version(argc, argv);
183 conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
184 read_diskfile(conf_diskfile, &diskq);
185 amfree(conf_diskfile);
187 if (config_errors(NULL) >= CFGERR_WARNINGS) {
188 config_print_errors();
189 if (config_errors(NULL) >= CFGERR_ERRORS) {
190 g_critical(_("errors processing config file"));
194 dbrename(get_config_name(), DBG_SUBDIR_SERVER);
196 check_running_as(RUNNING_AS_DUMPUSER);
198 conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST));
199 if(read_tapelist(conf_tapelist)) {
200 error(_("could not load tapelist \"%s\""), conf_tapelist);
203 /* conf_tapelist is not freed yet -- it may be used to write the
206 conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));
207 if(open_infofile(conf_infofile)) {
208 error(_("could not open info db \"%s\""), conf_infofile);
211 amfree(conf_infofile);
213 displayunit = getconf_str(CNF_DISPLAYUNIT);
214 unitdivisor = getconf_unit_divisor();
216 for (i = 0; i < NCMDS; i++)
217 if (strcmp(argv[2], cmdtab[i].name) == 0) {
218 (*cmdtab[i].fn)(argc, argv);
222 g_fprintf(stderr, _("%s: unknown command \"%s\"\n"), argv[0], argv[2]);
228 amfree(conf_tapelist);
232 free_disklist(&diskq);
243 g_fprintf(stderr, _("\nUsage: %s <conf> <command> {<args>} [-o configoption]* ...\n"),
245 g_fprintf(stderr, _(" Valid <command>s are:\n"));
246 for (i = 0; i < NCMDS; i++)
247 g_fprintf(stderr, "\t%s%s\n", cmdtab[i].name, _(cmdtab[i].usage));
252 /* ----------------------------------------------- */
254 #define SECS_PER_DAY (24*60*60)
262 static char *dow[7] = {
271 time_t t = today + seq*SECS_PER_DAY;
277 g_snprintf(str, SIZEOF(str),
278 "%2d/%02d %3s", tm->tm_mon+1, tm->tm_mday, _(dow[tm->tm_wday]));
280 strcpy(str, _("BAD DATE"));
286 #define days_diff(a, b) (int)(((b) - (a) + SECS_PER_DAY) / SECS_PER_DAY)
288 /* when is next level 0 due? 0 = tonight, 1 = tommorrow, etc*/
294 if(dp->strategy == DS_NOFULL)
295 return 1; /* fake it */
296 if(info->inf[0].date < (time_t)0)
297 return 0; /* new disk */
299 return dp->dumpcycle - days_diff(info->inf[0].date, today);
302 /* ----------------------------------------------- */
309 void (*func)(disk_t *dp))
316 g_fprintf(stderr,_("%s: expecting \"%s [<hostname> [<disks>]* ]+\"\n"),
317 get_pname(), cmdname);
321 errstr = match_disklist(&diskq, argc-3, argv+3);
323 g_printf("%s", errstr);
327 for(dp = diskq.head; dp != NULL; dp = dp->next) {
334 g_fprintf(stderr,_("%s: no disk matched\n"),get_pname());
338 /* ----------------------------------------------- */
345 char *hostname = dp->host->hostname;
346 char *diskname = dp->name;
347 char *qhost = quote_string(hostname);
348 char *qdisk = quote_string(diskname);
353 get_info(hostname, diskname, &info);
355 size = internal_server_estimate(dp, &info, 0, &stats);
357 printf("%s %s %d %jd\n", qhost, qdisk, 0, (intmax_t)size);
360 if (info.last_level > 0) {
361 size = internal_server_estimate(dp, &info, info.last_level, &stats);
363 printf("%s %s %d %jd\n", qhost, qdisk, info.last_level,
368 if (info.last_level > -1) {
369 size = internal_server_estimate(dp, &info, info.last_level+1, &stats);
371 printf("%s %s %d %jd\n", qhost, qdisk, info.last_level+1,
389 diskloop(argc, argv, "estimate", estimate_one);
391 for(dp = diskq.head; dp != NULL; dp = dp->next)
396 /* ----------------------------------------------- */
403 char *hostname = dp->host->hostname;
404 char *diskname = dp->name;
407 get_info(hostname, diskname, &info);
408 SET(info.command, FORCE_FULL);
409 if (ISSET(info.command, FORCE_BUMP)) {
410 CLR(info.command, FORCE_BUMP);
411 g_printf(_("%s: WARNING: %s:%s FORCE_BUMP command was cleared.\n"),
412 get_pname(), hostname, diskname);
414 if(put_info(hostname, diskname, &info) == 0) {
415 if (dp->strategy == DS_INCRONLY) {
416 g_printf(_("%s: %s:%s, full dump done offline, next dump will be at level 1.\n"),
417 get_pname(), hostname, diskname);
419 g_printf(_("%s: %s:%s is set to a forced level 0 at next run.\n"),
420 get_pname(), hostname, diskname);
423 g_fprintf(stderr, _("%s: %s:%s could not be forced.\n"),
424 get_pname(), hostname, diskname);
434 diskloop(argc, argv, "force", force_one);
438 /* ----------------------------------------------- */
445 char *hostname = dp->host->hostname;
446 char *diskname = dp->name;
449 get_info(hostname, diskname, &info);
450 if (ISSET(info.command, FORCE_FULL)) {
451 CLR(info.command, FORCE_FULL);
452 if(put_info(hostname, diskname, &info) == 0){
453 g_printf(_("%s: force command for %s:%s cleared.\n"),
454 get_pname(), hostname, diskname);
457 _("%s: force command for %s:%s could not be cleared.\n"),
458 get_pname(), hostname, diskname);
462 g_printf(_("%s: no force command outstanding for %s:%s, unchanged.\n"),
463 get_pname(), hostname, diskname);
472 diskloop(argc, argv, "unforce", unforce_one);
476 /* ----------------------------------------------- */
483 char *hostname = dp->host->hostname;
484 char *diskname = dp->name;
487 get_info(hostname, diskname, &info);
488 SET(info.command, FORCE_BUMP);
489 if (ISSET(info.command, FORCE_NO_BUMP)) {
490 CLR(info.command, FORCE_NO_BUMP);
491 g_printf(_("%s: WARNING: %s:%s FORCE_NO_BUMP command was cleared.\n"),
492 get_pname(), hostname, diskname);
494 if (ISSET(info.command, FORCE_FULL)) {
495 CLR(info.command, FORCE_FULL);
496 g_printf(_("%s: WARNING: %s:%s FORCE_FULL command was cleared.\n"),
497 get_pname(), hostname, diskname);
499 if(put_info(hostname, diskname, &info) == 0) {
500 g_printf(_("%s: %s:%s is set to bump at next run.\n"),
501 get_pname(), hostname, diskname);
503 g_fprintf(stderr, _("%s: %s:%s could not be forced to bump.\n"),
504 get_pname(), hostname, diskname);
514 diskloop(argc, argv, "force-bump", force_bump_one);
518 /* ----------------------------------------------- */
525 char *hostname = dp->host->hostname;
526 char *diskname = dp->name;
529 get_info(hostname, diskname, &info);
530 SET(info.command, FORCE_NO_BUMP);
531 if (ISSET(info.command, FORCE_BUMP)) {
532 CLR(info.command, FORCE_BUMP);
533 g_printf(_("%s: WARNING: %s:%s FORCE_BUMP command was cleared.\n"),
534 get_pname(), hostname, diskname);
536 if(put_info(hostname, diskname, &info) == 0) {
537 g_printf(_("%s: %s:%s is set to not bump at next run.\n"),
538 get_pname(), hostname, diskname);
540 g_fprintf(stderr, _("%s: %s:%s could not be force to not bump.\n"),
541 get_pname(), hostname, diskname);
551 diskloop(argc, argv, "force-no-bump", force_no_bump_one);
555 /* ----------------------------------------------- */
562 char *hostname = dp->host->hostname;
563 char *diskname = dp->name;
566 get_info(hostname, diskname, &info);
567 if (ISSET(info.command, FORCE_BUMP|FORCE_NO_BUMP)) {
568 CLR(info.command, FORCE_BUMP|FORCE_NO_BUMP);
569 if(put_info(hostname, diskname, &info) == 0) {
570 g_printf(_("%s: bump command for %s:%s cleared.\n"),
571 get_pname(), hostname, diskname);
573 g_fprintf(stderr, _("%s: %s:%s bump command could not be cleared.\n"),
574 get_pname(), hostname, diskname);
578 g_printf(_("%s: no bump command outstanding for %s:%s, unchanged.\n"),
579 get_pname(), hostname, diskname);
589 diskloop(argc, argv, "unforce-bump", unforce_bump_one);
593 /* ----------------------------------------------- */
604 g_fprintf(stderr,_("%s: expecting \"reuse <tapelabel> ...\"\n"),
609 for(count=3; count< argc; count++) {
610 tp = lookup_tapelabel(argv[count]);
612 g_fprintf(stderr, _("reuse: tape label %s not found in tapelist.\n"),
616 if( tp->reuse == 0 ) {
618 g_printf(_("%s: marking tape %s as reusable.\n"),
619 get_pname(), argv[count]);
621 g_fprintf(stderr, _("%s: tape %s already reusable.\n"),
622 get_pname(), argv[count]);
626 if(write_tapelist(conf_tapelist)) {
627 error(_("could not write tapelist \"%s\""), conf_tapelist);
641 g_fprintf(stderr,_("%s: expecting \"no-reuse <tapelabel> ...\"\n"),
646 for(count=3; count< argc; count++) {
647 tp = lookup_tapelabel(argv[count]);
649 g_fprintf(stderr, _("no-reuse: tape label %s not found in tapelist.\n"),
653 if( tp->reuse == 1 ) {
655 g_printf(_("%s: marking tape %s as not reusable.\n"),
656 get_pname(), argv[count]);
658 g_fprintf(stderr, _("%s: tape %s already not reusable.\n"),
659 get_pname(), argv[count]);
663 if(write_tapelist(conf_tapelist)) {
664 error(_("could not write tapelist \"%s\""), conf_tapelist);
670 /* ----------------------------------------------- */
678 char *hostname = dp->host->hostname;
679 char *diskname = dp->name;
682 if(get_info(hostname, diskname, &info)) {
683 g_printf(_("%s: %s:%s NOT currently in database.\n"),
684 get_pname(), hostname, diskname);
689 if(del_info(hostname, diskname)) {
690 error(_("couldn't delete %s:%s from database: %s"),
691 hostname, diskname, strerror(errno));
694 g_printf(_("%s: %s:%s deleted from curinfo database.\n"),
695 get_pname(), hostname, diskname);
705 diskloop(argc, argv, "delete", delete_one);
709 _("%s: NOTE: you'll have to remove these from the disklist yourself.\n"),
713 /* ----------------------------------------------- */
724 get_info(dp->host->hostname, dp->name, &info);
726 g_printf(_("\nCurrent info for %s %s:\n"), dp->host->hostname, dp->name);
727 if (ISSET(info.command, FORCE_FULL))
728 g_printf(_(" (Forcing to level 0 dump at next run)\n"));
729 if (ISSET(info.command, FORCE_BUMP))
730 g_printf(_(" (Forcing bump at next run)\n"));
731 if (ISSET(info.command, FORCE_NO_BUMP))
732 g_printf(_(" (Forcing no-bump at next run)\n"));
733 g_printf(_(" Stats: dump rates (kps), Full: %5.1lf, %5.1lf, %5.1lf\n"),
734 info.full.rate[0], info.full.rate[1], info.full.rate[2]);
735 g_printf(_(" Incremental: %5.1lf, %5.1lf, %5.1lf\n"),
736 info.incr.rate[0], info.incr.rate[1], info.incr.rate[2]);
737 g_printf(_(" compressed size, Full: %5.1lf%%,%5.1lf%%,%5.1lf%%\n"),
738 info.full.comp[0]*100, info.full.comp[1]*100, info.full.comp[2]*100);
739 g_printf(_(" Incremental: %5.1lf%%,%5.1lf%%,%5.1lf%%\n"),
740 info.incr.comp[0]*100, info.incr.comp[1]*100, info.incr.comp[2]*100);
742 g_printf(_(" Dumps: lev datestmp tape file origK compK secs\n"));
743 for(lev = 0, sp = &info.inf[0]; lev < 9; lev++, sp++) {
744 if(sp->date < (time_t)0 && sp->label[0] == '\0') continue;
745 tm = localtime(&sp->date);
747 g_printf(_(" %d %04d%02d%02d %-15s %lld %lld %lld %jd\n"),
748 lev, tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
750 (long long)sp->filenum,
752 (long long)sp->csize,
755 g_printf(_(" %d BAD-DATE %-15s %lld %lld %lld %jd\n"),
758 (long long)sp->filenum,
760 (long long)sp->csize,
775 diskloop(argc, argv, "info", info_one);
777 for(dp = diskq.head; dp != NULL; dp = dp->next)
781 /* ----------------------------------------------- */
792 if(get_info(hp->hostname, dp->name, &info)) {
793 g_printf(_("new disk %s:%s ignored.\n"), hp->hostname, dp->name);
796 days = next_level0(dp, &info);
798 g_printf(_("Overdue %2d day%s %s:%s\n"),
799 -days, (-days == 1) ? ": " : "s:",
800 hp->hostname, dp->name);
803 g_printf(_("Due today: %s:%s\n"), hp->hostname, dp->name);
806 g_printf(_("Due in %2d day%s %s:%s\n"), days,
807 (days == 1) ? ": " : "s:",
808 hp->hostname, dp->name);
822 diskloop(argc, argv, "due", due_one);
824 for(dp = diskq.head; dp != NULL; dp = dp->next)
828 /* ----------------------------------------------- */
842 if(argc > 4 && strcmp(argv[3],"--days") == 0) {
843 nb_days = atoi(argv[4]);
845 g_printf(_("days must be an integer bigger than 0\n"));
852 runtapes = getconf_int(CNF_RUNTAPES);
853 tp = lookup_last_reusable_tape(0);
856 for ( j=0 ; j < nb_days ; j++ ) {
858 for ( i=0 ; i < runtapes ; i++ ) {
860 g_fprintf(stdout, _("The next Amanda run should go onto "));
862 if (nb_new_tape > 0) {
863 if (nb_new_tape == 1)
864 g_fprintf(stdout, _("1 new tape.\n"));
866 g_fprintf(stdout, _("%d new tapes.\n"), nb_new_tape);
867 g_fprintf(stdout, " ");
870 g_fprintf(stdout, _("tape %s or a new tape.\n"), tp->label);
872 g_fprintf(stdout, " ");
878 tp = lookup_last_reusable_tape(skip);
880 if (nb_new_tape > 0) {
881 if (nb_new_tape == 1)
882 g_fprintf(stdout, _("1 new tape.\n"));
884 g_fprintf(stdout, _("%d new tapes.\n"), nb_new_tape);
888 print_new_tapes(stdout, nb_days * runtapes);
891 /* ----------------------------------------------- */
899 struct balance_stats {
901 off_t origsize, outsize;
903 int conf_runspercycle, conf_dumpcycle;
904 int seq, runs_per_cycle, overdue, max_overdue;
905 int later, total, balance, distinct;
906 double fseq, disk_dumpcycle;
908 off_t total_balanced, balanced;
912 conf_dumpcycle = getconf_int(CNF_DUMPCYCLE);
913 conf_runspercycle = getconf_int(CNF_RUNSPERCYCLE);
914 later = conf_dumpcycle;
918 if(argc > 4 && strcmp(argv[3],"--days") == 0) {
919 later = atoi(argv[4]);
920 if(later < 0) later = conf_dumpcycle;
922 if(later > 10000) later = 10000;
924 if(conf_runspercycle == 0) {
925 runs_per_cycle = conf_dumpcycle;
926 } else if(conf_runspercycle == -1 ) {
927 runs_per_cycle = guess_runs_from_tapelist();
929 runs_per_cycle = conf_runspercycle;
931 if (runs_per_cycle <= 0) {
937 distinct = later + 3;
939 sp = (struct balance_stats *)
940 alloc(SIZEOF(struct balance_stats) * (distinct+1));
942 for(seq=0; seq <= distinct; seq++) {
944 sp[seq].origsize = sp[seq].outsize = (off_t)0;
947 for(dp = diskq.head; dp != NULL; dp = dp->next) {
948 if(get_info(dp->host->hostname, dp->name, &info)) {
949 g_printf(_("new disk %s:%s ignored.\n"), dp->host->hostname, dp->name);
952 if (dp->strategy == DS_NOFULL) {
955 sp[distinct].disks++;
956 sp[distinct].origsize += info.inf[0].size/(off_t)unitdivisor;
957 sp[distinct].outsize += info.inf[0].csize/(off_t)unitdivisor;
960 if(dp->dumpcycle == 0) {
961 sp[balance].origsize += (info.inf[0].size/(off_t)unitdivisor) * (off_t)runs_per_cycle;
962 sp[balance].outsize += (info.inf[0].csize/(off_t)unitdivisor) * (off_t)runs_per_cycle;
965 sp[balance].origsize += (info.inf[0].size/(off_t)unitdivisor) *
966 (off_t)(conf_dumpcycle / dp->dumpcycle);
967 sp[balance].outsize += (info.inf[0].csize/(off_t)unitdivisor) *
968 (off_t)(conf_dumpcycle / dp->dumpcycle);
971 disk_dumpcycle = (double)dp->dumpcycle;
972 if(dp->dumpcycle <= 0)
973 disk_dumpcycle = ((double)conf_dumpcycle) / ((double)runs_per_cycle);
975 seq = next_level0(dp, &info);
980 if (-seq > max_overdue)
990 sp[seq].origsize += info.inf[0].size/(off_t)unitdivisor;
991 sp[seq].outsize += info.inf[0].csize/(off_t)unitdivisor;
995 sp[total].origsize += info.inf[0].size/(off_t)unitdivisor;
996 sp[total].outsize += info.inf[0].csize/(off_t)unitdivisor;
999 /* See, if there's another run in this dumpcycle */
1000 fseq += disk_dumpcycle;
1002 } while (seq < later);
1005 if(sp[total].outsize == (off_t)0 && sp[later].outsize == (off_t)0) {
1006 g_printf(_("\nNo data to report on yet.\n"));
1011 balanced = sp[balance].outsize / (off_t)runs_per_cycle;
1012 if(conf_dumpcycle == later) {
1013 total_balanced = sp[total].outsize / (off_t)runs_per_cycle;
1016 total_balanced = (((sp[total].outsize/(off_t)1024) * (off_t)conf_dumpcycle)
1017 / (off_t)(runs_per_cycle * later)) * (off_t)1024;
1021 g_printf(_("\n due-date #fs orig %cB out %cB balance\n"),
1022 displayunit[0], displayunit[0]);
1023 g_printf("----------------------------------------------\n");
1024 for(seq = 0; seq < later; seq++) {
1025 if(sp[seq].disks == 0 &&
1026 ((seq > 0 && sp[seq-1].disks == 0) ||
1027 ((seq < later-1) && sp[seq+1].disks == 0))) {
1035 g_printf(_("%-9.9s %3d %10lld %10lld "),
1036 seqdatestr(seq), sp[seq].disks,
1037 (long long)sp[seq].origsize,
1038 (long long)sp[seq].outsize);
1039 if(!sp[seq].outsize) g_printf(" --- \n");
1040 else g_printf(_("%+8.1lf%%\n"),
1041 (((double)sp[seq].outsize - (double)balanced) * 100.0 /
1046 if(sp[later].disks != 0) {
1047 g_printf(_("later %3d %10lld %10lld "),
1049 (long long)sp[later].origsize,
1050 (long long)sp[later].outsize);
1051 if(!sp[later].outsize) g_printf(" --- \n");
1052 else g_printf(_("%+8.1lf%%\n"),
1053 (((double)sp[later].outsize - (double)balanced) * 100.0 /
1056 g_printf("----------------------------------------------\n");
1057 g_printf(_("TOTAL %3d %10lld %10lld %9lld\n"),
1059 (long long)sp[total].origsize,
1060 (long long)sp[total].outsize,
1061 (long long)total_balanced);
1062 if (sp[balance].origsize != sp[total].origsize ||
1063 sp[balance].outsize != sp[total].outsize ||
1064 balanced != total_balanced) {
1065 g_printf(_("BALANCED %10lld %10lld %9lld\n"),
1066 (long long)sp[balance].origsize,
1067 (long long)sp[balance].outsize,
1068 (long long)balanced);
1070 if (sp[distinct].disks != sp[total].disks) {
1071 g_printf(_("DISTINCT %3d %10lld %10lld\n"),
1073 (long long)sp[distinct].origsize,
1074 (long long)sp[distinct].outsize);
1076 g_printf(plural(_(" (estimated %d run per dumpcycle)\n"),
1077 _(" (estimated %d runs per dumpcycle)\n"),
1081 g_printf(plural(_(" (%d filesystem overdue."),
1082 _(" (%d filesystems overdue."), overdue),
1084 g_printf(plural(_(" The most being overdue %d day.)\n"),
1085 _(" The most being overdue %d days.)\n"), max_overdue),
1092 /* ----------------------------------------------- */
1100 char *sort_order = NULL;
1101 find_result_t *output_find;
1106 _("%s: expecting \"find [--sort <hkdlpbfw>] [hostname [<disk>]]*\"\n"),
1112 sort_order = newstralloc(sort_order, DEFAULT_SORT_ORDER);
1113 if(argc > 4 && strcmp(argv[3],"--sort") == 0) {
1114 size_t i, valid_sort=1;
1116 for(i = strlen(argv[4]); i > 0; i--) {
1117 switch (argv[4][i - 1]) {
1135 default: valid_sort=0;
1139 sort_order = newstralloc(sort_order, argv[4]);
1141 g_printf(_("Invalid sort order: %s\n"), argv[4]);
1142 g_printf(_("Use default sort order: %s\n"), sort_order);
1148 errstr = match_disklist(&diskq, argc-(start_argc-1), argv+(start_argc-1));
1150 output_find = find_dump(&diskq); /* Add deleted dump to diskq */
1151 if(argc-(start_argc-1) > 0) {
1153 free_find_result(&output_find);
1154 errstr = match_disklist(&diskq, argc-(start_argc-1),
1155 argv+(start_argc-1));
1157 g_printf("%s", errstr);
1160 output_find = find_dump(NULL);
1161 } else if (errstr) {
1162 g_printf("%s", errstr);
1166 sort_find_result(sort_order, &output_find);
1167 print_find_result(output_find);
1168 free_find_result(&output_find);
1174 /* ------------------------ */
1182 GSList * file_list = NULL;
1186 flags = CMDLINE_PARSE_DATESTAMP;
1187 if (allow_empty) flags |= CMDLINE_EMPTY_TO_WILDCARD;
1188 dumplist = cmdline_parse_dumpspecs(argc, argv, flags);
1190 file_list = cmdline_match_holding(dumplist);
1191 dumpspec_list_free(dumplist);
1196 /* Given a file header, find the history element in curinfo most likely
1197 * corresponding to that dump (this is not an exact science).
1199 * @param info: the info_t element for this DLE
1200 * @param file: the header of the file
1201 * @returns: index of the matching history element, or -1 if not found
1204 holding_file_find_history(
1208 int matching_hist_idx = -1;
1212 /* Begin by trying to find the history element matching this dump.
1213 * The datestamp on the dump is for the entire run of amdump, while the
1214 * 'date' in the history element of 'info' is the time the dump itself
1215 * began. A matching history element, then, is the earliest element
1216 * with a 'date' equal to or later than the date of the dumpfile.
1218 * We compare using formatted datestamps; even using seconds since epoch,
1219 * we would still face timezone issues, and have to do a reverse (timezone
1220 * to gmt) translation.
1223 /* get to the end of the history list and search backward */
1224 for (nhist = 0; info->history[nhist].level > -1; nhist++) /* empty loop */;
1225 for (i = nhist-1; i > -1; i--) {
1226 char *info_datestamp = get_timestamp_from_time(info->history[i].date);
1227 int order = strcmp(file->datestamp, info_datestamp);
1228 amfree(info_datestamp);
1231 /* only a match if the levels are equal */
1232 if (info->history[i].level == file->dumplevel) {
1233 matching_hist_idx = i;
1239 return matching_hist_idx;
1242 /* A holding file is 'outdated' if a subsequent dump of the same DLE was made
1243 * at the same level or a lower leve; for example, a level 2 dump is outdated if
1244 * there is a subsequent level 2, or a subsequent level 0.
1246 * @param file: the header of the file
1247 * @returns: true if the file is outdated
1250 holding_file_is_outdated(
1254 int matching_hist_idx;
1256 if (get_info(file->name, file->disk, &info) == -1) {
1257 return 0; /* assume it's not outdated */
1260 /* if the last level is less than the level of this dump, then
1262 if (info.last_level < file->dumplevel)
1265 /* otherwise, we need to see if this dump is the last at its level */
1266 matching_hist_idx = holding_file_find_history(&info, file);
1267 if (matching_hist_idx == -1) {
1268 return 0; /* assume it's not outdated */
1271 /* compare the date of the history element with the most recent date
1272 * for this level. If they match, then this is the last dump at this
1273 * level, and we checked above for more recent lower-level dumps, so
1274 * the dump is not outdated. */
1275 if (info.history[matching_hist_idx].date ==
1276 info.inf[info.history[matching_hist_idx].level].date) {
1284 remove_holding_file_from_catalog(
1287 static int warnings_printed; /* only print once per invocation */
1290 int matching_hist_idx = -1;
1291 history_t matching_hist; /* will be a copy */
1294 if (!holding_file_get_dumpfile(filename, &file)) {
1295 g_printf(_("Could not read holding file %s\n"), filename);
1299 if (get_info(file.name, file.disk, &info) == -1) {
1300 g_printf(_("WARNING: No curinfo record for %s:%s\n"), file.name, file.disk);
1301 dumpfile_free_data(&file);
1302 return 1; /* not an error */
1305 matching_hist_idx = holding_file_find_history(&info, &file);
1307 if (matching_hist_idx == -1) {
1308 g_printf(_("WARNING: No dump matching %s found in curinfo.\n"), filename);
1309 dumpfile_free_data(&file);
1310 return 1; /* not an error */
1314 matching_hist = info.history[matching_hist_idx];
1316 /* Remove the history element itself before doing the stats */
1317 for (i = matching_hist_idx; i < NB_HISTORY; i++) {
1318 info.history[i] = info.history[i+1];
1320 info.history[NB_HISTORY].level = -1;
1322 /* Remove stats for that history element, if necessary. Doing so
1323 * will result in an inconsistent set of backups, so we warn the
1324 * user and adjust last_level to make the next dump get us a
1325 * consistent picture. */
1326 if (matching_hist.date == info.inf[matching_hist.level].date) {
1327 /* search for an earlier dump at this level */
1328 for (i = matching_hist_idx; info.history[i].level > -1; i++) {
1329 if (info.history[i].level == matching_hist.level)
1333 if (info.history[i].level < 0) {
1334 /* not found => zero it out */
1335 info.inf[matching_hist.level].date = (time_t)-1; /* flag as not set */
1336 info.inf[matching_hist.level].label[0] = '\0';
1338 /* found => reconstruct stats as best we can */
1339 info.inf[matching_hist.level].size = info.history[i].size;
1340 info.inf[matching_hist.level].csize = info.history[i].csize;
1341 info.inf[matching_hist.level].secs = info.history[i].secs;
1342 info.inf[matching_hist.level].date = info.history[i].date;
1343 info.inf[matching_hist.level].filenum = 0; /* we don't know */
1344 info.inf[matching_hist.level].label[0] = '\0'; /* we don't know */
1347 /* set last_level to the level we just deleted, and set command
1348 * appropriately to make sure planner does a new dump at this level
1350 info.last_level = matching_hist.level;
1351 if (info.last_level == 0) {
1352 g_printf(_("WARNING: Deleting the most recent full dump; forcing a full dump at next run.\n"));
1353 SET(info.command, FORCE_FULL);
1355 g_printf(_("WARNING: Deleting the most recent level %d dump; forcing a level %d dump or \nWARNING: lower at next run.\n"),
1356 info.last_level, info.last_level);
1357 SET(info.command, FORCE_NO_BUMP);
1360 /* Search for and display any subsequent runs that depended on this one */
1361 warnings_printed = 0;
1362 for (i = matching_hist_idx-1; i >= 0; i--) {
1364 if (info.history[i].level <= matching_hist.level) break;
1366 datestamp = get_timestamp_from_time(info.history[i].date);
1367 g_printf(_("WARNING: Level %d dump made %s can no longer be accurately restored.\n"),
1368 info.history[i].level, datestamp);
1371 warnings_printed = 1;
1373 if (warnings_printed)
1374 g_printf(_("WARNING: (note, dates shown above are for dumps, and may be later than the\nWARNING: corresponding run date)\n"));
1377 /* recalculate consecutive_runs based on the history: find the first run
1378 * at this level, and then count the consecutive runs at that level. This
1379 * number may be zero (if we just deleted the last run at this level) */
1380 info.consecutive_runs = 0;
1381 for (i = 0; info.history[i].level >= 0; i++) {
1382 if (info.history[i].level == info.last_level) break;
1384 while (info.history[i+info.consecutive_runs].level == info.last_level)
1385 info.consecutive_runs++;
1387 /* this function doesn't touch the performance stats */
1389 /* write out the changes */
1390 if (put_info(file.name, file.disk, &info) == -1) {
1391 g_printf(_("Could not write curinfo record for %s:%s\n"), file.name, file.disk);
1392 dumpfile_free_data(&file);
1396 dumpfile_free_data(&file);
1407 enum { HOLDING_USAGE, HOLDING_LIST, HOLDING_DELETE } action = HOLDING_USAGE;
1409 int outdated_list = 0;
1413 action = HOLDING_USAGE;
1414 else if (strcmp(argv[3], "list") == 0 && argc >= 4)
1415 action = HOLDING_LIST;
1416 else if (strcmp(argv[3], "delete") == 0 && argc > 4)
1417 action = HOLDING_DELETE;
1422 _("%s: expecting \"holding list [-l] [-d]\" or \"holding delete <host> [ .. ]\"\n"),
1428 argc -= 4; argv += 4;
1429 while (argc && argv[0][0] == '-') {
1430 switch (argv[0][1]) {
1434 case 'd': /* have to use '-d', and not '-o', because of parse_config */
1438 g_fprintf(stderr, _("Unknown option -%c\n"), argv[0][1]);
1447 g_printf("%-10s %-2s %-4s %s\n",
1448 _("size (kB)"), _("lv"), _("outd"), _("dump specification"));
1451 file_list = get_file_list(argc, argv, 1);
1452 for (li = file_list; li != NULL; li = li->next) {
1456 if (!holding_file_get_dumpfile((char *)li->data, &file)) {
1457 g_fprintf(stderr, _("Error reading %s\n"), (char *)li->data);
1461 is_outdated = holding_file_is_outdated(&file);
1463 dumpstr = cmdline_format_dumpspec_components(file.name, file.disk, file.datestamp, NULL);
1464 /* only print this entry if we're printing everything, or if it's outdated and
1465 * we're only printing outdated files (-o) */
1466 if (!outdated_list || is_outdated) {
1468 g_printf("%-10lld %-2d %-4s %s\n",
1469 (long long)holding_file_size((char *)li->data, 0),
1471 is_outdated? " *":"",
1474 g_printf("%s\n", dumpstr);
1478 dumpfile_free_data(&file);
1480 g_slist_free_full(file_list);
1483 case HOLDING_DELETE:
1484 argc -= 4; argv += 4;
1486 file_list = get_file_list(argc, argv, 0);
1487 for (li = file_list; li != NULL; li = li->next) {
1488 g_fprintf(stderr, _("Deleting '%s'\n"), (char *)li->data);
1489 /* remove it from the catalog */
1490 if (!remove_holding_file_from_catalog((char *)li->data))
1494 if (!holding_file_unlink((char *)li->data)) {
1495 error(_("Could not delete '%s'"), (char *)li->data);
1498 g_slist_free_full(file_list);
1504 /* ------------------------ */
1507 /* shared code with planner.c */
1513 int bump = getconf_int(CNF_BUMPSIZE);
1514 double mult = getconf_real(CNF_BUMPMULT);
1517 bump = (int)((double)bump * mult);
1527 int conf_bumppercent = getconf_int(CNF_BUMPPERCENT);
1528 double conf_bumpmult = getconf_real(CNF_BUMPMULT);
1530 (void)argc; /* Quiet unused parameter warning */
1531 (void)argv; /* Quiet unused parameter warning */
1533 g_printf(_("Current bump parameters:\n"));
1534 if(conf_bumppercent == 0) {
1535 g_printf(_(" bumpsize %5d KB\t- minimum savings (threshold) to bump level 1 -> 2\n"),
1536 getconf_int(CNF_BUMPSIZE));
1537 g_printf(_(" bumpdays %5d\t- minimum days at each level\n"),
1538 getconf_int(CNF_BUMPDAYS));
1539 g_printf(_(" bumpmult %5.5lg\t- threshold = bumpsize * bumpmult**(level-1)\n\n"),
1542 g_printf(_(" Bump -> To Threshold\n"));
1543 for(l = 1; l < 9; l++)
1544 g_printf(_("\t%d -> %d %9d KB\n"), l, l+1, bump_thresh(l));
1548 double bumppercent = (double)conf_bumppercent;
1550 g_printf(_(" bumppercent %3d %%\t- minimum savings (threshold) to bump level 1 -> 2\n"),
1552 g_printf(_(" bumpdays %5d\t- minimum days at each level\n"),
1553 getconf_int(CNF_BUMPDAYS));
1554 g_printf(_(" bumpmult %5.5lg\t- threshold = disk_size * bumppercent * bumpmult**(level-1)\n\n"),
1556 g_printf(_(" Bump -> To Threshold\n"));
1557 for(l = 1; l < 9; l++) {
1558 g_printf(_("\t%d -> %d %7.2lf %%\n"), l, l+1, bumppercent);
1559 bumppercent *= conf_bumpmult;
1560 if(bumppercent >= 100.000) { bumppercent = 100.0;}
1566 /* ----------------------------------------------- */
1568 void export_one(disk_t *dp);
1577 char hostname[MAX_HOSTNAME_LENGTH+1];
1580 g_printf(_("CURINFO Version %s CONF %s\n"), VERSION, getconf_str(CNF_ORG));
1583 if(gethostname(hostname, SIZEOF(hostname)-1) == -1) {
1584 error(_("could not determine host name: %s\n"), strerror(errno));
1587 hostname[SIZEOF(hostname)-1] = '\0';
1588 g_printf(_("# Generated by:\n# host: %s\n# date: %s"),
1589 hostname, ctime(&curtime));
1591 g_printf(_("# command:"));
1592 for(i = 0; i < argc; i++)
1593 g_printf(_(" %s"), argv[i]);
1595 g_printf(_("\n# This file can be merged back in with \"amadmin import\".\n"));
1596 g_printf(_("# Edit only with care.\n"));
1599 diskloop(argc, argv, "export", export_one);
1600 else for(dp = diskq.head; dp != NULL; dp = dp->next)
1611 if(get_info(dp->host->hostname, dp->name, &info)) {
1612 g_fprintf(stderr, _("Warning: no curinfo record for %s:%s\n"),
1613 dp->host->hostname, dp->name);
1616 g_printf(_("host: %s\ndisk: %s\n"), dp->host->hostname, dp->name);
1617 g_printf(_("command: %u\n"), info.command);
1618 g_printf(_("last_level: %d\n"),info.last_level);
1619 g_printf(_("consecutive_runs: %d\n"),info.consecutive_runs);
1620 g_printf(_("full-rate:"));
1621 for(i=0;i<AVG_COUNT;i++) g_printf(_(" %lf"), info.full.rate[i]);
1622 g_printf(_("\nfull-comp:"));
1623 for(i=0;i<AVG_COUNT;i++) g_printf(_(" %lf"), info.full.comp[i]);
1625 g_printf(_("\nincr-rate:"));
1626 for(i=0;i<AVG_COUNT;i++) g_printf(_(" %lf"), info.incr.rate[i]);
1627 g_printf(_("\nincr-comp:"));
1628 for(i=0;i<AVG_COUNT;i++) g_printf(_(" %lf"), info.incr.comp[i]);
1630 for(l=0;l<DUMP_LEVELS;l++) {
1631 if(info.inf[l].date < (time_t)0 && info.inf[l].label[0] == '\0') continue;
1632 g_printf(_("stats: %d %lld %lld %jd %jd %lld %s\n"), l,
1633 (long long)info.inf[l].size,
1634 (long long)info.inf[l].csize,
1635 (intmax_t)info.inf[l].secs,
1636 (intmax_t)info.inf[l].date,
1637 (long long)info.inf[l].filenum,
1640 for(l=0;info.history[l].level > -1;l++) {
1641 g_printf(_("history: %d %lld %lld %jd\n"),
1642 info.history[l].level,
1643 (long long)info.history[l].size,
1644 (long long)info.history[l].csize,
1645 (intmax_t)info.history[l].date);
1650 /* ----------------------------------------------- */
1652 int import_one(void);
1653 char *impget_line(void);
1671 (void)argc; /* Quiet unused parameter warning */
1672 (void)argv; /* Quiet unused parameter warning */
1674 /* process header line */
1676 if((line = agets(stdin)) == NULL) {
1677 g_fprintf(stderr, _("%s: empty input.\n"), get_pname());
1685 if(strncmp_const_skip(s - 1, "CURINFO Version", s, ch) != 0) {
1689 skip_whitespace(s, ch);
1691 || sscanf(s - 1, "%d.%d.%d", &vers_maj, &vers_min, &vers_patch) != 3) {
1695 skip_integer(s, ch); /* skip over major */
1700 skip_integer(s, ch); /* skip over minor */
1705 skip_integer(s, ch); /* skip over patch */
1711 skip_non_whitespace(s, ch);
1715 skip_whitespace(s, ch); /* find the org keyword */
1716 if(ch == '\0' || strncmp_const_skip(s - 1, "CONF", s, ch) != 0) {
1722 skip_whitespace(s, ch); /* find the org string */
1729 newer = (vers_maj != VERSION_MAJOR)? vers_maj > VERSION_MAJOR :
1730 (vers_min != VERSION_MINOR)? vers_min > VERSION_MINOR :
1731 vers_patch > VERSION_PATCH;
1734 _("%s: WARNING: input is from newer Amanda version: %d.%d.%d.\n"),
1735 get_pname(), vers_maj, vers_min, vers_patch);
1738 if(strcmp(org, getconf_str(CNF_ORG)) != 0) {
1739 g_fprintf(stderr, _("%s: WARNING: input is from different org: %s\n"),
1752 /*@i@*/ amfree(line);
1753 g_fprintf(stderr, _("%s: bad CURINFO header line in input: %s.\n"),
1755 g_fprintf(stderr, _(" Was the input in \"amadmin export\" format?\n"));
1770 char *hostname = NULL;
1771 char *diskname = NULL;
1772 long long off_t_tmp;
1773 long long time_t_tmp;
1775 memset(&info, 0, SIZEOF(info_t));
1777 for(level = 0; level < DUMP_LEVELS; level++) {
1778 info.inf[level].date = (time_t)-1;
1781 /* get host: disk: command: lines */
1783 hostname = diskname = NULL;
1785 if((line = impget_line()) == NULL) return 0; /* nothing there */
1789 skip_whitespace(s, ch);
1790 if(ch == '\0' || strncmp_const_skip(s - 1, "host:", s, ch) != 0) goto parse_err;
1791 skip_whitespace(s, ch);
1792 if(ch == '\0') goto parse_err;
1794 skip_non_whitespace(s, ch);
1796 hostname = stralloc(fp);
1799 skip_whitespace(s, ch);
1802 if((line = impget_line()) == NULL) goto shortfile_err;
1805 skip_whitespace(s, ch);
1807 if(strncmp_const_skip(s - 1, "disk:", s, ch) != 0) goto parse_err;
1808 skip_whitespace(s, ch);
1809 if(ch == '\0') goto parse_err;
1811 skip_non_whitespace(s, ch);
1813 diskname = stralloc(fp);
1817 if((line = impget_line()) == NULL) goto shortfile_err;
1818 if(sscanf(line, "command: %u", &info.command) != 1) goto parse_err;
1820 /* get last_level and consecutive_runs */
1823 if((line = impget_line()) == NULL) goto shortfile_err;
1824 rc = sscanf(line, "last_level: %d", &info.last_level);
1827 if((line = impget_line()) == NULL) goto shortfile_err;
1828 if(sscanf(line, "consecutive_runs: %d", &info.consecutive_runs) != 1) goto parse_err;
1830 if((line = impget_line()) == NULL) goto shortfile_err;
1833 /* get rate: and comp: lines for full dumps */
1835 rc = sscanf(line, "full-rate: %lf %lf %lf",
1836 &info.full.rate[0], &info.full.rate[1], &info.full.rate[2]);
1837 if(rc != 3) goto parse_err;
1840 if((line = impget_line()) == NULL) goto shortfile_err;
1841 rc = sscanf(line, "full-comp: %lf %lf %lf",
1842 &info.full.comp[0], &info.full.comp[1], &info.full.comp[2]);
1843 if(rc != 3) goto parse_err;
1845 /* get rate: and comp: lines for incr dumps */
1848 if((line = impget_line()) == NULL) goto shortfile_err;
1849 rc = sscanf(line, "incr-rate: %lf %lf %lf",
1850 &info.incr.rate[0], &info.incr.rate[1], &info.incr.rate[2]);
1851 if(rc != 3) goto parse_err;
1854 if((line = impget_line()) == NULL) goto shortfile_err;
1855 rc = sscanf(line, "incr-comp: %lf %lf %lf",
1856 &info.incr.comp[0], &info.incr.comp[1], &info.incr.comp[2]);
1857 if(rc != 3) goto parse_err;
1859 /* get stats for dump levels */
1863 if((line = impget_line()) == NULL) goto shortfile_err;
1864 if(strncmp_const(line, "//") == 0) {
1868 if(strncmp_const(line, "history:") == 0) {
1872 memset(&onestat, 0, SIZEOF(onestat));
1877 skip_whitespace(s, ch);
1878 if(ch == '\0' || strncmp_const_skip(s - 1, "stats:", s, ch) != 0) {
1882 skip_whitespace(s, ch);
1883 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
1886 skip_integer(s, ch);
1888 skip_whitespace(s, ch);
1889 if(ch == '\0' || sscanf(s - 1, "%lld", &off_t_tmp) != 1) {
1892 onestat.size = (off_t)off_t_tmp;
1893 skip_integer(s, ch);
1895 skip_whitespace(s, ch);
1896 if(ch == '\0' || sscanf(s - 1, "%lld", &off_t_tmp) != 1) {
1899 onestat.csize = (off_t)off_t_tmp;
1900 skip_integer(s, ch);
1902 skip_whitespace(s, ch);
1903 if(ch == '\0' || sscanf(s - 1, "%lld", &time_t_tmp) != 1) {
1906 onestat.secs = (time_t)time_t_tmp;
1907 skip_integer(s, ch);
1909 skip_whitespace(s, ch);
1910 if(ch == '\0' || sscanf(s - 1, "%lld", &time_t_tmp) != 1) {
1913 /* time_t not guarranteed to be long */
1914 /*@i1@*/ onestat.date = (time_t)time_t_tmp;
1915 skip_integer(s, ch);
1917 skip_whitespace(s, ch);
1919 if(sscanf(s - 1, "%lld", &off_t_tmp) != 1) {
1922 onestat.filenum = (off_t)off_t_tmp;
1923 skip_integer(s, ch);
1925 skip_whitespace(s, ch);
1927 if (onestat.filenum != 0)
1929 onestat.label[0] = '\0';
1931 strncpy(onestat.label, s - 1, SIZEOF(onestat.label)-1);
1932 onestat.label[SIZEOF(onestat.label)-1] = '\0';
1936 if(level < 0 || level > 9) goto parse_err;
1938 info.inf[level] = onestat;
1941 for(i=0;i<=NB_HISTORY;i++) {
1942 info.history[i].level = -2;
1945 history_t onehistory;
1947 if(line[0] == '/' && line[1] == '/') {
1948 info.history[nb_history].level = -2;
1952 memset(&onehistory, 0, SIZEOF(onehistory));
1955 if(strncmp_const_skip(line, "history:", s, ch) != 0) {
1959 skip_whitespace(s, ch);
1960 if(ch == '\0' || sscanf((s - 1), "%d", &onehistory.level) != 1) {
1963 skip_integer(s, ch);
1965 skip_whitespace(s, ch);
1966 if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) {
1969 onehistory.size = (off_t)off_t_tmp;
1970 skip_integer(s, ch);
1972 skip_whitespace(s, ch);
1973 if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) {
1976 onehistory.csize = (off_t)off_t_tmp;
1977 skip_integer(s, ch);
1979 skip_whitespace(s, ch);
1980 if((ch == '\0') || sscanf((s - 1), "%lld", &time_t_tmp) != 1) {
1983 /* time_t not guarranteed to be long */
1984 /*@i1@*/ onehistory.date = (time_t)time_t_tmp;
1985 skip_integer(s, ch);
1987 info.history[nb_history++] = onehistory;
1989 if((line = impget_line()) == NULL) goto shortfile_err;
1991 /*@i@*/ amfree(line);
1993 /* got a full record, now write it out to the database */
1995 if(put_info(hostname, diskname, &info)) {
1996 g_fprintf(stderr, _("%s: error writing record for %s:%s\n"),
1997 get_pname(), hostname, diskname);
2004 /*@i@*/ amfree(line);
2007 g_fprintf(stderr, _("%s: parse error reading import record.\n"), get_pname());
2011 /*@i@*/ amfree(line);
2014 g_fprintf(stderr, _("%s: short file reading import record.\n"), get_pname());
2025 for(; (line = agets(stdin)) != NULL; free(line)) {
2029 skip_whitespace(s, ch);
2031 /* ignore comment lines */
2034 /* found non-blank, return line */
2037 /* otherwise, a blank line, so keep going */
2040 g_fprintf(stderr, _("%s: reading stdin: %s\n"),
2041 get_pname(), strerror(errno));
2046 /* ----------------------------------------------- */
2055 identlist_t pp_scriptlist;
2056 estimatelist_t estimates;
2061 g_printf("line %d:\n", dp->line);
2063 g_printf(" host %s:\n", hp->hostname);
2064 g_printf(" interface %s\n",
2065 interface_name(ip->config)[0] ? interface_name(ip->config) : "default");
2066 g_printf(" disk %s:\n", dp->name);
2067 if (dp->device) g_printf(" device %s\n", dp->device);
2069 g_printf(" program \"%s\"\n", dp->program);
2070 if (dp->application)
2071 g_printf(" application \"%s\"\n", dp->application);
2072 g_printf(" data-path %s\n", data_path_to_string(dp->data_path));
2073 if (dp->exclude_file != NULL && dp->exclude_file->nb_element > 0) {
2074 g_printf(" exclude file");
2075 for(excl = dp->exclude_file->first; excl != NULL; excl = excl->next) {
2076 g_printf(" \"%s\"", excl->name);
2080 if (dp->exclude_list != NULL && dp->exclude_list->nb_element > 0) {
2081 g_printf(" exclude list");
2082 if(dp->exclude_optional) g_printf(" optional");
2083 for(excl = dp->exclude_list->first; excl != NULL; excl = excl->next) {
2084 g_printf(" \"%s\"", excl->name);
2088 if (dp->include_file != NULL && dp->include_file->nb_element > 0) {
2089 g_printf(" include file");
2090 for(excl = dp->include_file->first; excl != NULL; excl = excl->next) {
2091 g_printf(" \"%s\"", excl->name);
2095 if (dp->include_list != NULL && dp->include_list->nb_element > 0) {
2096 g_printf(" include list");
2097 if (dp->include_optional) g_printf(" optional");
2098 for(excl = dp->include_list->first; excl != NULL; excl = excl->next) {
2099 g_printf(" \"%s\"", excl->name);
2103 g_printf(" priority %d\n", dp->priority);
2104 g_printf(" dumpcycle %d\n", dp->dumpcycle);
2105 g_printf(" maxdumps %d\n", dp->maxdumps);
2106 g_printf(" maxpromoteday %d\n", dp->maxpromoteday);
2107 if (dp->bumppercent > 0) {
2108 g_printf(" bumppercent %d\n", dp->bumppercent);
2111 g_printf(" bumpsize %lld\n",
2112 (long long)dp->bumpsize);
2114 g_printf(" bumpdays %d\n", dp->bumpdays);
2115 g_printf(" bumpmult %lf\n", dp->bumpmult);
2117 g_printf(" strategy ");
2118 switch(dp->strategy) {
2123 g_printf("STANDARD\n");
2126 g_printf("NOFULL\n");
2129 g_printf("NOINC\n");
2132 g_printf("HANOI\n");
2135 g_printf("INCRONLY\n");
2138 g_printf(" ignore %s\n", (dp->ignore? "YES" : "NO"));
2139 g_printf(" estimate ");
2140 estimates = dp->estimatelist;
2142 switch((estimate_t)GPOINTER_TO_INT(estimates->data)) {
2150 g_printf("CALCSIZE");
2155 estimates = estimates->next;
2161 g_printf(" compress ");
2162 switch(dp->compress) {
2167 g_printf("CLIENT FAST\n");
2170 g_printf("CLIENT BEST\n");
2173 g_printf("CLIENT CUSTOM\n");
2174 g_printf(" client_custom_compress \"%s\"\n",
2175 dp->clntcompprog? dp->clntcompprog : "");
2177 case COMP_SERVER_FAST:
2178 g_printf("SERVER FAST\n");
2180 case COMP_SERVER_BEST:
2181 g_printf("SERVER BEST\n");
2183 case COMP_SERVER_CUST:
2184 g_printf("SERVER CUSTOM\n");
2185 g_printf(" server_custom_compress \"%s\"\n",
2186 dp->srvcompprog? dp->srvcompprog : "");
2189 if(dp->compress != COMP_NONE) {
2190 g_printf(" comprate %.2lf %.2lf\n",
2191 dp->comprate[0], dp->comprate[1]);
2194 g_printf(" encrypt ");
2195 switch(dp->encrypt) {
2200 g_printf("CLIENT\n");
2201 g_printf(" client_encrypt \"%s\"\n",
2202 dp->clnt_encrypt? dp->clnt_encrypt : "");
2203 g_printf(" client_decrypt_option \"%s\"\n",
2204 dp->clnt_decrypt_opt? dp->clnt_decrypt_opt : "");
2206 case ENCRYPT_SERV_CUST:
2207 g_printf("SERVER\n");
2208 g_printf(" server_encrypt \"%s\"\n",
2209 dp->srv_encrypt? dp->srv_encrypt : "");
2210 g_printf(" server_decrypt_option \"%s\"\n",
2211 dp->srv_decrypt_opt? dp->srv_decrypt_opt : "");
2215 g_printf(" auth \"%s\"\n", dp->auth);
2216 g_printf(" kencrypt %s\n", (dp->kencrypt? "YES" : "NO"));
2217 g_printf(" amandad_path \"%s\"\n", dp->amandad_path);
2218 g_printf(" client_username \"%s\"\n", dp->client_username);
2219 g_printf(" client_port \"%s\"\n", dp->client_port);
2220 g_printf(" ssh_keys \"%s\"\n", dp->ssh_keys);
2222 g_printf(" holdingdisk ");
2223 switch(dp->to_holdingdisk) {
2225 g_printf("NEVER\n");
2231 g_printf("REQUIRED\n");
2235 g_printf(" record %s\n", (dp->record? "YES" : "NO"));
2236 g_printf(" index %s\n", (dp->index? "YES" : "NO"));
2237 g_printf(" starttime %04d\n", (int)dp->starttime);
2238 if(dp->tape_splitsize > (off_t)0) {
2239 g_printf(" tape_splitsize %lld\n",
2240 (long long)dp->tape_splitsize);
2242 if(dp->split_diskbuffer) {
2243 g_printf(" split_diskbuffer %s\n", dp->split_diskbuffer);
2245 if(dp->fallback_splitsize > (off_t)0) {
2246 g_printf(" fallback_splitsize %lldMb\n",
2247 (long long)(dp->fallback_splitsize / (off_t)1024));
2249 g_printf(" skip-incr %s\n", (dp->skip_incr? "YES" : "NO"));
2250 g_printf(" skip-full %s\n", (dp->skip_full? "YES" : "NO"));
2251 g_printf(" spindle %d\n", dp->spindle);
2252 pp_scriptlist = dp->pp_scriptlist;
2253 while (pp_scriptlist != NULL) {
2254 g_printf(" script \"%s\"\n", (char *)pp_scriptlist->data);
2255 pp_scriptlist = pp_scriptlist->next;
2262 dtype = lookup_dumptype(dp->dtype_name);
2263 prop = val_t_display_strs(dumptype_getconf((dtype), DUMPTYPE_PROPERTY),
2265 for(p1 = prop; *p1 != NULL; p1++) {
2266 g_printf(" property %s\n", *p1);
2283 diskloop(argc, argv, "disklist", disklist_one);
2285 for(dp = diskq.head; dp != NULL; dp = dp->next)
2296 (void)argc; /* Quiet unused parameter warning */
2297 (void)argv; /* Quiet unused parameter warning */
2299 for(i = 0; version_info[i] != NULL; i++)
2300 g_printf("%s", version_info[i]);
2305 int argc G_GNUC_UNUSED,
2306 char **argv G_GNUC_UNUSED)
2308 dump_configuration();