From: Kern Sibbald Date: Wed, 14 Apr 2010 13:24:50 +0000 (+0200) Subject: Apply James' patch with my restore object changes X-Git-Tag: Release-5.2.1~1479 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3ea94fb346f433e2af1237aab3a164005602ad48;p=bacula%2Fbacula Apply James' patch with my restore object changes --- diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 3456446064..4988b64451 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -1338,6 +1338,14 @@ static void close_vss_backup_session(JCR *jcr) Jmsg(jcr, msg_type, 0, _("VSS Writer (BackupComplete): %s\n"), g_pVSSClient->GetWriterInfo(i)); } } + WCHAR *metadata = g_pVSSClient->GetMetadata(); + FF_PKT *ff_pkt = jcr->ff; + ff_pkt->fname = bstrdup("job_metadata.xml"); + ff_pkt->type = FT_RESTORE_FIRST; + ff_pkt->LinkFI = 0; + ff_pkt->object = (char *)metadata; + ff_pkt->object_len = (wcslen(metadata) + 1) * sizeof(WCHAR); + save_file(jcr, ff_pkt, true); } #endif } diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 4a224cd68f..9fa5df46cd 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -317,6 +317,7 @@ void *handle_client_request(void *dirp) dir->signal(BNET_TERMINATE); free_plugins(jcr); /* release instantiated plugins */ + free_and_null_pool_memory(jcr->job_metadata); /* Clean up fileset */ FF_PKT *ff = jcr->ff; @@ -619,7 +620,6 @@ static int runscript_cmd(JCR *jcr) return dir->fsend(OKRunScript); } - static int restore_object_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; @@ -663,8 +663,15 @@ static int restore_object_cmd(JCR *jcr) rop.object = dir->msg; // Dmsg2(000, "Recv Object: len=%d Object=%s\n", dir->msglen, dir->msg); - /* pass to plugin */ - generate_plugin_event(jcr, bEventRestoreObject, (void *)&rop); + if (strcmp(rop.object_name, "job_metadata.xml") == 0) { + Dmsg0(000, "got job metadata\n"); + free_and_null_pool_memory(jcr->job_metadata); + jcr->job_metadata = rop.object; + rop.object = NULL; + } else { + /* pass to plugin */ + generate_plugin_event(jcr, bEventRestoreObject, (void *)&rop); + } if (rop.object_name) { free(rop.object_name); @@ -1958,7 +1965,8 @@ static int restore_cmd(JCR *jcr) #if defined(WIN32_VSS) /* START VSS ON WIN32 */ if (jcr->VSS) { - if (g_pVSSClient->InitializeForRestore(jcr, vss_restore_init_callback)) { + if (g_pVSSClient->InitializeForRestore(jcr, vss_restore_init_callback, + (WCHAR *)jcr->job_metadata)) { /* inform user about writer states */ int i; for (i=0; i < (int)g_pVSSClient->GetWriterCount(); i++) { @@ -1976,6 +1984,7 @@ static int restore_cmd(JCR *jcr) berrno be; Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled. ERR=%s\n"), be.bstrerror()); } + free_and_null_pool_memory(jcr->job_metadata); run_scripts(jcr, jcr->RunScripts, "ClientAfterVSS"); } #endif diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 9e6c14a504..9db901ad67 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -358,6 +358,7 @@ public: /* File Daemon specific part of JCR */ uint32_t num_files_examined; /* files examined this job */ POOLMEM *last_fname; /* last file saved/verified */ + POOLMEM *job_metadata; /* VSS job metadata */ acl_data_t *acl_data; /* ACLs for backup/restore */ xattr_data_t *xattr_data; /* Extended Attributes for backup/restore */ int32_t last_type; /* type of last file saved/verified */ diff --git a/bacula/src/win32/filed/plugins/Makefile b/bacula/src/win32/filed/plugins/Makefile index 63ae13a325..9764352dd9 100644 --- a/bacula/src/win32/filed/plugins/Makefile +++ b/bacula/src/win32/filed/plugins/Makefile @@ -51,12 +51,15 @@ VSS_BASE_OBJS = \ $(OBJDIR)/vss_root_node.o \ $(OBJDIR)/vss_writer_node.o \ $(OBJDIR)/vss_component_node.o \ - $(OBJDIR)/vss_directory_node.o \ - $(OBJDIR)/vss_file_node.o + $(OBJDIR)/vss_file_node.o \ + $(OBJDIR)/find_filespec.o SYSTEMSTATE_OBJS = \ $(VSS_BASE_OBJS) \ - $(OBJDIR)/systemstate-fd.o + $(OBJDIR)/systemstate-fd.o \ + $(OBJDIR)/systemstate_registry.o \ + $(OBJDIR)/systemstate_frs.o \ + $(OBJDIR)/systemstate_complusregdb.o BPIPE_OBJS = \ $(OBJDIR)/bpipe-fd.o diff --git a/bacula/src/win32/filed/vss.cpp b/bacula/src/win32/filed/vss.cpp index 28e0b34fc2..55655dcc94 100644 --- a/bacula/src/win32/filed/vss.cpp +++ b/bacula/src/win32/filed/vss.cpp @@ -136,8 +136,9 @@ bool VSSClient::InitializeForBackup(JCR *jcr) } -bool VSSClient::InitializeForRestore(JCR *jcr, bool (*VssInitCallback)(JCR *, int)) +bool VSSClient::InitializeForRestore(JCR *jcr, bool (*VssInitCallback)(JCR *, int), WCHAR *job_metadata) { + m_metadata = job_metadata; m_jcr = jcr; return Initialize(0, true/*=>Restore*/, VssInitCallback); } diff --git a/bacula/src/win32/filed/vss.h b/bacula/src/win32/filed/vss.h index 45fdfbd125..1a7d0906f2 100644 --- a/bacula/src/win32/filed/vss.h +++ b/bacula/src/win32/filed/vss.h @@ -60,12 +60,11 @@ public: // Backup Process bool InitializeForBackup(JCR *jcr); - bool InitializeForRestore(JCR *jcr, bool (*VssInitCallback)(JCR *, int) = NULL); - //bool GatherForRestore() = 0; - //bool PrepareForRestore() = 0; + bool InitializeForRestore(JCR *jcr, bool (*VssInitCallback)(JCR *, int) = NULL, WCHAR *job_metadata = NULL); virtual bool CreateSnapshots(char* szDriveLetters) = 0; virtual bool CloseBackup() = 0; virtual bool CloseRestore() = 0; + virtual WCHAR *GetMetadata() = 0; virtual const char* GetDriverName() = 0; bool GetShadowPath (const char* szFilePath, char* szShadowPath, int nBuflen); bool GetShadowPathW (const wchar_t* szFilePath, wchar_t* szShadowPath, int nBuflen); /* nBuflen in characters */ @@ -104,6 +103,8 @@ protected: bool m_bCoInitializeSecurityCalled; bool m_bDuringRestore; /* true if we are doing a restore */ bool m_bBackupIsInitialized; + + WCHAR *m_metadata; }; class VSSClientXP:public VSSClient @@ -114,6 +115,7 @@ public: virtual bool CreateSnapshots(char* szDriveLetters); virtual bool CloseBackup(); virtual bool CloseRestore(); + virtual WCHAR *GetMetadata(); virtual const char* GetDriverName() { return "VSS WinXP"; }; private: virtual bool Initialize(DWORD dwContext, bool bDuringRestore, bool (*VssInitCallback)(JCR *, int) = NULL); @@ -130,6 +132,7 @@ public: virtual bool CreateSnapshots(char* szDriveLetters); virtual bool CloseBackup(); virtual bool CloseRestore(); + virtual WCHAR *GetMetadata(); virtual const char* GetDriverName() { return "VSS Win 2003"; }; private: virtual bool Initialize(DWORD dwContext, bool bDuringRestore, bool (*VssInitCallback)(JCR *, int) = NULL); @@ -146,6 +149,7 @@ public: virtual bool CreateSnapshots(char* szDriveLetters); virtual bool CloseBackup(); virtual bool CloseRestore(); + virtual WCHAR *GetMetadata(); virtual const char* GetDriverName() { return "VSS Vista"; }; private: virtual bool Initialize(DWORD dwContext, bool bDuringRestore, bool (*VssInitCallback)(JCR *, int) = NULL); diff --git a/bacula/src/win32/filed/vss_generic.cpp b/bacula/src/win32/filed/vss_generic.cpp index fba70a45a6..8707f7f3d2 100644 --- a/bacula/src/win32/filed/vss_generic.cpp +++ b/bacula/src/win32/filed/vss_generic.cpp @@ -334,11 +334,12 @@ bool VSSClientGeneric::Initialize(DWORD dwContext, bool bDuringRestore, bool (*V * Initialize for restore */ - WCHAR *xml; HRESULT hr; + +#if 0 + WCHAR *xml; int fd; struct stat stat; - /* obviously this is just temporary - the xml should come from somewhere like the catalog */ fd = open("C:\\james.xml", O_RDONLY); Dmsg1(0, "fd = %d\n", fd); @@ -348,9 +349,10 @@ bool VSSClientGeneric::Initialize(DWORD dwContext, bool bDuringRestore, bool (*V read(fd, xml, stat.st_size); close(fd); xml[stat.st_size / sizeof(WCHAR)] = 0; +#endif // 1. InitializeForRestore - hr = ((IVssBackupComponents*) m_pVssObject)->InitializeForRestore(xml); + hr = ((IVssBackupComponents*) m_pVssObject)->InitializeForRestore(m_metadata); if (FAILED(hr)) { Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->InitializeForRestore returned 0x%08X\n", hr); errno = b_errno_win32; @@ -523,6 +525,9 @@ bool VSSClientGeneric::CreateSnapshots(char* szDriveLetters) bool VSSClientGeneric::CloseBackup() { bool bRet = false; + HRESULT hr; + BSTR xml; + if (!m_pVssObject) errno = ENOSYS; else { @@ -533,6 +538,12 @@ bool VSSClientGeneric::CloseBackup() m_bBackupIsInitialized = false; + hr = pVss->SaveAsXML(&xml); + if (hr == ERROR_SUCCESS) + m_metadata = xml; + else + m_metadata = NULL; +#if 0 { HRESULT hr; BSTR xml; @@ -543,6 +554,7 @@ bool VSSClientGeneric::CloseBackup() write(fd, xml, wcslen(xml) * sizeof(WCHAR)); close(fd); } +#endif if (SUCCEEDED(pVss->BackupComplete(&pAsync.p))) { // Waits for the async operation to finish and checks the result WaitAndCheckForAsyncOperation(pAsync.p); @@ -582,6 +594,11 @@ bool VSSClientGeneric::CloseBackup() return bRet; } +WCHAR *VSSClientGeneric::GetMetadata() +{ + return m_metadata; +} + bool VSSClientGeneric::CloseRestore() { HRESULT hr;