mirror of
https://github.com/restic/restic.git
synced 2024-12-21 23:33: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:
parent
c5fb46da53
commit
5df6bf80b1
1 changed files with 27 additions and 4 deletions
|
@ -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
|
||||||
if err != nil {
|
var snapshotSetID ole.GUID
|
||||||
iVssBackupComponents.Release()
|
for {
|
||||||
return VssSnapshot{}, err
|
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 {
|
||||||
|
iVssBackupComponents.Release()
|
||||||
|
return VssSnapshot{}, err
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := iVssBackupComponents.AddToSnapshotSet(volume, providerID, &snapshotSetID); err != nil {
|
if err := iVssBackupComponents.AddToSnapshotSet(volume, providerID, &snapshotSetID); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue