mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-20 06:34:20 +01:00
backup: Ensure at startup that the backup backend was initialized
This commit is contained in:
@@ -230,22 +230,22 @@ def on_init(options: Mapping[str, str], plugin: Plugin, **kwargs):
|
|||||||
destination = options['backup-destination']
|
destination = options['backup-destination']
|
||||||
|
|
||||||
# Ensure that we don't inadventently switch the destination
|
# Ensure that we don't inadventently switch the destination
|
||||||
if os.path.exists("backup.lock"):
|
if not os.path.exists("backup.lock"):
|
||||||
d = json.load(open("backup.lock", 'r'))
|
print("Files in the current directory {}".format(", ".join(os.listdir("."))))
|
||||||
if destination is None or destination == 'null':
|
return abort("Could not find backup.lock in the lightning-dir, have you initialized using the backup-cli utility?")
|
||||||
destination = d['backend_url']
|
|
||||||
elif destination != d['backend_url']:
|
d = json.load(open("backup.lock", 'r'))
|
||||||
abort(
|
if destination is None or destination == 'null':
|
||||||
"The destination specified as option does not match the one "
|
destination = d['backend_url']
|
||||||
"specified in backup.lock. Please check your settings"
|
elif destination != d['backend_url']:
|
||||||
)
|
abort(
|
||||||
|
"The destination specified as option does not match the one "
|
||||||
|
"specified in backup.lock. Please check your settings"
|
||||||
|
)
|
||||||
|
|
||||||
if not plugin.db_path.startswith('sqlite3'):
|
if not plugin.db_path.startswith('sqlite3'):
|
||||||
abort("The backup plugin only works with the sqlite3 database.")
|
abort("The backup plugin only works with the sqlite3 database.")
|
||||||
|
|
||||||
if destination == 'null':
|
|
||||||
abort("You must specify a backup destination, possibly on a secondary disk.")
|
|
||||||
|
|
||||||
# Let's initialize the backed. First we need to figure out which backend to use.
|
# Let's initialize the backed. First we need to figure out which backend to use.
|
||||||
backend_cl = resolve_backend_class(destination)
|
backend_cl = resolve_backend_class(destination)
|
||||||
if backend_cl is None:
|
if backend_cl is None:
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ from flaky import flaky
|
|||||||
from pyln.client import RpcError
|
from pyln.client import RpcError
|
||||||
from pyln.testing.fixtures import *
|
from pyln.testing.fixtures import *
|
||||||
import os
|
import os
|
||||||
import time
|
import pytest
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
@@ -13,14 +12,22 @@ cli_path = os.path.join(os.path.dirname(__file__), "backup-cli")
|
|||||||
|
|
||||||
|
|
||||||
def test_start(node_factory, directory):
|
def test_start(node_factory, directory):
|
||||||
bdest = os.path.join(directory, 'backup.dbak')
|
bdest = os.path.join(directory, 'lightning-1', 'backup.dbak')
|
||||||
opts = {
|
opts = {
|
||||||
'plugin': plugin_path,
|
'plugin': plugin_path,
|
||||||
'backup-destination': 'file://' + bdest,
|
'backup-destination': 'file://' + bdest,
|
||||||
}
|
}
|
||||||
|
|
||||||
subprocess.check_call([cli_path, "init", directory, directory])
|
subprocess.check_call([cli_path, "init", directory, directory])
|
||||||
l1 = node_factory.get_node(options=opts)
|
bpath = os.path.join(directory, 'lightning-1', 'regtest')
|
||||||
|
bdest = os.path.join(bpath, 'backup.dbak')
|
||||||
|
os.makedirs(bpath)
|
||||||
|
subprocess.check_call([cli_path, "init", bpath, bpath])
|
||||||
|
opts = {
|
||||||
|
'plugin': plugin_path,
|
||||||
|
'backup-destination': 'file://' + bdest,
|
||||||
|
}
|
||||||
|
l1 = node_factory.get_node(options=opts, cleandir=False)
|
||||||
|
|
||||||
l1.daemon.wait_for_log(r'backup.py')
|
l1.daemon.wait_for_log(r'backup.py')
|
||||||
|
|
||||||
@@ -40,13 +47,15 @@ def test_tx_abort(node_factory, directory):
|
|||||||
inbetween the hook call and the DB transaction.
|
inbetween the hook call and the DB transaction.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
bdest = os.path.join(directory, 'backup.dbak')
|
bpath = os.path.join(directory, 'lightning-1', 'regtest')
|
||||||
|
bdest = os.path.join(bpath, 'backup.dbak')
|
||||||
|
os.makedirs(bpath)
|
||||||
|
subprocess.check_call([cli_path, "init", bpath, bpath])
|
||||||
opts = {
|
opts = {
|
||||||
'plugin': plugin_path,
|
'plugin': plugin_path,
|
||||||
'backup-destination': 'file://' + bdest,
|
'backup-destination': 'file://' + bdest,
|
||||||
}
|
}
|
||||||
subprocess.check_call([cli_path, "init", directory, directory])
|
l1 = node_factory.get_node(options=opts, cleandir=False)
|
||||||
l1 = node_factory.get_node(options=opts)
|
|
||||||
l1.stop()
|
l1.stop()
|
||||||
|
|
||||||
print(l1.db.query("SELECT * FROM vars;"))
|
print(l1.db.query("SELECT * FROM vars;"))
|
||||||
@@ -68,12 +77,15 @@ def test_failing_restore(nf, directory):
|
|||||||
in the database back to n-2, which is non-recoverable.
|
in the database back to n-2, which is non-recoverable.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
bpath = os.path.join(directory, 'lightning-1', 'regtest')
|
||||||
|
bdest = os.path.join(bpath, 'backup.dbak')
|
||||||
|
os.makedirs(bpath)
|
||||||
|
subprocess.check_call([cli_path, "init", bpath, bpath])
|
||||||
opts = {
|
opts = {
|
||||||
'plugin': plugin_path,
|
'plugin': plugin_path,
|
||||||
'backup-destination': 'file://' + os.path.join(directory, 'backup.dbak')
|
'backup-destination': 'file://' + bdest,
|
||||||
}
|
}
|
||||||
subprocess.check_call([cli_path, "init", directory, directory])
|
l1 = node_factory.get_node(options=opts, cleandir=False)
|
||||||
l1 = node_factory.get_node(options=opts)
|
|
||||||
l1.stop()
|
l1.stop()
|
||||||
|
|
||||||
# Now fudge the data_version:
|
# Now fudge the data_version:
|
||||||
@@ -90,13 +102,15 @@ def test_intermittent_backup(node_factory, directory):
|
|||||||
"""Simulate intermittent use of the backup, or an old file backup.
|
"""Simulate intermittent use of the backup, or an old file backup.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
bpath = os.path.join(directory, 'lightning-1', 'regtest')
|
||||||
|
bdest = os.path.join(bpath, 'backup.dbak')
|
||||||
|
os.makedirs(bpath)
|
||||||
|
subprocess.check_call([cli_path, "init", bpath, bpath])
|
||||||
opts = {
|
opts = {
|
||||||
'plugin': plugin_path,
|
'plugin': plugin_path,
|
||||||
'backup-destination': 'file://' + os.path.join(directory, 'backup.dbak')
|
'backup-destination': 'file://' + bdest,
|
||||||
}
|
}
|
||||||
subprocess.check_call([cli_path, "init", directory, directory])
|
l1 = node_factory.get_node(options=opts, cleandir=False)
|
||||||
l1 = node_factory.get_node(options=opts)
|
|
||||||
|
|
||||||
# Now start without the plugin. This should work fine.
|
# Now start without the plugin. This should work fine.
|
||||||
del l1.daemon.opts['plugin']
|
del l1.daemon.opts['plugin']
|
||||||
|
|||||||
Reference in New Issue
Block a user