зеркало из https://github.com/github/vitess-gh.git
Simplifying file backup storage (implementation and plugins).
This commit is contained in:
Родитель
4c743918c0
Коммит
d0cc07ae69
|
@ -4,10 +4,6 @@
|
|||
|
||||
package main
|
||||
|
||||
import "github.com/youtube/vitess/go/vt/mysqlctl/backupstorage"
|
||||
|
||||
func init() {
|
||||
initFuncs = append(initFuncs, func() {
|
||||
backupstorage.RegisterFileBackupStorage()
|
||||
})
|
||||
}
|
||||
import (
|
||||
_ "github.com/youtube/vitess/go/vt/mysqlctl/backupstorage"
|
||||
)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright 2015, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/youtube/vitess/go/vt/mysqlctl/backupstorage"
|
||||
"github.com/youtube/vitess/go/vt/servenv"
|
||||
)
|
||||
|
||||
func init() {
|
||||
servenv.OnRun(func() {
|
||||
backupstorage.RegisterFileBackupStorage()
|
||||
})
|
||||
}
|
|
@ -45,7 +45,7 @@ func (fbh *FileBackupHandle) AddFile(filename string) (io.WriteCloser, error) {
|
|||
if fbh.readOnly {
|
||||
return nil, fmt.Errorf("AddFile cannot be called on read-only backup")
|
||||
}
|
||||
p := path.Join(fbh.fbs.root, fbh.bucket, fbh.name, filename)
|
||||
p := path.Join(*FileBackupStorageRoot, fbh.bucket, fbh.name, filename)
|
||||
return os.Create(p)
|
||||
}
|
||||
|
||||
|
@ -70,19 +70,17 @@ func (fbh *FileBackupHandle) ReadFile(filename string) (io.ReadCloser, error) {
|
|||
if !fbh.readOnly {
|
||||
return nil, fmt.Errorf("ReadFile cannot be called on read-write backup")
|
||||
}
|
||||
p := path.Join(fbh.fbs.root, fbh.bucket, fbh.name, filename)
|
||||
p := path.Join(*FileBackupStorageRoot, fbh.bucket, fbh.name, filename)
|
||||
return os.Open(p)
|
||||
}
|
||||
|
||||
// FileBackupStorage implements BackupStorage for local file system.
|
||||
type FileBackupStorage struct {
|
||||
root string
|
||||
}
|
||||
type FileBackupStorage struct{}
|
||||
|
||||
// ListBackups is part of the BackupStorage interface
|
||||
func (fbs *FileBackupStorage) ListBackups(bucket string) ([]BackupHandle, error) {
|
||||
// ReadDir already sorts the results
|
||||
p := path.Join(fbs.root, bucket)
|
||||
p := path.Join(*FileBackupStorageRoot, bucket)
|
||||
fi, err := ioutil.ReadDir(p)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
@ -112,7 +110,7 @@ func (fbs *FileBackupStorage) ListBackups(bucket string) ([]BackupHandle, error)
|
|||
// StartBackup is part of the BackupStorage interface
|
||||
func (fbs *FileBackupStorage) StartBackup(bucket, name string) (BackupHandle, error) {
|
||||
// make sure the bucket directory exists
|
||||
p := path.Join(fbs.root, bucket)
|
||||
p := path.Join(*FileBackupStorageRoot, bucket)
|
||||
if err := os.MkdirAll(p, os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -133,16 +131,10 @@ func (fbs *FileBackupStorage) StartBackup(bucket, name string) (BackupHandle, er
|
|||
|
||||
// RemoveBackup is part of the BackupStorage interface
|
||||
func (fbs *FileBackupStorage) RemoveBackup(bucket, name string) error {
|
||||
p := path.Join(fbs.root, bucket, name)
|
||||
p := path.Join(*FileBackupStorageRoot, bucket, name)
|
||||
return os.RemoveAll(p)
|
||||
}
|
||||
|
||||
// RegisterFileBackupStorage should be called after Flags has been
|
||||
// initialized, to register the FileBackupStorage implementation
|
||||
func RegisterFileBackupStorage() {
|
||||
if *FileBackupStorageRoot != "" {
|
||||
BackupStorageMap["file"] = &FileBackupStorage{
|
||||
root: *FileBackupStorageRoot,
|
||||
}
|
||||
}
|
||||
func init() {
|
||||
BackupStorageMap["file"] = &FileBackupStorage{}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,13 @@ func setupFileBackupStorage(t *testing.T) *FileBackupStorage {
|
|||
if err != nil {
|
||||
t.Fatalf("os.TempDir failed: %v", err)
|
||||
}
|
||||
return &FileBackupStorage{
|
||||
root: root,
|
||||
}
|
||||
*FileBackupStorageRoot = root
|
||||
return &FileBackupStorage{}
|
||||
}
|
||||
|
||||
// cleanupFileBackupStorage removes the entire directory
|
||||
func cleanupFileBackupStorage(fbs *FileBackupStorage) {
|
||||
os.RemoveAll(fbs.root)
|
||||
os.RemoveAll(*FileBackupStorageRoot)
|
||||
}
|
||||
|
||||
func TestListBackups(t *testing.T) {
|
||||
|
|
|
@ -40,7 +40,6 @@ func TestBackupRestore(t *testing.T) {
|
|||
fbsRoot := path.Join(root, "fbs")
|
||||
*backupstorage.FileBackupStorageRoot = fbsRoot
|
||||
*backupstorage.BackupStorageImplementation = "file"
|
||||
backupstorage.RegisterFileBackupStorage()
|
||||
|
||||
// Initialize the fake mysql root directories
|
||||
sourceInnodbDataDir := path.Join(root, "source_innodb_data")
|
||||
|
|
Загрузка…
Ссылка в новой задаче