feat: add various infrastructure check and automation scripts
This commit is contained in:
47
scripts/check_heimdall_db_fixed.py
Normal file
47
scripts/check_heimdall_db_fixed.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import paramiko
|
||||
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect("140.44.4.71", username="snarf", password="Katzir476!", timeout=10)
|
||||
|
||||
py_code = '''
|
||||
import sqlite3
|
||||
import shutil
|
||||
import time
|
||||
|
||||
db_path = '/var/lib/docker/volumes/heimdall_heimdall_config/_data/www/app.sqlite'
|
||||
backup_name = db_path + '.backup_' + str(int(time.time()))
|
||||
shutil.copyfile(db_path, backup_name)
|
||||
print('Backup created:', backup_name)
|
||||
|
||||
con = sqlite3.connect(db_path)
|
||||
cur = con.cursor()
|
||||
|
||||
print('=== USERS ===')
|
||||
for r in cur.execute('SELECT id, username, email, public_front FROM users').fetchall():
|
||||
print('User:', r)
|
||||
|
||||
print('\\n=== ITEMS ===')
|
||||
rows = cur.execute('SELECT id, title, url, pinned, user_id, apporder FROM items').fetchall()
|
||||
print('Total items in DB:', len(rows))
|
||||
for r in rows:
|
||||
print('Item:', r)
|
||||
|
||||
print('\\n=== SETTINGS ===')
|
||||
for r in cur.execute('SELECT * FROM settings').fetchall():
|
||||
print('Setting:', r)
|
||||
'''
|
||||
|
||||
# Write script to /tmp/inspect_heimdall.py on remote host
|
||||
stdin, stdout, stderr = c.exec_command("cat > /tmp/inspect_heimdall.py")
|
||||
stdin.write(py_code)
|
||||
stdin.close()
|
||||
stdout.channel.recv_exit_status()
|
||||
|
||||
# Execute script with sudo
|
||||
_, o, e = c.exec_command("echo Katzir476! | sudo -S python3 /tmp/inspect_heimdall.py")
|
||||
print(o.read().decode())
|
||||
print(e.read().decode())
|
||||
|
||||
c.close()
|
||||
|
||||
Reference in New Issue
Block a user