First testing of full snapshotting
parent
cdb78e0486
commit
bbcb8f7c9b
Binary file not shown.
@ -0,0 +1,34 @@
|
|||||||
|
import sqlite3
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Database file
|
||||||
|
db_file = 'mydatabase.db'
|
||||||
|
|
||||||
|
# Open a connection to SQLite database
|
||||||
|
conn = sqlite3.connect(db_file)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Enable WAL mode and disable automatic checkpointing
|
||||||
|
cursor.execute("PRAGMA journal_mode=WAL;")
|
||||||
|
cursor.execute("PRAGMA wal_autocheckpoint=0;")
|
||||||
|
cursor.execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, value TEXT);")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Checkpoint the WAL file so we've got just a SQLite file
|
||||||
|
conn.execute("PRAGMA wal_checkpoint(TRUNCATE);")
|
||||||
|
shutil.copy(db_file, 'backup.db')
|
||||||
|
|
||||||
|
for i in range(0, 4):
|
||||||
|
# Write a new row
|
||||||
|
cursor.execute(f"INSERT INTO foo (value) VALUES ('Row {i}');")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Copy the newly-created WAL
|
||||||
|
shutil.copy(db_file + '-wal', f'wal-{i:02}')
|
||||||
|
|
||||||
|
# Checkpoint the WAL file
|
||||||
|
conn.execute("PRAGMA wal_checkpoint(TRUNCATE);")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
conn.close()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"Version":1,"ID":"2-18-1686659761026","Index":18,"Term":2,"Peers":"ka5sb2NhbGhvc3Q6NDAwMg==","Configuration":{"Servers":[{"Suffrage":0,"ID":"node1","Address":"localhost:4002"}]},"ConfigurationIndex":1,"Size":293,"CRC":"QhU1tAtfgpo="}
|
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
{"Version":1,"ID":"2-8-1686659756627","Index":8,"Term":2,"Peers":"ka5sb2NhbGhvc3Q6NDAwMg==","Configuration":{"Servers":[{"Suffrage":0,"ID":"node1","Address":"localhost:4002"}]},"ConfigurationIndex":1,"Size":250,"CRC":"oInhBEZSzOo="}
|
Loading…
Reference in New Issue