From be523aa54f66e56c413b84f4253081ef422f7c6e Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Mon, 30 Nov 2020 15:45:15 +0100 Subject: [PATCH] backup: restore default filename lightningd.sqlite3 --- backup/backup.py | 6 +++++- backup/test_backup.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backup/backup.py b/backup/backup.py index bb457f3..c63afdf 100755 --- a/backup/backup.py +++ b/backup/backup.py @@ -117,8 +117,12 @@ class Backend(object): def restore(self, dest: str, remove_existing: bool = False): """Restore the backup in this backend to its former glory. - """ + If `dest` is a directory, we assume the default database filename: + lightningd.sqlite3 + """ + if os.path.isdir(dest): + dest = os.path.join(dest, "lightningd.sqlite3") if os.path.exists(dest): if not remove_existing: raise ValueError( diff --git a/backup/test_backup.py b/backup/test_backup.py index 82c8dbe..6096702 100644 --- a/backup/test_backup.py +++ b/backup/test_backup.py @@ -192,6 +192,27 @@ def test_restore(node_factory, directory): subprocess.check_call([cli_path, "restore", bdest, rdest]) +def test_restore_dir(node_factory, directory): + bpath = os.path.join(directory, 'lightning-1', 'regtest') + bdest = 'file://' + os.path.join(bpath, 'backup.dbak') + os.makedirs(bpath) + subprocess.check_call([cli_path, "init", bpath, bdest]) + opts = { + 'plugin': plugin_path, + 'allow-deprecated-apis': deprecated_apis, + } + l1 = node_factory.get_node(options=opts, cleandir=False) + l1.stop() + + # should raise error without remove_existing + with pytest.raises(Exception): + subprocess.check_call([cli_path, "restore", bdest, bpath]) + + # but succeed when we remove the sqlite3 dbfile before + os.remove(os.path.join(bpath, "lightningd.sqlite3")) + subprocess.check_call([cli_path, "restore", bdest, bpath]) + + def test_warning(directory, node_factory): bpath = os.path.join(directory, 'lightning-1', 'regtest') bdest = 'file://' + os.path.join(bpath, 'backup.dbak')