mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
Update DB WAL before backup #1300
This commit is contained in:
parent
c980a06969
commit
6411facf6a
3 changed files with 21 additions and 0 deletions
|
@ -112,3 +112,12 @@ func IsSQLiteDB(file io.ReaderAt) (bool, error) {
|
||||||
}
|
}
|
||||||
return bytes.Equal(buf, signature), nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -435,6 +435,11 @@ func (s *ServerService) GetConfigJson() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerService) GetDb() ([]byte, 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
|
// Open the file for reading
|
||||||
file, err := os.Open(config.GetDBPath())
|
file, err := os.Open(config.GetDBPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"x-ui/config"
|
"x-ui/config"
|
||||||
|
"x-ui/database"
|
||||||
"x-ui/database/model"
|
"x-ui/database/model"
|
||||||
"x-ui/logger"
|
"x-ui/logger"
|
||||||
"x-ui/util/common"
|
"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"))
|
output := t.I18nBot("tgbot.messages.backupTime", "Time=="+time.Now().Format("2006-01-02 15:04:05"))
|
||||||
t.SendMsgToTgbot(chatId, output)
|
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())
|
file, err := os.Open(config.GetDBPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("Error in opening db file for backup: ", err)
|
logger.Warning("Error in opening db file for backup: ", err)
|
||||||
|
|
Loading…
Reference in a new issue