You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_, err=conn.ExecContext(ctx, fmt.Sprintf("BACKUP DATABASE %s INTO '%s' AS OF SYSTEM TIME '%s' WITH revision_history", dbName, bucket, backupTS.AsOfSystemTime()))
84
+
// Back up by creating a schedule, to lay down a protected time stamp.
85
+
// Then take 1 full and 24 incrementals, as rapidly as possible - that is, one every minute.
86
+
_, err=conn.ExecContext(
87
+
ctx, fmt.Sprintf(
88
+
"CREATE SCHEDULE IF NOT EXISTS backup_restore_operation FOR BACKUP DATABASE %s INTO '%s' WITH revision_history RECURRING '* * * * *' FULL BACKUP '@weekly' with schedule options first_run='now'", dbName, bucket))
84
89
iferr!=nil {
85
90
o.Fatal(err)
86
91
}
87
-
fori:=range24 {
88
-
o.Status(fmt.Sprintf("backing up db %s (incremental layer %d)", dbName, i))
_, err=conn.ExecContext(ctx, fmt.Sprintf("BACKUP DATABASE %s INTO LATEST IN '%s' AS OF SYSTEM TIME '%s' WITH revision_history", dbName, bucket, backupTS.AsOfSystemTime()))
92
+
deferfunc() {
93
+
_, _=conn.Exec(fmt.Sprintf("DROP SCHEDULES WITH x AS (SHOW SCHEDULES) SELECT id FROM x WHERE label = 'backup_restore_operation';"))
rows, err:=conn.QueryContext(ctx, "WITH t AS (SHOW BACKUPS IN $1) SELECT * FROM t ORDER BY path DESC LIMIT 1", bucket)
92
107
iferr!=nil {
93
108
o.Fatal(err)
94
109
}
110
+
111
+
path:=""
112
+
if!rows.Next() {
113
+
o.Status("no backups found, retrying")
114
+
continue
115
+
}
116
+
iferr:=rows.Scan(&path); err!=nil {
117
+
o.Fatal(err)
118
+
}
119
+
120
+
res:=conn.QueryRowContext(ctx, "WITH t AS (SHOW BACKUP $1 in $2) SELECT COUNT(*) FROM t WHERE t.object_type='database' AND t.object_name=$3", path, bucket, dbName)
121
+
varcountint
122
+
iferr:=res.Scan(&count); err!=nil {
123
+
o.Fatal(err)
124
+
}
125
+
126
+
ifcount<25 {
127
+
o.Status(fmt.Sprintf("found %d layers, need 25", count))
128
+
continue
129
+
}
130
+
o.Status("found 25 layers, proceeding")
131
+
132
+
res=conn.QueryRowContext(ctx, "WITH t AS (SHOW BACKUP $1 in $2) SELECT end_time FROM t WHERE t.object_type='database' ORDER BY end_time DESC LIMIT 1", path, bucket)
0 commit comments