Files
jiang13-forum/services/backup.go
freefire fde5f628ec feat: opaque session、安装/发帖 SSR 与最小 Admin 后台
浏览器登录改为 DB sessions(可吊销);敏感词与 OIDC PEM 入 settings;
落地安装向导、注册发帖与 /admin 仪表盘/板块/审核/设置。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-29 05:44:16 +08:00

46 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package services
import (
"fmt"
"io"
"os"
"path/filepath"
"time"
"git.iioio.com/freefire/jiang13-forum/models"
)
type BackupService struct {
dbPath string
dataDir string
}
func NewBackupService(dbPath, dataDir string) *BackupService {
return &BackupService{dbPath: dbPath, dataDir: dataDir}
}
// ExportSQLite 导出 SQLite 备份文件到 data 目录(仅 sqlite
func (s *BackupService) ExportSQLite() (string, error) {
if models.DialectorName() != "sqlite" {
return "", fmt.Errorf("一键文件备份仅支持 SQLite当前为 %s请使用数据库自带备份工具", models.DialectorName())
}
src, err := os.Open(s.dbPath)
if err != nil {
return "", fmt.Errorf("打开数据库失败: %w", err)
}
defer src.Close()
filename := fmt.Sprintf("jiang13_backup_%s.db", time.Now().Format("20060102_150405"))
destPath := filepath.Join(s.dataDir, filename)
dst, err := os.Create(destPath)
if err != nil {
return "", err
}
defer dst.Close()
if _, err := io.Copy(dst, src); err != nil {
return "", err
}
return destPath, nil
}