-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafanadb.go
executable file
·55 lines (44 loc) · 1.16 KB
/
grafanadb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
_ "database/sql"
m "github.com/grafana/grafana/pkg/models"
"github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3"
)
func main() {
connstr := fmt.Sprintf("file:/root/lm/grafana.db?cache=private&mode=rwc")
engine, err := xorm.NewEngine("sqlite3", connstr)
if err != nil {
fmt.Printf("%s\n", err)
return
}
engine.SetMaxOpenConns(0)
var ids []int64
err = engine.Table("dashboard").Cols("id").Find(&ids)
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Println(ids)
var dashboards = make([]*m.Dashboard, 0)
engine.In("id", ids).Find(&dashboards)
for _, value := range dashboards {
fmt.Println(*value)
//fmt.Println(value.Data)
}
new_connstr := fmt.Sprintf("file:/root/lm/new_grafana.db?cache=private&mode=rwc")
new_engine, err := xorm.NewEngine("sqlite3", new_connstr)
if err != nil {
fmt.Printf("%s\n", err)
return
}
for _, value := range dashboards {
affected, err := new_engine.Insert(value)
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Printf("affected %d records\n", affected)
}
}