Files
code-utils/tools/dumpmeta/main.go
2026-08-14 07:52:01 +08:00

63 lines
1.6 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.
// dumpmeta读取本地 SQLite 的 sync_* 配置,排查同步实际连接的 MySQL 目标。
package main
import (
"database/sql"
"fmt"
"os"
"path/filepath"
_ "modernc.org/sqlite"
)
func main() {
dir, _ := os.UserConfigDir()
path := filepath.Join(dir, "CodeCount", "code-count.db")
if len(os.Args) > 1 {
path = os.Args[1]
}
db, err := sql.Open("sqlite", path)
if err != nil {
panic(err)
}
defer db.Close()
rows, err := db.Query(`SELECT key,value FROM settings WHERE key LIKE 'sync_%' ORDER BY key`)
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var k, v string
_ = rows.Scan(&k, &v)
if k == "sync_password" || k == "sync_enc_key" {
v = fmt.Sprintf("<len %d>", len(v))
}
fmt.Printf("%-22s = %s\n", k, v)
}
fmt.Println("---- festival_images ----")
fr, err := db.Query(`SELECT fest_key,LENGTH(value),updated_at,dirty FROM festival_images ORDER BY fest_key`)
if err == nil {
for fr.Next() {
var k, at string
var n, dirty int
_ = fr.Scan(&k, &n, &at, &dirty)
fmt.Printf("%-10s bytes=%-7d at=%s dirty=%d\n", k, n, at, dirty)
}
fr.Close()
} else {
fmt.Println("(no table)", err)
}
fmt.Println("---- recent warning/error logs ----")
lr, err := db.Query(`SELECT id,level,message,detail,created_at FROM app_logs WHERE level IN('warning','error') ORDER BY id DESC LIMIT 12`)
if err != nil {
panic(err)
}
defer lr.Close()
for lr.Next() {
var id int64
var level, msg, detail, at string
_ = lr.Scan(&id, &level, &msg, &detail, &at)
fmt.Printf("#%d [%s] %s | %s | %s\n", id, level, at, msg, detail)
}
}