36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import paramiko
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('140.44.4.71', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
py_script = """import sqlite3
|
|
import shutil
|
|
|
|
# 1. Backup
|
|
shutil.copyfile('/mnt/swarm_shared/legacy_volumes/gotify/_data/gotify.db', '/mnt/swarm_shared/legacy_volumes/gotify/_data/gotify.db.bak')
|
|
|
|
# 2. Fix NULL sort_key in _data
|
|
conn = sqlite3.connect('/mnt/swarm_shared/legacy_volumes/gotify/_data/gotify.db')
|
|
cur = conn.cursor()
|
|
cur.execute("UPDATE applications SET sort_key = 'a5' WHERE id = 6;")
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
# 3. Copy to parent directory where volume is bound
|
|
shutil.copyfile('/mnt/swarm_shared/legacy_volumes/gotify/_data/gotify.db', '/mnt/swarm_shared/legacy_volumes/gotify/gotify.db')
|
|
print("Successfully updated sort_key and synced database!")
|
|
"""
|
|
|
|
stdin, stdout, stderr = c.exec_command("cat > /tmp/fix_gotify.py && python3 /tmp/fix_gotify.py")
|
|
stdin.write(py_script)
|
|
stdin.close()
|
|
print(stdout.read().decode())
|
|
print(stderr.read().decode())
|
|
|
|
# Restart gotify service
|
|
print(c.exec_command("docker service update --force gotify_gotify")[1].read().decode())
|
|
|
|
c.close()
|
|
|