From 6f48712a7dbd1007b4e894f7e9945670193b7f0c Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 18 Jul 2023 09:48:05 +0200 Subject: [PATCH] Reporting: Unbound DNS - modify pre-upgrade export hook, output when skipped or processed and transfer ownership to unbound --- src/etc/rc.syshook.d/upgrade/20-unbound-duckdb.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/etc/rc.syshook.d/upgrade/20-unbound-duckdb.py b/src/etc/rc.syshook.d/upgrade/20-unbound-duckdb.py index 89b6eb97d..850d0a59b 100755 --- a/src/etc/rc.syshook.d/upgrade/20-unbound-duckdb.py +++ b/src/etc/rc.syshook.d/upgrade/20-unbound-duckdb.py @@ -25,10 +25,20 @@ POSSIBILITY OF SUCH DAMAGE. """ import sys +import os +import shutil +import glob sys.path.insert(0, "/usr/local/opnsense/site-python") from duckdb_helper import DbConnection # export database in case the new storage version doesn't match with DbConnection('/var/unbound/data/unbound.duckdb', read_only=True) as db: if db.connection is not None: + os.makedirs('/var/cache/unbound.duckdb', mode=0o750, exist_ok=True) + shutil.chown('/var/cache/unbound.duckdb', 'unbound', 'unbound') db.connection.execute("EXPORT DATABASE '/var/cache/unbound.duckdb';") + for filename in glob.glob('/var/cache/unbound.duckdb/*'): + shutil.chown(filename, 'unbound', 'unbound') + print('database exported.') + else: + print('skip: no database found') \ No newline at end of file