SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
fix: add doDeleteFile option for filer backup
Konstantin Lebedev2b229e98cee8
diff --git a/weed/command/filer_backup.go b/weed/command/filer_backup.goindex cd63f49f7b..691b1c0b51 100644--- a/weed/command/filer_backup.go+++ b/weed/command/filer_backup.go@@ -20,6 +20,7 @@ type FilerBackupOptions struct {excludeFileName *stringdebug *boolproxyByFiler *bool+ doDeleteFiles *booltimeAgo *time.DurationretentionDays *int}@@ -35,10 +36,10 @@ func init() {filerBackupOptions.excludePaths = cmdFilerBackup.Flag.String("filerExcludePaths", "", "exclude directories to sync on filer")filerBackupOptions.excludeFileName = cmdFilerBackup.Flag.String("filerExcludeFileName", "", "exclude file names that match the regexp to sync on filer")filerBackupOptions.proxyByFiler = cmdFilerBackup.Flag.Bool("filerProxy", false, "read and write file chunks by filer instead of volume servers")+ filerBackupOptions.doDeleteFiles = cmdFilerBackup.Flag.Bool("doDeleteFiles", false, "delete files on the destination")filerBackupOptions.debug = cmdFilerBackup.Flag.Bool("debug", false, "debug mode to print out received files")filerBackupOptions.timeAgo = cmdFilerBackup.Flag.Duration("timeAgo", 0, "start time before now. \"300ms\", \"1.5h\" or \"2h45m\". Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"")filerBackupOptions.retentionDays = cmdFilerBackup.Flag.Int("retentionDays", 0, "incremental backup retention days")-}var cmdFilerBackup = &Command{@@ -129,7 +130,7 @@ func doFilerBackup(grpcDialOption grpc.DialOption, backupOption *FilerBackupOpti*backupOption.proxyByFiler)dataSink.SetSourceFiler(filerSource)- processEventFn := genProcessFunction(sourcePath, targetPath, excludePaths, reExcludeFileName, dataSink, debug)+ processEventFn := genProcessFunction(sourcePath, targetPath, excludePaths, reExcludeFileName, dataSink, *backupOption.doDeleteFiles, debug)processEventFnWithOffset := pb.AddOffsetFunc(processEventFn, 3*time.Second, func(counter int64, lastTsNs int64) error {glog.V(0).Infof("backup %s progressed to %v %0.2f/sec", sourceFiler, time.Unix(0, lastTsNs), float64(counter)/float64(3))diff --git a/weed/command/filer_sync.go b/weed/command/filer_sync.goindex 38d29cdc61..33dcf4073f 100644--- a/weed/command/filer_sync.go+++ b/weed/command/filer_sync.go@@ -251,7 +251,7 @@ func doSubscribeFilerMetaChanges(clientId int32, clientEpoch int32, grpcDialOptifilerSink.DoInitialize(targetFiler.ToHttpAddress(), targetFiler.ToGrpcAddress(), targetPath, replicationStr, collection, ttlSec, diskType, grpcDialOption, sinkWriteChunkByFiler)filerSink.SetSourceFiler(filerSource)- persistEventFn := genProcessFunction(sourcePath, targetPath, sourceExcludePaths, nil, filerSink, debug)+ persistEventFn := genProcessFunction(sourcePath, targetPath, sourceExcludePaths, nil, filerSink, true, debug)processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {message := resp.EventNotification@@ -369,7 +369,7 @@ func setOffset(grpcDialOption grpc.DialOption, filer pb.ServerAddress, signature}-func genProcessFunction(sourcePath string, targetPath string, excludePaths []string, reExcludeFileName *regexp.Regexp, dataSink sink.ReplicationSink, debug bool) func(resp *filer_pb.SubscribeMetadataResponse) error {+func genProcessFunction(sourcePath string, targetPath string, excludePaths []string, reExcludeFileName *regexp.Regexp, dataSink sink.ReplicationSink, doDeleteFiles bool, debug bool) func(resp *filer_pb.SubscribeMetadataResponse) error {// process functionprocessEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {message := resp.EventNotification@@ -397,16 +397,19 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []strif reExcludeFileName != nil && reExcludeFileName.MatchString(message.NewEntry.Name) {return nil}+ if dataSink.IsIncremental() {+ doDeleteFiles = false+ }// handle deletionsif filer_pb.IsDelete(resp) {+ if doDeleteFiles {+ return nil+ }if !strings.HasPrefix(string(sourceOldKey), sourcePath) {return nil}key := buildKey(dataSink, message, targetPath, sourceOldKey, sourcePath)- if !dataSink.IsIncremental() {- return dataSink.DeleteEntry(key, message.OldEntry.IsDirectory, message.DeleteChunks, message.Signatures)- }- return nil+ return dataSink.DeleteEntry(key, message.OldEntry.IsDirectory, message.DeleteChunks, message.Signatures)}// handle new entries@@ -432,7 +435,7 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str// old key is in the watched directoryif strings.HasPrefix(string(sourceNewKey), sourcePath) {// new key is also in the watched directory- if !dataSink.IsIncremental() {+ if doDeleteFiles {oldKey := util.Join(targetPath, string(sourceOldKey)[len(sourcePath):])message.NewParentPath = util.Join(targetPath, message.NewParentPath[len(sourcePath):])foundExisting, err := dataSink.UpdateEntry(string(oldKey), message.OldEntry, message.NewParentPath, message.NewEntry, message.DeleteChunks, message.Signatures)@@ -455,7 +458,7 @@ func genProcessFunction(sourcePath string, targetPath string, excludePaths []str} else {// new key is outside of the watched directory- if !dataSink.IsIncremental() {+ if doDeleteFiles {key := buildKey(dataSink, message, targetPath, sourceOldKey, sourcePath)return dataSink.DeleteEntry(key, message.OldEntry.IsDirectory, message.DeleteChunks, message.Signatures)}