From 7a5465fc56f79f5fc3c32547c89a80b7ebb24c8f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 8 Sep 2020 23:45:10 +0800 Subject: LFS support to be stored on minio (#12518) * LFS support to be stored on minio * Fix test * Fix lint * Fix lint * Fix check * Fix test * Update documents and add migration for LFS * Fix some bugs --- cmd/migrate_storage.go | 74 +++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 31 deletions(-) (limited to 'cmd') diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go index 3a26f0b3f5..b8e45c954d 100644 --- a/cmd/migrate_storage.go +++ b/cmd/migrate_storage.go @@ -83,6 +83,13 @@ func migrateAttachments(dstStorage storage.ObjectStorage) error { }) } +func migrateLFS(dstStorage storage.ObjectStorage) error { + return models.IterateLFS(func(mo *models.LFSMetaObject) error { + _, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath()) + return err + }) +} + func runMigrateStorage(ctx *cli.Context) error { if err := initDB(); err != nil { return err @@ -103,45 +110,50 @@ func runMigrateStorage(ctx *cli.Context) error { return err } + var dstStorage storage.ObjectStorage + var err error + switch ctx.String("store") { + case "local": + p := ctx.String("path") + if p == "" { + log.Fatal("Path must be given when store is loal") + return nil + } + dstStorage, err = storage.NewLocalStorage(p) + case "minio": + dstStorage, err = storage.NewMinioStorage( + context.Background(), + ctx.String("minio-endpoint"), + ctx.String("minio-access-key-id"), + ctx.String("minio-secret-access-key"), + ctx.String("minio-bucket"), + ctx.String("minio-location"), + ctx.String("minio-base-path"), + ctx.Bool("minio-use-ssl"), + ) + default: + return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store")) + } + + if err != nil { + return err + } + tp := ctx.String("type") switch tp { case "attachments": - var dstStorage storage.ObjectStorage - var err error - switch ctx.String("store") { - case "local": - p := ctx.String("path") - if p == "" { - log.Fatal("Path must be given when store is loal") - return nil - } - dstStorage, err = storage.NewLocalStorage(p) - case "minio": - dstStorage, err = storage.NewMinioStorage( - context.Background(), - ctx.String("minio-endpoint"), - ctx.String("minio-access-key-id"), - ctx.String("minio-secret-access-key"), - ctx.String("minio-bucket"), - ctx.String("minio-location"), - ctx.String("minio-base-path"), - ctx.Bool("minio-use-ssl"), - ) - default: - return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store")) - } - - if err != nil { + if err := migrateAttachments(dstStorage); err != nil { return err } - if err := migrateAttachments(dstStorage); err != nil { + case "lfs": + if err := migrateLFS(dstStorage); err != nil { return err } - - log.Warn("All files have been copied to the new placement but old files are still on the orignial placement.") - - return nil + default: + return fmt.Errorf("Unsupported storage: %s", ctx.String("type")) } + log.Warn("All files have been copied to the new placement but old files are still on the orignial placement.") + return nil } -- cgit v1.2.3