Sync 2026-04-14 08:07
This commit is contained in:
Binary file not shown.
BIN
state_merged.db
BIN
state_merged.db
Binary file not shown.
20
sync.sh
20
sync.sh
@@ -12,16 +12,11 @@ echo "[$(date '+%H:%M:%S')] Sync from $HOSTNAME..."
|
|||||||
python3 << PYEOF
|
python3 << PYEOF
|
||||||
import sqlite3, os, shutil, tempfile
|
import sqlite3, os, shutil, tempfile
|
||||||
|
|
||||||
local_db = os.path.join(os.environ['HERMES_HOME'], 'state.db')
|
local_db = os.path.join(os.path.expanduser('~/.hermes'), 'state.db')
|
||||||
export_db = os.path.join(os.environ['SYNC_DIR'], f"state_{os.environ['HOSTNAME']}.db")
|
export_db = os.path.join(os.path.expanduser('~/.hermes-sync'), f"state_{os.environ.get('HOSTNAME') or __import__('socket').gethostname()}.db")
|
||||||
tmpdir = tempfile.mkdtemp(prefix='hs_exp_')
|
tmpdir = tempfile.mkdtemp(prefix='hs_exp_')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = sqlite3.connect(local_db)
|
|
||||||
conn.execute('PRAGMA wal_checkpoint(TRUNCATE)')
|
|
||||||
conn.execute('PRAGMA optimize')
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
tmp_db = os.path.join(tmpdir, 'db')
|
tmp_db = os.path.join(tmpdir, 'db')
|
||||||
shutil.copy2(local_db, tmp_db)
|
shutil.copy2(local_db, tmp_db)
|
||||||
|
|
||||||
@@ -75,7 +70,7 @@ fi
|
|||||||
python3 << 'PYEOF'
|
python3 << 'PYEOF'
|
||||||
import sqlite3, os, glob, shutil, tempfile
|
import sqlite3, os, glob, shutil, tempfile
|
||||||
|
|
||||||
sync_dir = os.environ['SYNC_DIR']
|
sync_dir = os.path.expanduser('~/.hermes-sync')
|
||||||
merged_path = os.path.join(sync_dir, 'state_merged.db')
|
merged_path = os.path.join(sync_dir, 'state_merged.db')
|
||||||
db_files = sorted(glob.glob(os.path.join(sync_dir, 'state_*.db')))
|
db_files = sorted(glob.glob(os.path.join(sync_dir, 'state_*.db')))
|
||||||
db_files = [f for f in db_files if not f.endswith('_merged.db')]
|
db_files = [f for f in db_files if not f.endswith('_merged.db')]
|
||||||
@@ -176,8 +171,8 @@ fi
|
|||||||
python3 << 'PYEOF'
|
python3 << 'PYEOF'
|
||||||
import sqlite3, os, shutil, tempfile
|
import sqlite3, os, shutil, tempfile
|
||||||
|
|
||||||
hermes_home = os.environ['HERMES_HOME']
|
hermes_home = os.path.expanduser('~/.hermes')
|
||||||
merged_path = os.path.join(os.environ['SYNC_DIR'], 'state_merged.db')
|
merged_path = os.path.join(os.path.expanduser('~/.hermes-sync'), 'state_merged.db')
|
||||||
local_db = os.path.join(hermes_home, 'state.db')
|
local_db = os.path.join(hermes_home, 'state.db')
|
||||||
|
|
||||||
if not os.path.exists(merged_path):
|
if not os.path.exists(merged_path):
|
||||||
@@ -185,11 +180,6 @@ if not os.path.exists(merged_path):
|
|||||||
else:
|
else:
|
||||||
tmpdir = tempfile.mkdtemp(prefix='hs_rest_')
|
tmpdir = tempfile.mkdtemp(prefix='hs_rest_')
|
||||||
try:
|
try:
|
||||||
conn = sqlite3.connect(local_db)
|
|
||||||
conn.execute('PRAGMA wal_checkpoint(TRUNCATE)')
|
|
||||||
conn.execute('PRAGMA optimize')
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
tmp_db = os.path.join(tmpdir, 'db')
|
tmp_db = os.path.join(tmpdir, 'db')
|
||||||
shutil.copy2(merged_path, tmp_db)
|
shutil.copy2(merged_path, tmp_db)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user