63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
|
|
// 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)
|
|||
|
|
}
|
|||
|
|
}
|