changeset 1567:349eef23a13c

lucene named backup
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 14 Nov 2020 20:05:07 -0700
parents 364859d29ff5
children adba594db0b4
files src/luan/modules/host/backup.luan src/luan/modules/host/restore.luan src/luan/modules/lucene/Lucene.luan
diffstat 3 files changed, 31 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/host/backup.luan	Thu Nov 12 16:59:47 2020 -0700
+++ b/src/luan/modules/host/backup.luan	Sat Nov 14 20:05:07 2020 -0700
@@ -5,14 +5,14 @@
 local uri = Io.uri or error()
 local Hosting = require "luan:host/Hosting.luan"
 
-if #{...} ~= 2 then
-	Io.stderr.write "usage: luan luan:host/backup.luan domain password\n"
+if #{...} ~= 3 then
+	Io.stderr.write "usage: luan luan:host/backup.luan domain password name\n"
 	return
 end
 
-local domain, password = ...
+local domain, password, name = ...
 
-local zip = Hosting.caller(domain).lucene_backup(password)
+local zip = Hosting.caller(domain).lucene_backup(password,name)
 uri("file:backup.zip").write(zip)
 
 print("backed up lucene from "..domain.." to backup.zip")
--- a/src/luan/modules/host/restore.luan	Thu Nov 12 16:59:47 2020 -0700
+++ b/src/luan/modules/host/restore.luan	Sat Nov 14 20:05:07 2020 -0700
@@ -5,15 +5,15 @@
 local uri = Io.uri or error()
 local Hosting = require "luan:host/Hosting.luan"
 
-if #{...} ~= 2 then
-	Io.stderr.write "usage: luan luan:host/restore.luan domain password\n"
+if #{...} ~= 3 then
+	Io.stderr.write "usage: luan luan:host/restore.luan domain password name\n"
 	return
 end
 
-local domain, password = ...
+local domain, password, name = ...
 
 local zip_file = uri("file:backup.zip")
 zip_file.exists() or error "backup.zip not found"
-Hosting.caller(domain).lucene_restore(password,zip_file)
+Hosting.caller(domain).lucene_restore(password,name,zip_file)
 
 print("restored lucene from backup.zip to "..domain)
--- a/src/luan/modules/lucene/Lucene.luan	Thu Nov 12 16:59:47 2020 -0700
+++ b/src/luan/modules/lucene/Lucene.luan	Sat Nov 14 20:05:07 2020 -0700
@@ -24,6 +24,25 @@
 
 local Lucene = {}
 
+local indexes = {}
+
+function Rpc.functions.lucene_backup(password,name)
+	Io.password == password or error "wrong password"
+	local index = indexes[name] or error("index not found: "..name)
+	local zip_file = index.dir.parent().child("backup.zip")
+	index.zip(zip_file)
+	return zip_file
+end
+
+function Rpc.functions.lucene_restore(password,name,zip_file)
+	Io.password == password or error "wrong password"
+	local index = indexes[name] or error "index not found"
+	local backup_zip = index.dir.parent().child("backup.zip")
+	backup_zip.write(zip_file)
+	index.restore(backup_zip)
+end
+
+
 Lucene.type = {
 	english = LuceneIndex.ENGLISH_FIELD_PARSER
 	string = LuceneIndex.STRING_FIELD_PARSER
@@ -43,6 +62,10 @@
 
 function Lucene.index(index_dir,options)
 	local index = {}
+	if options.name ~= nil then
+		indexes[options.name] = index
+		options.name = nil
+	end
 	index.dir = index_dir
 	index_dir = get_file(index_dir)
 	options = options or {}
@@ -202,31 +225,6 @@
 		end
 	end
 
-	local function multi_error(...)
-		error "multiple lucene instances"
-	end
-
-	if Rpc.functions.lucene_backup == nil then
-
-		function Rpc.functions.lucene_backup(password)
-			Io.password == password or error "wrong password"
-			local zip_file = index.dir.parent().child("backup.zip")
-			index.zip(zip_file)
-			return zip_file
-		end
-
-		function Rpc.functions.lucene_restore(password,zip_file)
-			Io.password == password or error "wrong password"
-			local backup_zip = index.dir.parent().child("backup.zip")
-			backup_zip.write(zip_file)
-			index.restore(backup_zip)
-		end
-
-	else
-		Rpc.functions.lucene_backup = multi_error
-		Rpc.functions.lucene_restore = multi_error
-	end
-
 	return index
 end