|
|
|
@ -88,13 +88,24 @@ func runBackup(cmd *Command, args []string) bool { |
|
|
|
fmt.Printf("Error looking up volume %d: %v\n", vid, err) |
|
|
|
return true |
|
|
|
} |
|
|
|
volumeServer := lookup.Locations[0].ServerAddress() |
|
|
|
if len(lookup.Locations) == 0 { |
|
|
|
fmt.Printf("Error: volume %d has no locations available\n", vid) |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
// Try each available location until one succeeds
|
|
|
|
var lastErr error |
|
|
|
for i, location := range lookup.Locations { |
|
|
|
volumeServer := location.ServerAddress() |
|
|
|
fmt.Printf("Attempting to backup volume %d from location %d/%d: %s\n", vid, i+1, len(lookup.Locations), volumeServer) |
|
|
|
|
|
|
|
stats, err := operation.GetVolumeSyncStatus(volumeServer, grpcDialOption, uint32(vid)) |
|
|
|
if err != nil { |
|
|
|
fmt.Printf("Error get volume %d status: %v\n", vid, err) |
|
|
|
return true |
|
|
|
fmt.Printf("Error getting volume %d status from %s: %v\n", vid, volumeServer, err) |
|
|
|
lastErr = err |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
var ttl *needle.TTL |
|
|
|
if *s.ttl != "" { |
|
|
|
ttl, err = needle.ReadTTL(*s.ttl) |
|
|
|
@ -135,10 +146,12 @@ func runBackup(cmd *Command, args []string) bool { |
|
|
|
if v.SuperBlock.CompactionRevision < uint16(stats.CompactRevision) { |
|
|
|
if err = v.Compact2(0, 0, nil); err != nil { |
|
|
|
fmt.Printf("Compact Volume before synchronizing %v\n", err) |
|
|
|
v.Close() |
|
|
|
return true |
|
|
|
} |
|
|
|
if err = v.CommitCompact(); err != nil { |
|
|
|
fmt.Printf("Commit Compact before synchronizing %v\n", err) |
|
|
|
v.Close() |
|
|
|
return true |
|
|
|
} |
|
|
|
v.SuperBlock.CompactionRevision = uint16(stats.CompactRevision) |
|
|
|
@ -159,12 +172,23 @@ func runBackup(cmd *Command, args []string) bool { |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
defer v.Close() |
|
|
|
|
|
|
|
// Try the incremental backup
|
|
|
|
if err := v.IncrementalBackup(volumeServer, grpcDialOption); err != nil { |
|
|
|
fmt.Printf("Error synchronizing volume %d: %v\n", vid, err) |
|
|
|
fmt.Printf("Error synchronizing volume %d from %s: %v\n", vid, volumeServer, err) |
|
|
|
v.Close() |
|
|
|
lastErr = err |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// Success!
|
|
|
|
v.Close() |
|
|
|
fmt.Printf("Successfully backed up volume %d from %s\n", vid, volumeServer) |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
// All locations failed
|
|
|
|
fmt.Printf("Failed to backup volume %d after trying all %d locations. Last error: %v\n", vid, len(lookup.Locations), lastErr) |
|
|
|
|
|
|
|
return true |
|
|
|
} |