From: Kern Sibbald Date: Wed, 7 Apr 2010 09:32:12 +0000 (+0200) Subject: Add FT_RESTORE and first cut handling it X-Git-Tag: Release-7.0.0~1975 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dd74c383e3a715a279515d2f8776f0c318692013;p=bacula%2Fbacula Add FT_RESTORE and first cut handling it --- diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 195d688f4d..c9ed17001b 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -343,6 +343,7 @@ void InitWinAPIWrapper(); #define FT_PLUGIN 22 /* Plugin generated filename */ #define FT_DELETED 23 /* Deleted file entry */ #define FT_BASE 24 /* Duplicate base file entry */ +#define FT_RESTORE_FIRST 25 /* Restore this "object" first */ /* Definitions for upper part of type word (see above). */ #define AR_DATA_STREAM (1<<16) /* Data stream id present */ diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index b2fad4c302..5faeb259dc 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -314,7 +314,7 @@ int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) #endif BSOCK *sd = jcr->store_bsock; - if (job_canceled(jcr)) { + if (jcr->is_job_canceled()) { return 0; } @@ -335,6 +335,9 @@ int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) case FT_LNK: Dmsg2(130, "FT_LNK saving: %s -> %s\n", ff_pkt->fname, ff_pkt->link); break; + case FT_RESTORE_FIRST: + Dmsg1(00, "FT_RESTORE_FIRST saving: %s\n", ff_pkt->fname); + break; case FT_DIRBEGIN: jcr->num_files_examined--; /* correct file count */ return 1; /* not used */ @@ -489,6 +492,7 @@ int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) set_portable_backup(&ff_pkt->bfd); /* disable Win32 BackupRead() */ } if (ff_pkt->cmd_plugin) { + /* Tell bfile that it needs to call plugin */ if (!set_cmd_plugin(&ff_pkt->bfd, jcr)) { goto bail_out; } @@ -853,7 +857,7 @@ static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest, * */ if (!sd->fsend("%ld %d 0", jcr->JobFiles, stream)) { - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); } @@ -1013,7 +1017,7 @@ static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest, } sd->msg = wbuf; /* set correct write buffer */ if (!sd->send()) { - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); } @@ -1050,7 +1054,7 @@ static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest, sd->msglen = encrypted_len; /* set encrypted length */ sd->msg = jcr->crypto.crypto_buf; /* set correct write buffer */ if (!sd->send()) { - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); } @@ -1063,7 +1067,7 @@ static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest, } if (!sd->signal(BNET_EOD)) { /* indicate end of file data */ - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); } @@ -1093,7 +1097,7 @@ bool encode_and_send_attributes(JCR *jcr, FF_PKT *ff_pkt, int &data_stream) char attribs[MAXSTRING]; char attribsEx[MAXSTRING]; int attr_stream; - int stat; + bool stat; #ifdef FD_NO_SEND_TEST return true; #endif @@ -1123,7 +1127,7 @@ bool encode_and_send_attributes(JCR *jcr, FF_PKT *ff_pkt, int &data_stream) * */ if (!sd->fsend("%ld %d 0", jcr->JobFiles, attr_stream)) { - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); } @@ -1146,33 +1150,36 @@ bool encode_and_send_attributes(JCR *jcr, FF_PKT *ff_pkt, int &data_stream) if (ff_pkt->type != FT_DELETED) { /* already stripped */ strip_path(ff_pkt); } - if (ff_pkt->type == FT_LNK || ff_pkt->type == FT_LNKSAVED) { + switch (ff_pkt->type) { + case FT_LNK: + case FT_LNKSAVED: Dmsg2(300, "Link %s to %s\n", ff_pkt->fname, ff_pkt->link); stat = sd->fsend("%ld %d %s%c%s%c%s%c%s%c", jcr->JobFiles, ff_pkt->type, ff_pkt->fname, 0, attribs, 0, ff_pkt->link, 0, attribsEx, 0); - } else if (ff_pkt->type == FT_DIREND || ff_pkt->type == FT_REPARSE) { + break; + case FT_DIREND: + case FT_REPARSE: /* Here link is the canonical filename (i.e. with trailing slash) */ stat = sd->fsend("%ld %d %s%c%s%c%c%s%c", jcr->JobFiles, ff_pkt->type, ff_pkt->link, 0, attribs, 0, 0, attribsEx, 0); - } else { + break; + default: stat = sd->fsend("%ld %d %s%c%s%c%c%s%c", jcr->JobFiles, ff_pkt->type, ff_pkt->fname, 0, attribs, 0, 0, attribsEx, 0); + break; } if (ff_pkt->type != FT_DELETED) { unstrip_path(ff_pkt); } Dmsg2(300, ">stored: attr len=%d: %s\n", sd->msglen, sd->msg); - if (!stat) { - if (!job_canceled(jcr)) { - Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), - sd->bstrerror()); - } - return false; + if (!stat && !jcr->is_job_canceled()) { + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), + sd->bstrerror()); } sd->signal(BNET_EOD); /* indicate end of attributes data */ - return true; + return stat; } /** diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index 5a57ccd20d..92235c868b 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -82,6 +82,7 @@ struct save_pkt { uint32_t flags; /* Bacula internal flags */ bool portable; /* set if data format is portable */ char *cmd; /* command */ + char *object; /* restore object data to save */ int32_t pkt_end; /* end packet sentinel */ }; diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index 10d0b22a88..950bb2ad78 100644 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -68,6 +68,12 @@ int select_data_stream(FF_PKT *ff_pkt) { int stream; + /* This is a plugin special restore object */ + if (ff_pkt->type == FT_RESTORE_FIRST) { + ff_pkt->flags = 0; + return STREAM_RESTORE_OBJECT; + } + /** * Fix all incompatible options */