Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlireza Ahmadi <alireza7@gmail.com>2023-12-08 22:35:10 +0300
committerAlireza Ahmadi <alireza7@gmail.com>2023-12-08 22:35:10 +0300
commit6411facf6af1ad1ad264f0e73303d472cc004635 (patch)
treee57d1a27fb78baee9d0994c072b72e7a0e2092b1
parentc980a06969c9595f0b0b7d5db301f2413506eb6f (diff)
Update DB WAL before backup #1300
-rw-r--r--database/db.go9
-rw-r--r--web/service/server.go5
-rw-r--r--web/service/tgbot.go7
3 files changed, 21 insertions, 0 deletions
diff --git a/database/db.go b/database/db.go
index aaeb8bd9..8bd0fb49 100644
--- a/database/db.go
+++ b/database/db.go
@@ -112,3 +112,12 @@ func IsSQLiteDB(file io.ReaderAt) (bool, error) {
}
return bytes.Equal(buf, signature), nil
}
+
+func Checkpoint() error {
+ // Update WAL
+ err := db.Exec("PRAGMA wal_checkpoint;").Error
+ if err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/web/service/server.go b/web/service/server.go
index 629d9253..49e6a2c0 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -435,6 +435,11 @@ func (s *ServerService) GetConfigJson() (interface{}, error) {
}
func (s *ServerService) GetDb() ([]byte, error) {
+ // Update by manually trigger a checkpoint operation
+ err := database.Checkpoint()
+ if err != nil {
+ return nil, err
+ }
// Open the file for reading
file, err := os.Open(config.GetDBPath())
if err != nil {
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index b54ceb1c..0847e418 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -9,6 +9,7 @@ import (
"strings"
"time"
"x-ui/config"
+ "x-ui/database"
"x-ui/database/model"
"x-ui/logger"
"x-ui/util/common"
@@ -1417,6 +1418,12 @@ func (t *Tgbot) sendBackup(chatId int64) {
output := t.I18nBot("tgbot.messages.backupTime", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
t.SendMsgToTgbot(chatId, output)
+ // Update by manually trigger a checkpoint operation
+ err := database.Checkpoint()
+ if err != nil {
+ logger.Warning("Error in trigger a checkpoint operation: ", err)
+ }
+
file, err := os.Open(config.GetDBPath())
if err != nil {
logger.Warning("Error in opening db file for backup: ", err)