From 15d6df80a5f4a6b68f7a5c904acd534f01058b8f Mon Sep 17 00:00:00 2001 From: qishenonly <1050026498@qq.com> Date: Tue, 23 Jan 2024 11:21:20 +0800 Subject: [PATCH] database backup --- db/engine/db.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db/engine/db.go b/db/engine/db.go index 80d9189..ee8a0da 100644 --- a/db/engine/db.go +++ b/db/engine/db.go @@ -8,6 +8,7 @@ import ( "github.com/ByteStorage/FlyDB/config" data2 "github.com/ByteStorage/FlyDB/db/data" "github.com/ByteStorage/FlyDB/db/index" + "github.com/ByteStorage/FlyDB/lib/backup" "github.com/ByteStorage/FlyDB/lib/const" "go.uber.org/zap" "io" @@ -544,6 +545,15 @@ func (db *DB) loadIndexFromDataFiles() error { return nil } +// Backup the database to the specified directory +func (db *DB) Backup(dir string) error { + db.lock.RLock() + defer db.lock.RUnlock() + + // Create a backup directory + return backup.CopyDir(db.options.DirPath, dir) +} + // Clean the DB data directory after the test is complete func (db *DB) Clean() { if db != nil {