fix #746 add system.properties backup

This commit is contained in:
Shinsuke Sugaya 2016-10-17 23:00:11 +09:00
parent ea3f8baa83
commit cfbc2210d8
4 changed files with 54 additions and 21 deletions

View file

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

View file

@ -17,6 +17,8 @@ package org.codelibs.fess.app.web.admin.backup;
import static org.codelibs.core.stream.StreamUtil.stream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
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.CurlResponse;
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.ResourceUtil;
import org.lastaflute.core.magic.async.AsyncManager;
@ -70,20 +73,29 @@ public class AdminBackupAction extends FessAdminAction {
validate(form, messages -> {}, () -> asListHtml());
verifyToken(() -> asListHtml());
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) {
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));
@ -93,13 +105,34 @@ public class AdminBackupAction extends FessAdminAction {
@Execute
public ActionResponse download(final String 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), () -> {
return asListHtml();

View file

@ -517,7 +517,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. 1,2 */
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";
/** 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>
* 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
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/

View file

@ -270,7 +270,7 @@ smb.role.from.file=true
smb.available.sid.types=1,2
# 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