Prechádzať zdrojové kódy

fix #746 add system.properties backup

Shinsuke Sugaya 8 rokov pred
rodič
commit
cfbc2210d8

+ 1 - 1
pom.xml

@@ -1098,7 +1098,7 @@
 		<dependency>
 		<dependency>
 			<groupId>org.codelibs</groupId>
 			<groupId>org.codelibs</groupId>
 			<artifactId>corelib</artifactId>
 			<artifactId>corelib</artifactId>
-			<version>0.3.5</version>
+			<version>0.3.6-SNAPSHOT</version>
 		</dependency>
 		</dependency>
 		<dependency>
 		<dependency>
 			<groupId>org.codelibs</groupId>
 			<groupId>org.codelibs</groupId>

+ 50 - 17
src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java

@@ -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();

+ 2 - 2
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -517,7 +517,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. 1,2 */
     /** The key of the configuration. e.g. 1,2 */
     String SMB_AVAILABLE_SID_TYPES = "smb.available.sid.types";
     String SMB_AVAILABLE_SID_TYPES = "smb.available.sid.types";
 
 
-    /** The key of the configuration. e.g. .fess_basic_config,.fess_config,.fess_user */
+    /** The key of the configuration. e.g. .fess_basic_config.bulk,.fess_config.bulk,.fess_user.bulk,system.properties */
     String INDEX_BACKUP_TARGETS = "index.backup.targets";
     String INDEX_BACKUP_TARGETS = "index.backup.targets";
 
 
     /** The key of the configuration. e.g. admin */
     /** The key of the configuration. e.g. admin */
@@ -2535,7 +2535,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
 
 
     /**
     /**
      * Get the value for the key 'index.backup.targets'. <br>
      * Get the value for the key 'index.backup.targets'. <br>
-     * The value is, e.g. .fess_basic_config,.fess_config,.fess_user <br>
+     * The value is, e.g. .fess_basic_config.bulk,.fess_config.bulk,.fess_user.bulk,system.properties <br>
      * comment: backup
      * comment: backup
      * @return The value of found property. (NotNull: if not found, exception but basically no way)
      * @return The value of found property. (NotNull: if not found, exception but basically no way)
      */
      */

+ 1 - 1
src/main/resources/fess_config.properties

@@ -270,7 +270,7 @@ smb.role.from.file=true
 smb.available.sid.types=1,2
 smb.available.sid.types=1,2
 
 
 # backup
 # backup
-index.backup.targets=.fess_basic_config,.fess_config,.fess_user
+index.backup.targets=.fess_basic_config.bulk,.fess_config.bulk,.fess_user.bulk,system.properties
 
 
 # ========================================================================================
 # ========================================================================================
 #                                                                                     Web
 #                                                                                     Web