*/
/*
- Copyright (C) 2002-2003 Kern Sibbald and John Walker
+ Copyright (C) 2002-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
#include "dird.h"
/* Forward referenced functions */
-static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd);
+static int write_bsr(UAContext *ua, RBSR *bsr, FILE *fd);
void print_bsr(UAContext *ua, RBSR *bsr);
* We are called here once for each JobMedia record
* for each Volume.
*/
-static void write_findex(UAContext *ua, RBSR_FINDEX *fi,
+static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi,
int32_t FirstIndex, int32_t LastIndex, FILE *fd)
{
+ uint32_t count = 0;
for ( ; fi; fi=fi->next) {
int32_t findex, findex2;
if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) ||
findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
if (findex == findex2) {
fprintf(fd, "FileIndex=%d\n", findex);
+ count++;
} else {
fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
+ count += findex2 - findex + 1;
}
}
}
+ return count;
}
/*
static void print_findex(UAContext *ua, RBSR_FINDEX *fi)
{
- bsendmsg(ua, "fi=0x%x\n", (unsigned)fi);
+ bsendmsg(ua, "fi=0x%lx\n", fi);
for ( ; fi; fi=fi->next) {
if (fi->findex == fi->findex2) {
bsendmsg(ua, "FileIndex=%d\n", fi->findex);
-// Dmsg1(000, "FileIndex=%d\n", fi->findex);
+// Dmsg1(100, "FileIndex=%d\n", fi->findex);
} else {
bsendmsg(ua, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
-// Dmsg2(000, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
+// Dmsg2(100, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
}
}
}
{
if (bsr) {
free_findex(bsr->fi);
- free_bsr(bsr->next);
if (bsr->VolParams) {
free(bsr->VolParams);
}
+ free_bsr(bsr->next);
free(bsr);
}
}
}
/*
- * Write the bootstrap record to file
+ * Write the bootstrap records to file
*/
int write_bsr_file(UAContext *ua, RBSR *bsr)
{
FILE *fd;
POOLMEM *fname = get_pool_memory(PM_MESSAGE);
- int stat;
+ int count = 0;;
+ bool err;
- Mmsg(&fname, "%s/restore.bsr", working_directory);
+ Mmsg(fname, "%s/restore.bsr", working_directory);
fd = fopen(fname, "w+");
if (!fd) {
+ berrno be;
bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"),
- fname, strerror(errno));
- free_pool_memory(fname);
- return 0;
+ fname, be.strerror());
+ goto bail_out;
}
/* Write them to file */
- write_bsr(ua, bsr, fd);
- stat = !ferror(fd);
+ count = write_bsr(ua, bsr, fd);
+ err = ferror(fd);
fclose(fd);
+ if (err) {
+ bsendmsg(ua, _("Error writing bsr file.\n"));
+ count = 0;
+ goto bail_out;
+ }
+
+
bsendmsg(ua, _("Bootstrap records written to %s\n"), fname);
/* Tell the user what he will need to mount */
bsendmsg(ua, "\n");
- bsendmsg(ua, _("The restore job will require the following Volumes:\n"));
+ bsendmsg(ua, _("The job will require the following Volumes:\n"));
/* Create Unique list of Volumes using prompt list */
start_prompt(ua, "");
for (RBSR *nbsr=bsr; nbsr; nbsr=nbsr->next) {
bsendmsg(ua, " %s\n", ua->prompt[i]);
free(ua->prompt[i]);
}
+ if (ua->num_prompts == 0) {
+ bsendmsg(ua, _("No Volumes found to restore.\n"));
+ count = 0;
+ }
ua->num_prompts = 0;
bsendmsg(ua, "\n");
+
+bail_out:
free_pool_memory(fname);
- return stat;
+ return count;
}
-static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
+static int write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
{
+ uint32_t count = 0;
if (bsr) {
/*
* For a given volume, loop over all the JobMedia records.
fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId);
fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime);
- fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
- bsr->VolParams[i].EndFile);
- fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
- bsr->VolParams[i].EndBlock);
-
-// Dmsg2(000, "bsr VolParam FI=%u LI=%u\n",
+ if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) {
+ fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartFile);
+ } else {
+ fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
+ bsr->VolParams[i].EndFile);
+ }
+ if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) {
+ fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartBlock);
+ } else {
+ fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
+ bsr->VolParams[i].EndBlock);
+ }
+// Dmsg2(100, "bsr VolParam FI=%u LI=%u\n",
// bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex);
- write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
- bsr->VolParams[i].LastIndex, fd);
+
+ count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
+ bsr->VolParams[i].LastIndex, fd);
+ if (count) {
+ fprintf(fd, "Count=%u\n", count);
+ }
}
write_bsr(ua, bsr->next, fd);
}
+ return count;
}
void print_bsr(UAContext *ua, RBSR *bsr)