1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-22 07:43:03 +00:00

fs: retry vss creation on VSS_E_SNAPSHOT_SET_IN_PROGRESS error

Depending on the change packages, the VSS tests from ./cmd/restic and
the fs package may overlap in time. This causes the snapshot creation to
fail. Add retries in that case.
This commit is contained in:
Michael Eischer 2024-11-30 16:07:18 +01:00
parent c5fb46da53
commit 5df6bf80b1

View file

@ -171,6 +171,11 @@ func (h HRESULT) Str() string {
return "UNKNOWN" return "UNKNOWN"
} }
// Error implements the error interface
func (h HRESULT) Error() string {
return h.Str()
}
// VssError encapsulates errors returned from calling VSS api. // VssError encapsulates errors returned from calling VSS api.
type vssError struct { type vssError struct {
text string text string
@ -195,6 +200,11 @@ func (e *vssError) Error() string {
return fmt.Sprintf("VSS error: %s: %s (%#x)", e.text, e.hresult.Str(), e.hresult) return fmt.Sprintf("VSS error: %s: %s (%#x)", e.text, e.hresult.Str(), e.hresult)
} }
// Unwrap returns the underlying HRESULT error
func (e *vssError) Unwrap() error {
return e.hresult
}
// vssTextError encapsulates errors returned from calling VSS api. // vssTextError encapsulates errors returned from calling VSS api.
type vssTextError struct { type vssTextError struct {
text string text string
@ -943,10 +953,23 @@ func NewVssSnapshot(provider string,
"%s", volume)) "%s", volume))
} }
snapshotSetID, err := iVssBackupComponents.StartSnapshotSet() const retryStartSnapshotSetSleep = 5 * time.Second
var snapshotSetID ole.GUID
for {
var err error
snapshotSetID, err = iVssBackupComponents.StartSnapshotSet()
if errors.Is(err, VSS_E_SNAPSHOT_SET_IN_PROGRESS) && time.Now().Add(-retryStartSnapshotSetSleep).Before(deadline) {
// retry snapshot set creation while deadline is not reached
time.Sleep(retryStartSnapshotSetSleep)
continue
}
if err != nil { if err != nil {
iVssBackupComponents.Release() iVssBackupComponents.Release()
return VssSnapshot{}, err return VssSnapshot{}, err
} else {
break
}
} }
if err := iVssBackupComponents.AddToSnapshotSet(volume, providerID, &snapshotSetID); err != nil { if err := iVssBackupComponents.AddToSnapshotSet(volume, providerID, &snapshotSetID); err != nil {