You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

508 lines
20 KiB

4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
  1. package command
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/glog"
  7. "github.com/seaweedfs/seaweedfs/weed/pb"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  9. "github.com/seaweedfs/seaweedfs/weed/replication"
  10. "github.com/seaweedfs/seaweedfs/weed/replication/sink"
  11. "github.com/seaweedfs/seaweedfs/weed/replication/sink/filersink"
  12. "github.com/seaweedfs/seaweedfs/weed/replication/source"
  13. "github.com/seaweedfs/seaweedfs/weed/security"
  14. statsCollect "github.com/seaweedfs/seaweedfs/weed/stats"
  15. "github.com/seaweedfs/seaweedfs/weed/util"
  16. "github.com/seaweedfs/seaweedfs/weed/util/grace"
  17. "google.golang.org/grpc"
  18. "os"
  19. "regexp"
  20. "strings"
  21. "time"
  22. )
  23. type SyncOptions struct {
  24. isActivePassive *bool
  25. filerA *string
  26. filerB *string
  27. aPath *string
  28. aExcludePaths *string
  29. bPath *string
  30. bExcludePaths *string
  31. aReplication *string
  32. bReplication *string
  33. aCollection *string
  34. bCollection *string
  35. aTtlSec *int
  36. bTtlSec *int
  37. aDiskType *string
  38. bDiskType *string
  39. aDebug *bool
  40. bDebug *bool
  41. aFromTsMs *int64
  42. bFromTsMs *int64
  43. aProxyByFiler *bool
  44. bProxyByFiler *bool
  45. metricsHttpIp *string
  46. metricsHttpPort *int
  47. concurrency *int
  48. aDoDeleteFiles *bool
  49. bDoDeleteFiles *bool
  50. clientId int32
  51. clientEpoch int32
  52. }
  53. const (
  54. SyncKeyPrefix = "sync."
  55. DefaultConcurrencyLimit = 32
  56. )
  57. var (
  58. syncOptions SyncOptions
  59. syncCpuProfile *string
  60. syncMemProfile *string
  61. )
  62. func init() {
  63. cmdFilerSynchronize.Run = runFilerSynchronize // break init cycle
  64. syncOptions.isActivePassive = cmdFilerSynchronize.Flag.Bool("isActivePassive", false, "one directional follow from A to B if true")
  65. syncOptions.filerA = cmdFilerSynchronize.Flag.String("a", "", "filer A in one SeaweedFS cluster")
  66. syncOptions.filerB = cmdFilerSynchronize.Flag.String("b", "", "filer B in the other SeaweedFS cluster")
  67. syncOptions.aPath = cmdFilerSynchronize.Flag.String("a.path", "/", "directory to sync on filer A")
  68. syncOptions.aExcludePaths = cmdFilerSynchronize.Flag.String("a.excludePaths", "", "exclude directories to sync on filer A")
  69. syncOptions.bPath = cmdFilerSynchronize.Flag.String("b.path", "/", "directory to sync on filer B")
  70. syncOptions.bExcludePaths = cmdFilerSynchronize.Flag.String("b.excludePaths", "", "exclude directories to sync on filer B")
  71. syncOptions.aReplication = cmdFilerSynchronize.Flag.String("a.replication", "", "replication on filer A")
  72. syncOptions.bReplication = cmdFilerSynchronize.Flag.String("b.replication", "", "replication on filer B")
  73. syncOptions.aCollection = cmdFilerSynchronize.Flag.String("a.collection", "", "collection on filer A")
  74. syncOptions.bCollection = cmdFilerSynchronize.Flag.String("b.collection", "", "collection on filer B")
  75. syncOptions.aTtlSec = cmdFilerSynchronize.Flag.Int("a.ttlSec", 0, "ttl in seconds on filer A")
  76. syncOptions.bTtlSec = cmdFilerSynchronize.Flag.Int("b.ttlSec", 0, "ttl in seconds on filer B")
  77. syncOptions.aDiskType = cmdFilerSynchronize.Flag.String("a.disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag on filer A")
  78. syncOptions.bDiskType = cmdFilerSynchronize.Flag.String("b.disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag on filer B")
  79. syncOptions.aProxyByFiler = cmdFilerSynchronize.Flag.Bool("a.filerProxy", false, "read and write file chunks by filer A instead of volume servers")
  80. syncOptions.bProxyByFiler = cmdFilerSynchronize.Flag.Bool("b.filerProxy", false, "read and write file chunks by filer B instead of volume servers")
  81. syncOptions.aDebug = cmdFilerSynchronize.Flag.Bool("a.debug", false, "debug mode to print out filer A received files")
  82. syncOptions.bDebug = cmdFilerSynchronize.Flag.Bool("b.debug", false, "debug mode to print out filer B received files")
  83. syncOptions.aFromTsMs = cmdFilerSynchronize.Flag.Int64("a.fromTsMs", 0, "synchronization from timestamp on filer A. The unit is millisecond")
  84. syncOptions.bFromTsMs = cmdFilerSynchronize.Flag.Int64("b.fromTsMs", 0, "synchronization from timestamp on filer B. The unit is millisecond")
  85. syncOptions.concurrency = cmdFilerSynchronize.Flag.Int("concurrency", DefaultConcurrencyLimit, "The maximum number of files that will be synced concurrently.")
  86. syncCpuProfile = cmdFilerSynchronize.Flag.String("cpuprofile", "", "cpu profile output file")
  87. syncMemProfile = cmdFilerSynchronize.Flag.String("memprofile", "", "memory profile output file")
  88. syncOptions.metricsHttpIp = cmdFilerSynchronize.Flag.String("metricsIp", "", "metrics listen ip")
  89. syncOptions.metricsHttpPort = cmdFilerSynchronize.Flag.Int("metricsPort", 0, "metrics listen port")
  90. syncOptions.aDoDeleteFiles = cmdFilerSynchronize.Flag.Bool("a.doDeleteFiles", true, "delete and update files when synchronizing on filer A")
  91. syncOptions.bDoDeleteFiles = cmdFilerSynchronize.Flag.Bool("b.doDeleteFiles", true, "delete and update files when synchronizing on filer B")
  92. syncOptions.clientId = util.RandomInt32()
  93. }
  94. var cmdFilerSynchronize = &Command{
  95. UsageLine: "filer.sync -a=<oneFilerHost>:<oneFilerPort> -b=<otherFilerHost>:<otherFilerPort>",
  96. Short: "resumable continuous synchronization between two active-active or active-passive SeaweedFS clusters",
  97. Long: `resumable continuous synchronization for file changes between two active-active or active-passive filers
  98. filer.sync listens on filer notifications. If any file is updated, it will fetch the updated content,
  99. and write to the other destination. Different from filer.replicate:
  100. * filer.sync only works between two filers.
  101. * filer.sync does not need any special message queue setup.
  102. * filer.sync supports both active-active and active-passive modes.
  103. If restarted, the synchronization will resume from the previous checkpoints, persisted every minute.
  104. A fresh sync will start from the earliest metadata logs.
  105. `,
  106. }
  107. func runFilerSynchronize(cmd *Command, args []string) bool {
  108. util.LoadConfiguration("security", false)
  109. grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
  110. grace.SetupProfiling(*syncCpuProfile, *syncMemProfile)
  111. filerA := pb.ServerAddress(*syncOptions.filerA)
  112. filerB := pb.ServerAddress(*syncOptions.filerB)
  113. // start filer.sync metrics server
  114. go statsCollect.StartMetricsServer(*syncOptions.metricsHttpIp, *syncOptions.metricsHttpPort)
  115. // read a filer signature
  116. aFilerSignature, aFilerErr := replication.ReadFilerSignature(grpcDialOption, filerA)
  117. if aFilerErr != nil {
  118. glog.Errorf("get filer 'a' signature %d error from %s to %s: %v", aFilerSignature, *syncOptions.filerA, *syncOptions.filerB, aFilerErr)
  119. return true
  120. }
  121. // read b filer signature
  122. bFilerSignature, bFilerErr := replication.ReadFilerSignature(grpcDialOption, filerB)
  123. if bFilerErr != nil {
  124. glog.Errorf("get filer 'b' signature %d error from %s to %s: %v", bFilerSignature, *syncOptions.filerA, *syncOptions.filerB, bFilerErr)
  125. return true
  126. }
  127. go func() {
  128. // a->b
  129. // set synchronization start timestamp to offset
  130. initOffsetError := initOffsetFromTsMs(grpcDialOption, filerB, aFilerSignature, *syncOptions.bFromTsMs, getSignaturePrefixByPath(*syncOptions.aPath))
  131. if initOffsetError != nil {
  132. glog.Errorf("init offset from timestamp %d error from %s to %s: %v", *syncOptions.bFromTsMs, *syncOptions.filerA, *syncOptions.filerB, initOffsetError)
  133. os.Exit(2)
  134. }
  135. for {
  136. syncOptions.clientEpoch++
  137. err := doSubscribeFilerMetaChanges(
  138. syncOptions.clientId,
  139. syncOptions.clientEpoch,
  140. grpcDialOption,
  141. filerA,
  142. *syncOptions.aPath,
  143. util.StringSplit(*syncOptions.aExcludePaths, ","),
  144. *syncOptions.aProxyByFiler,
  145. filerB,
  146. *syncOptions.bPath,
  147. *syncOptions.bReplication,
  148. *syncOptions.bCollection,
  149. *syncOptions.bTtlSec,
  150. *syncOptions.bProxyByFiler,
  151. *syncOptions.bDiskType,
  152. *syncOptions.bDebug,
  153. *syncOptions.concurrency,
  154. *syncOptions.bDoDeleteFiles,
  155. aFilerSignature,
  156. bFilerSignature)
  157. if err != nil {
  158. glog.Errorf("sync from %s to %s: %v", *syncOptions.filerA, *syncOptions.filerB, err)
  159. time.Sleep(1747 * time.Millisecond)
  160. }
  161. }
  162. }()
  163. if !*syncOptions.isActivePassive {
  164. // b->a
  165. // set synchronization start timestamp to offset
  166. initOffsetError := initOffsetFromTsMs(grpcDialOption, filerA, bFilerSignature, *syncOptions.aFromTsMs, getSignaturePrefixByPath(*syncOptions.bPath))
  167. if initOffsetError != nil {
  168. glog.Errorf("init offset from timestamp %d error from %s to %s: %v", *syncOptions.aFromTsMs, *syncOptions.filerB, *syncOptions.filerA, initOffsetError)
  169. os.Exit(2)
  170. }
  171. go func() {
  172. for {
  173. syncOptions.clientEpoch++
  174. err := doSubscribeFilerMetaChanges(
  175. syncOptions.clientId,
  176. syncOptions.clientEpoch,
  177. grpcDialOption,
  178. filerB,
  179. *syncOptions.bPath,
  180. util.StringSplit(*syncOptions.bExcludePaths, ","),
  181. *syncOptions.bProxyByFiler,
  182. filerA,
  183. *syncOptions.aPath,
  184. *syncOptions.aReplication,
  185. *syncOptions.aCollection,
  186. *syncOptions.aTtlSec,
  187. *syncOptions.aProxyByFiler,
  188. *syncOptions.aDiskType,
  189. *syncOptions.aDebug,
  190. *syncOptions.concurrency,
  191. *syncOptions.aDoDeleteFiles,
  192. bFilerSignature,
  193. aFilerSignature)
  194. if err != nil {
  195. glog.Errorf("sync from %s to %s: %v", *syncOptions.filerB, *syncOptions.filerA, err)
  196. time.Sleep(2147 * time.Millisecond)
  197. }
  198. }
  199. }()
  200. }
  201. select {}
  202. return true
  203. }
  204. // initOffsetFromTsMs Initialize offset
  205. func initOffsetFromTsMs(grpcDialOption grpc.DialOption, targetFiler pb.ServerAddress, sourceFilerSignature int32, fromTsMs int64, signaturePrefix string) error {
  206. if fromTsMs <= 0 {
  207. return nil
  208. }
  209. // convert to nanosecond
  210. fromTsNs := fromTsMs * 1000_000
  211. // If not successful, exit the program.
  212. setOffsetErr := setOffset(grpcDialOption, targetFiler, signaturePrefix, sourceFilerSignature, fromTsNs)
  213. if setOffsetErr != nil {
  214. return setOffsetErr
  215. }
  216. glog.Infof("setOffset from timestamp ms success! start offset: %d from %s to %s", fromTsNs, *syncOptions.filerA, *syncOptions.filerB)
  217. return nil
  218. }
  219. func doSubscribeFilerMetaChanges(clientId int32, clientEpoch int32, grpcDialOption grpc.DialOption, sourceFiler pb.ServerAddress, sourcePath string, sourceExcludePaths []string, sourceReadChunkFromFiler bool, targetFiler pb.ServerAddress, targetPath string,
  220. replicationStr, collection string, ttlSec int, sinkWriteChunkByFiler bool, diskType string, debug bool, concurrency int, doDeleteFiles bool, sourceFilerSignature int32, targetFilerSignature int32) error {
  221. // if first time, start from now
  222. // if has previously synced, resume from that point of time
  223. sourceFilerOffsetTsNs, err := getOffset(grpcDialOption, targetFiler, getSignaturePrefixByPath(sourcePath), sourceFilerSignature)
  224. if err != nil {
  225. return err
  226. }
  227. glog.V(0).Infof("start sync %s(%d) => %s(%d) from %v(%d)", sourceFiler, sourceFilerSignature, targetFiler, targetFilerSignature, time.Unix(0, sourceFilerOffsetTsNs), sourceFilerOffsetTsNs)
  228. // create filer sink
  229. filerSource := &source.FilerSource{}
  230. filerSource.DoInitialize(sourceFiler.ToHttpAddress(), sourceFiler.ToGrpcAddress(), sourcePath, sourceReadChunkFromFiler)
  231. filerSink := &filersink.FilerSink{}
  232. filerSink.DoInitialize(targetFiler.ToHttpAddress(), targetFiler.ToGrpcAddress(), targetPath, replicationStr, collection, ttlSec, diskType, grpcDialOption, sinkWriteChunkByFiler)
  233. filerSink.SetSourceFiler(filerSource)
  234. persistEventFn := genProcessFunction(sourcePath, targetPath, sourceExcludePaths, nil, filerSink, doDeleteFiles, debug)
  235. processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
  236. message := resp.EventNotification
  237. for _, sig := range message.Signatures {
  238. if sig == targetFilerSignature && targetFilerSignature != 0 {
  239. fmt.Printf("%s skipping %s change to %v\n", targetFiler, sourceFiler, message)
  240. return nil
  241. }
  242. }
  243. return persistEventFn(resp)
  244. }
  245. if concurrency < 0 || concurrency > 1024 {
  246. glog.Warningf("invalid concurrency value, using default: %d", DefaultConcurrencyLimit)
  247. concurrency = DefaultConcurrencyLimit
  248. }
  249. processor := NewMetadataProcessor(processEventFn, concurrency)
  250. var lastLogTsNs = time.Now().UnixNano()
  251. var clientName = fmt.Sprintf("syncFrom_%s_To_%s", string(sourceFiler), string(targetFiler))
  252. processEventFnWithOffset := pb.AddOffsetFunc(func(resp *filer_pb.SubscribeMetadataResponse) error {
  253. processor.AddSyncJob(resp)
  254. return nil
  255. }, 3*time.Second, func(counter int64, lastTsNs int64) error {
  256. if processor.processedTsWatermark == 0 {
  257. return nil
  258. }
  259. // use processor.processedTsWatermark instead of the lastTsNs from the most recent job
  260. now := time.Now().UnixNano()
  261. glog.V(0).Infof("sync %s to %s progressed to %v %0.2f/sec", sourceFiler, targetFiler, time.Unix(0, processor.processedTsWatermark), float64(counter)/(float64(now-lastLogTsNs)/1e9))
  262. lastLogTsNs = now
  263. // collect synchronous offset
  264. statsCollect.FilerSyncOffsetGauge.WithLabelValues(sourceFiler.String(), targetFiler.String(), clientName, sourcePath).Set(float64(processor.processedTsWatermark))
  265. return setOffset(grpcDialOption, targetFiler, getSignaturePrefixByPath(sourcePath), sourceFilerSignature, processor.processedTsWatermark)
  266. })
  267. metadataFollowOption := &pb.MetadataFollowOption{
  268. ClientName: clientName,
  269. ClientId: clientId,
  270. ClientEpoch: clientEpoch,
  271. SelfSignature: targetFilerSignature,
  272. PathPrefix: sourcePath,
  273. AdditionalPathPrefixes: nil,
  274. DirectoriesToWatch: nil,
  275. StartTsNs: sourceFilerOffsetTsNs,
  276. StopTsNs: 0,
  277. EventErrorType: pb.RetryForeverOnError,
  278. }
  279. return pb.FollowMetadata(sourceFiler, grpcDialOption, metadataFollowOption, processEventFnWithOffset)
  280. }
  281. // When each business is distinguished according to path, and offsets need to be maintained separately.
  282. func getSignaturePrefixByPath(path string) string {
  283. // compatible historical version
  284. if path == "/" {
  285. return SyncKeyPrefix
  286. } else {
  287. return SyncKeyPrefix + path
  288. }
  289. }
  290. func getOffset(grpcDialOption grpc.DialOption, filer pb.ServerAddress, signaturePrefix string, signature int32) (lastOffsetTsNs int64, readErr error) {
  291. readErr = pb.WithFilerClient(false, signature, filer, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  292. syncKey := []byte(signaturePrefix + "____")
  293. util.Uint32toBytes(syncKey[len(signaturePrefix):len(signaturePrefix)+4], uint32(signature))
  294. resp, err := client.KvGet(context.Background(), &filer_pb.KvGetRequest{Key: syncKey})
  295. if err != nil {
  296. return err
  297. }
  298. if len(resp.Error) != 0 {
  299. return errors.New(resp.Error)
  300. }
  301. if len(resp.Value) < 8 {
  302. return nil
  303. }
  304. lastOffsetTsNs = int64(util.BytesToUint64(resp.Value))
  305. return nil
  306. })
  307. return
  308. }
  309. func setOffset(grpcDialOption grpc.DialOption, filer pb.ServerAddress, signaturePrefix string, signature int32, offsetTsNs int64) error {
  310. return pb.WithFilerClient(false, signature, filer, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  311. syncKey := []byte(signaturePrefix + "____")
  312. util.Uint32toBytes(syncKey[len(signaturePrefix):len(signaturePrefix)+4], uint32(signature))
  313. valueBuf := make([]byte, 8)
  314. util.Uint64toBytes(valueBuf, uint64(offsetTsNs))
  315. resp, err := client.KvPut(context.Background(), &filer_pb.KvPutRequest{
  316. Key: syncKey,
  317. Value: valueBuf,
  318. })
  319. if err != nil {
  320. return err
  321. }
  322. if len(resp.Error) != 0 {
  323. return errors.New(resp.Error)
  324. }
  325. return nil
  326. })
  327. }
  328. func genProcessFunction(sourcePath string, targetPath string, excludePaths []string, reExcludeFileName *regexp.Regexp, dataSink sink.ReplicationSink, doDeleteFiles bool, debug bool) func(resp *filer_pb.SubscribeMetadataResponse) error {
  329. // process function
  330. processEventFn := func(resp *filer_pb.SubscribeMetadataResponse) error {
  331. message := resp.EventNotification
  332. var sourceOldKey, sourceNewKey util.FullPath
  333. if message.OldEntry != nil {
  334. sourceOldKey = util.FullPath(resp.Directory).Child(message.OldEntry.Name)
  335. }
  336. if message.NewEntry != nil {
  337. sourceNewKey = util.FullPath(message.NewParentPath).Child(message.NewEntry.Name)
  338. }
  339. if debug {
  340. glog.V(0).Infof("received %v", resp)
  341. }
  342. if !strings.HasPrefix(resp.Directory, sourcePath) {
  343. return nil
  344. }
  345. for _, excludePath := range excludePaths {
  346. if strings.HasPrefix(resp.Directory, excludePath) {
  347. return nil
  348. }
  349. }
  350. if reExcludeFileName != nil && reExcludeFileName.MatchString(message.NewEntry.Name) {
  351. return nil
  352. }
  353. if dataSink.IsIncremental() {
  354. doDeleteFiles = false
  355. }
  356. // handle deletions
  357. if filer_pb.IsDelete(resp) {
  358. if doDeleteFiles {
  359. return nil
  360. }
  361. if !strings.HasPrefix(string(sourceOldKey), sourcePath) {
  362. return nil
  363. }
  364. key := buildKey(dataSink, message, targetPath, sourceOldKey, sourcePath)
  365. return dataSink.DeleteEntry(key, message.OldEntry.IsDirectory, message.DeleteChunks, message.Signatures)
  366. }
  367. // handle new entries
  368. if filer_pb.IsCreate(resp) {
  369. if !strings.HasPrefix(string(sourceNewKey), sourcePath) {
  370. return nil
  371. }
  372. key := buildKey(dataSink, message, targetPath, sourceNewKey, sourcePath)
  373. if err := dataSink.CreateEntry(key, message.NewEntry, message.Signatures); err != nil {
  374. return fmt.Errorf("create entry1 : %v", err)
  375. } else {
  376. return nil
  377. }
  378. }
  379. // this is something special?
  380. if filer_pb.IsEmpty(resp) {
  381. return nil
  382. }
  383. // handle updates
  384. if strings.HasPrefix(string(sourceOldKey), sourcePath) {
  385. // old key is in the watched directory
  386. if strings.HasPrefix(string(sourceNewKey), sourcePath) {
  387. // new key is also in the watched directory
  388. if doDeleteFiles {
  389. oldKey := util.Join(targetPath, string(sourceOldKey)[len(sourcePath):])
  390. message.NewParentPath = util.Join(targetPath, message.NewParentPath[len(sourcePath):])
  391. foundExisting, err := dataSink.UpdateEntry(string(oldKey), message.OldEntry, message.NewParentPath, message.NewEntry, message.DeleteChunks, message.Signatures)
  392. if foundExisting {
  393. return err
  394. }
  395. // not able to find old entry
  396. if err = dataSink.DeleteEntry(string(oldKey), message.OldEntry.IsDirectory, false, message.Signatures); err != nil {
  397. return fmt.Errorf("delete old entry %v: %v", oldKey, err)
  398. }
  399. }
  400. // create the new entry
  401. newKey := buildKey(dataSink, message, targetPath, sourceNewKey, sourcePath)
  402. if err := dataSink.CreateEntry(newKey, message.NewEntry, message.Signatures); err != nil {
  403. return fmt.Errorf("create entry2 : %v", err)
  404. } else {
  405. return nil
  406. }
  407. } else {
  408. // new key is outside of the watched directory
  409. if doDeleteFiles {
  410. key := buildKey(dataSink, message, targetPath, sourceOldKey, sourcePath)
  411. return dataSink.DeleteEntry(key, message.OldEntry.IsDirectory, message.DeleteChunks, message.Signatures)
  412. }
  413. }
  414. } else {
  415. // old key is outside of the watched directory
  416. if strings.HasPrefix(string(sourceNewKey), sourcePath) {
  417. // new key is in the watched directory
  418. key := buildKey(dataSink, message, targetPath, sourceNewKey, sourcePath)
  419. if err := dataSink.CreateEntry(key, message.NewEntry, message.Signatures); err != nil {
  420. return fmt.Errorf("create entry3 : %v", err)
  421. } else {
  422. return nil
  423. }
  424. } else {
  425. // new key is also outside of the watched directory
  426. // skip
  427. }
  428. }
  429. return nil
  430. }
  431. return processEventFn
  432. }
  433. func buildKey(dataSink sink.ReplicationSink, message *filer_pb.EventNotification, targetPath string, sourceKey util.FullPath, sourcePath string) (key string) {
  434. if !dataSink.IsIncremental() {
  435. key = util.Join(targetPath, string(sourceKey)[len(sourcePath):])
  436. } else {
  437. var mTime int64
  438. if message.NewEntry != nil {
  439. mTime = message.NewEntry.Attributes.Mtime
  440. } else if message.OldEntry != nil {
  441. mTime = message.OldEntry.Attributes.Mtime
  442. }
  443. dateKey := time.Unix(mTime, 0).Format("2006-01-02")
  444. key = util.Join(targetPath, dateKey, string(sourceKey)[len(sourcePath):])
  445. }
  446. return escapeKey(key)
  447. }