|
@@ -17,6 +17,8 @@ package org.codelibs.fess.app.web.admin.backup;
|
|
|
|
|
|
import static org.codelibs.core.stream.StreamUtil.stream;
|
|
import static org.codelibs.core.stream.StreamUtil.stream;
|
|
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
@@ -33,6 +35,7 @@ import org.codelibs.core.lang.StringUtil;
|
|
import org.codelibs.elasticsearch.runner.net.Curl;
|
|
import org.codelibs.elasticsearch.runner.net.Curl;
|
|
import org.codelibs.elasticsearch.runner.net.CurlResponse;
|
|
import org.codelibs.elasticsearch.runner.net.CurlResponse;
|
|
import org.codelibs.fess.app.web.base.FessAdminAction;
|
|
import org.codelibs.fess.app.web.base.FessAdminAction;
|
|
|
|
+import org.codelibs.fess.util.ComponentUtil;
|
|
import org.codelibs.fess.util.RenderDataUtil;
|
|
import org.codelibs.fess.util.RenderDataUtil;
|
|
import org.codelibs.fess.util.ResourceUtil;
|
|
import org.codelibs.fess.util.ResourceUtil;
|
|
import org.lastaflute.core.magic.async.AsyncManager;
|
|
import org.lastaflute.core.magic.async.AsyncManager;
|
|
@@ -70,20 +73,29 @@ public class AdminBackupAction extends FessAdminAction {
|
|
validate(form, messages -> {}, () -> asListHtml());
|
|
validate(form, messages -> {}, () -> asListHtml());
|
|
verifyToken(() -> asListHtml());
|
|
verifyToken(() -> asListHtml());
|
|
asyncManager.async(() -> {
|
|
asyncManager.async(() -> {
|
|
- try (CurlResponse response = Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_bulk").onConnect((req, con) -> {
|
|
|
|
- con.setDoOutput(true);
|
|
|
|
- try (InputStream in = form.bulkFile.getInputStream(); OutputStream out = con.getOutputStream()) {
|
|
|
|
- CopyUtil.copy(in, out);
|
|
|
|
|
|
+ final String fileName = form.bulkFile.getFileName();
|
|
|
|
+ if (fileName.startsWith("system") && fileName.endsWith(".properties")) {
|
|
|
|
+ try (final InputStream in = form.bulkFile.getInputStream()) {
|
|
|
|
+ ComponentUtil.getSystemProperties().load(in);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- throw new IORuntimeException(e);
|
|
|
|
|
|
+ logger.warn("Failed to process system.properties file: " + form.bulkFile.getFileName(), e);
|
|
}
|
|
}
|
|
- }).execute()) {
|
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
|
- logger.debug("Bulk Response:\n" + response.getContentAsString());
|
|
|
|
|
|
+ } else {
|
|
|
|
+ try (CurlResponse response = Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_bulk").onConnect((req, con) -> {
|
|
|
|
+ con.setDoOutput(true);
|
|
|
|
+ try (InputStream in = form.bulkFile.getInputStream(); OutputStream out = con.getOutputStream()) {
|
|
|
|
+ CopyUtil.copy(in, out);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new IORuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }).execute()) {
|
|
|
|
+ if (logger.isDebugEnabled()) {
|
|
|
|
+ logger.debug("Bulk Response:\n" + response.getContentAsString());
|
|
|
|
+ }
|
|
|
|
+ systemHelper.reloadConfiguration();
|
|
|
|
+ } catch (final Exception e) {
|
|
|
|
+ logger.warn("Failed to process bulk file: " + form.bulkFile.getFileName(), e);
|
|
}
|
|
}
|
|
- systemHelper.reloadConfiguration();
|
|
|
|
- } catch (final Exception e) {
|
|
|
|
- logger.warn("Failed to process bulk file: " + form.bulkFile.getFileName(), e);
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
|
|
saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
|
|
@@ -93,13 +105,34 @@ public class AdminBackupAction extends FessAdminAction {
|
|
@Execute
|
|
@Execute
|
|
public ActionResponse download(final String id) {
|
|
public ActionResponse download(final String id) {
|
|
if (stream(fessConfig.getIndexBackupTargetsAsArray()).get(stream -> stream.anyMatch(s -> s.equals(id)))) {
|
|
if (stream(fessConfig.getIndexBackupTargetsAsArray()).get(stream -> stream.anyMatch(s -> s.equals(id)))) {
|
|
- return asStream(id + ".bulk").contentTypeOctetStream().stream(
|
|
|
|
- out -> {
|
|
|
|
- try (CurlResponse response =
|
|
|
|
- Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/" + id + "/_data").param("format", "json").execute()) {
|
|
|
|
- out.write(response.getContentAsStream());
|
|
|
|
|
|
+ if (id.equals("system.properties")) {
|
|
|
|
+ return asStream(id).contentTypeOctetStream().stream(out -> {
|
|
|
|
+ try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
|
|
|
+ ComponentUtil.getSystemProperties().store(baos, id);
|
|
|
|
+ try (final InputStream in = new ByteArrayInputStream(baos.toByteArray())) {
|
|
|
|
+ out.write(in);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ final String index;
|
|
|
|
+ final String filename;
|
|
|
|
+ if (id.endsWith(".bulk")) {
|
|
|
|
+ index = id.substring(0, id.length() - 5);
|
|
|
|
+ filename = id;
|
|
|
|
+ } else {
|
|
|
|
+ index = id;
|
|
|
|
+ filename = id + ".bulk";
|
|
|
|
+ }
|
|
|
|
+ return asStream(filename).contentTypeOctetStream().stream(
|
|
|
|
+ out -> {
|
|
|
|
+ try (CurlResponse response =
|
|
|
|
+ Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/" + index + "/_data").param("format", "json")
|
|
|
|
+ .execute()) {
|
|
|
|
+ out.write(response.getContentAsStream());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
throwValidationError(messages -> messages.addErrorsCouldNotFindBackupIndex(GLOBAL), () -> {
|
|
throwValidationError(messages -> messages.addErrorsCouldNotFindBackupIndex(GLOBAL), () -> {
|
|
return asListHtml();
|
|
return asListHtml();
|