Skip to content

Commit

Permalink
Merge pull request #4549 from nozzle/backup-myrocks-dir
Browse files Browse the repository at this point in the history
mysqlctl: add MyRocks dir/files to backups
  • Loading branch information
derekperkins authored Jan 25, 2019
2 parents 3bd115f + 0eb3b4e commit b92f377
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion go/vt/mysqlctl/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func isDbDir(p string) bool {
return true
}

// Look for at least one .frm file
// Look for at least one database file
fis, err := ioutil.ReadDir(p)
if err != nil {
return false
Expand All @@ -174,6 +174,12 @@ func isDbDir(p string) bool {
return true
}

// the MyRocks engine stores data in RocksDB .sst files
// https://github.com/facebook/rocksdb/wiki/Rocksdb-BlockBasedTable-Format
if strings.HasSuffix(fi.Name(), ".sst") {
return true
}

// .frm files were removed in MySQL 8, so we need to check for two other file types
// https://dev.mysql.com/doc/refman/8.0/en/data-dictionary-file-removal.html
if strings.HasSuffix(fi.Name(), ".ibd") {
Expand Down
18 changes: 17 additions & 1 deletion go/vt/mysqlctl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func TestFindFilesToBackup(t *testing.T) {
dataDbDir := path.Join(dataDir, "vt_db")
extraDir := path.Join(dataDir, "extra_dir")
outsideDbDir := path.Join(root, "outside_db")
for _, s := range []string{innodbDataDir, innodbLogDir, dataDbDir, extraDir, outsideDbDir} {
rocksdbDir := path.Join(dataDir, ".rocksdb")
sdiOnlyDir := path.Join(dataDir, "sdi_dir")
for _, s := range []string{innodbDataDir, innodbLogDir, dataDbDir, extraDir, outsideDbDir, rocksdbDir, sdiOnlyDir} {
if err := os.MkdirAll(s, os.ModePerm); err != nil {
t.Fatalf("failed to create directory %v: %v", s, err)
}
Expand All @@ -62,6 +64,12 @@ func TestFindFilesToBackup(t *testing.T) {
if err := os.Symlink(outsideDbDir, path.Join(dataDir, "vt_symlink")); err != nil {
t.Fatalf("failed to symlink vt_symlink: %v", err)
}
if err := ioutil.WriteFile(path.Join(rocksdbDir, "000011.sst"), []byte("rocksdb file"), os.ModePerm); err != nil {
t.Fatalf("failed to write file 000011.sst: %v", err)
}
if err := ioutil.WriteFile(path.Join(sdiOnlyDir, "table1.sdi"), []byte("sdi file"), os.ModePerm); err != nil {
t.Fatalf("failed to write file table1.sdi: %v", err)
}

cnf := &Mycnf{
InnodbDataHomeDir: innodbDataDir,
Expand All @@ -76,6 +84,14 @@ func TestFindFilesToBackup(t *testing.T) {
sort.Sort(forTest(result))
t.Logf("findFilesToBackup returned: %v", result)
expected := []FileEntry{
{
Base: "Data",
Name: ".rocksdb/000011.sst",
},
{
Base: "Data",
Name: "sdi_dir/table1.sdi",
},
{
Base: "Data",
Name: "vt_db/db.opt",
Expand Down

0 comments on commit b92f377

Please sign in to comment.