fix: remove destructive sync from ListSnapshots #49
@@ -419,7 +419,7 @@ func (v *Vaultik) listRemoteSnapshotIDs() (map[string]bool, error) {
|
|||||||
return remoteSnapshots, nil
|
return remoteSnapshots, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// reconcileLocalWithRemote removes local snapshots not in remote and returns the surviving local map
|
// reconcileLocalWithRemote builds a map of local snapshots keyed by ID for cross-referencing with remote
|
||||||
func (v *Vaultik) reconcileLocalWithRemote(remoteSnapshots map[string]bool) (map[string]*database.Snapshot, error) {
|
func (v *Vaultik) reconcileLocalWithRemote(remoteSnapshots map[string]bool) (map[string]*database.Snapshot, error) {
|
||||||
localSnapshots, err := v.Repositories.Snapshots.ListRecent(v.ctx, 10000)
|
localSnapshots, err := v.Repositories.Snapshots.ListRecent(v.ctx, 10000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -431,19 +431,6 @@ func (v *Vaultik) reconcileLocalWithRemote(remoteSnapshots map[string]bool) (map
|
|||||||
localSnapshotMap[s.ID.String()] = s
|
localSnapshotMap[s.ID.String()] = s
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, snap := range localSnapshots {
|
|
||||||
snapshotIDStr := snap.ID.String()
|
|
||||||
if !remoteSnapshots[snapshotIDStr] {
|
|
||||||
log.Info("Removing local snapshot not found in remote", "snapshot_id", snap.ID)
|
|
||||||
if err := v.deleteSnapshotFromLocalDB(snapshotIDStr); err != nil {
|
|
||||||
log.Error("Failed to delete local snapshot", "snapshot_id", snap.ID, "error", err)
|
|
||||||
} else {
|
|
||||||
log.Info("Deleted local snapshot not found in remote", "snapshot_id", snap.ID)
|
|
||||||
delete(localSnapshotMap, snapshotIDStr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return localSnapshotMap, nil
|
return localSnapshotMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,7 +859,7 @@ func (v *Vaultik) syncWithRemote() error {
|
|||||||
snapshotIDStr := snapshot.ID.String()
|
snapshotIDStr := snapshot.ID.String()
|
||||||
if !remoteSnapshots[snapshotIDStr] {
|
if !remoteSnapshots[snapshotIDStr] {
|
||||||
log.Info("Removing local snapshot not found in remote", "snapshot_id", snapshot.ID)
|
log.Info("Removing local snapshot not found in remote", "snapshot_id", snapshot.ID)
|
||||||
if err := v.Repositories.Snapshots.Delete(v.ctx, snapshotIDStr); err != nil {
|
if err := v.deleteSnapshotFromLocalDB(snapshotIDStr); err != nil {
|
||||||
log.Error("Failed to delete local snapshot", "snapshot_id", snapshot.ID, "error", err)
|
log.Error("Failed to delete local snapshot", "snapshot_id", snapshot.ID, "error", err)
|
||||||
} else {
|
} else {
|
||||||
removedCount++
|
removedCount++
|
||||||
|
|||||||
Reference in New Issue
Block a user