super(message, e);
}
- /** @deprecated use {@link #ArgeoException(String, Throwable)} instead. */
- @Deprecated
- public ArgeoException(Throwable cause) {
- super(cause);
+ /**
+ * Chain the messages of all causes (one per line, <b>starts with a line
+ * return</b>) without all the stack
+ */
+ public static String chainCausesMessages(Throwable t) {
+ StringBuffer buf = new StringBuffer();
+ chainCauseMessage(buf, t);
+ return buf.toString();
}
+ /** Recursive chaining of messages */
+ private static void chainCauseMessage(StringBuffer buf, Throwable t) {
+ buf.append('\n').append(' ').append(t.getClass().getCanonicalName())
+ .append(": ").append(t.getMessage());
+ if (t.getCause() != null)
+ chainCauseMessage(buf, t.getCause());
+ }
}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.server;
-
-import org.argeo.ArgeoException;
-
-/** @deprecated use {@link ArgeoException} instead */
-public class ArgeoServerException extends ArgeoException {
- private static final long serialVersionUID = 1L;
-
- public ArgeoServerException(String message) {
- super(message);
- }
-
- public ArgeoServerException(Throwable cause) {
- super(cause);
- }
-
- public ArgeoServerException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
this.name = name;
}
+ public void init() {
+ if (name == null)
+ throw new ArgeoException("Atomic backup name must be set");
+ }
+
+ public void destroy() {
+
+ }
+
@Override
public String backup(FileSystemManager fileSystemManager,
String backupsBase, BackupContext backupContext,
this.name = name;
}
+ public String getName() {
+ return name;
+ }
+
public void setCompression(String compression) {
this.compression = compression;
}
/** Performs the backup of a single component, typically a database dump */
public interface AtomicBackup {
+ /** Name identifiying this backup */
+ public String getName();
+
/**
* Retrieves the data of the component in a format that allows to restore
* the component
* @return the VFS URI of the generated file or directory
*/
public String backup(FileSystemManager fileSystemManager,
- String backupsBase, BackupContext backupContext, FileSystemOptions opts);
+ String backupsBase, BackupContext backupContext,
+ FileSystemOptions opts);
}
package org.argeo.server.backup;
import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileSystemException;
/** Backup utilities */
public class BackupUtils {
if (fo != null) {
try {
fo.close();
- } catch (FileSystemException e) {
+ } catch (Exception e) {
// silent
}
}
}
-
+
/** Prevents instantiation */
private BackupUtils() {
}
}
public MySqlBackup(String dbUser, String dbPassword, String dbName) {
- super(dbName);
+ super(dbName + ".sql");
this.dbUser = dbUser;
this.dbPassword = dbPassword;
this.dbName = dbName;
}
+ @Override
+ public void init() {
+ if (getName() == null)
+ setName(dbName + ".sql");
+ super.init();
+ }
+
@Override
public void writeBackup(FileObject targetFo) {
if (getCommand() == null)
} catch (ExecuteException e) {
byte[] err = errBos.toByteArray();
String errStr = new String(err);
- throw new ArgeoException("Process " + commandLine
- + " failed with exit value " + e.getExitValue() + ": "
- + errStr, e);
+ throw new ArgeoException("Process " + commandLine + " failed ("
+ + e.getExitValue() + "): " + errStr, e);
} catch (Exception e) {
byte[] err = errBos.toByteArray();
String errStr = new String(err);
backupPurge.purge(fileSystemManager, backupsBase, systemName,
backupContext.getDateFormat(), opts);
} catch (Exception e) {
- failures.add(e.getMessage());
+ failures.add("Purge " + backupsBase + " failed: " + e.getMessage());
log.error("Purge of " + backupsBase + " failed", e);
}
if (log.isDebugEnabled())
log.debug("Performed backup " + target);
} catch (Exception e) {
- failures.add(e.getMessage());
- log.error("Atomic backup failed", e);
+ String msg = "Atomic backup " + atomickBackup.getName()
+ + " failed: " + ArgeoException.chainCausesMessages(e);
+ failures.add(msg);
+ log.error(msg);
+ if (log.isTraceEnabled())
+ log.trace(
+ "Stacktrace of atomic backup "
+ + atomickBackup.getName() + " failure.", e);
}
}
FileObject remoteBaseFo = null;
UserAuthenticator auth = remoteBases.get(remoteBase);
+ // authentication
+ FileSystemOptions remoteOpts = new FileSystemOptions();
try {
- // authentication
- FileSystemOptions remoteOpts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance()
.setUserAuthenticator(remoteOpts, auth);
backupPurge.purge(fileSystemManager, remoteBase, systemName,
backupContext.getDateFormat(), remoteOpts);
+ } catch (Exception e) {
+ failures.add("Purge " + remoteBase + " failed: "
+ + e.getMessage());
+ log.error("Cannot purge " + remoteBase, e);
+ }
+ try {
localBaseFo = fileSystemManager.resolveFile(backupsBase + '/'
+ backupContext.getRelativeFolder(), opts);
remoteBaseFo = fileSystemManager.resolveFile(remoteBase + '/'
log.debug("Copied backup to " + remoteBaseFo + " from "
+ localBaseFo);
// }
- } catch (FileSystemException e) {
+ } catch (Exception e) {
+ failures.add("Dispatch to " + remoteBase + " failed: "
+ + e.getMessage());
log.error(
"Cannot dispatch backups from "
+ backupContext.getRelativeFolder() + " to "
BackupUtils.closeFOQuietly(remoteBaseFo);
}
+ int failureCount = 0;
if (failures.size() > 0) {
StringBuffer buf = new StringBuffer();
- for (String failure : failures)
- buf.append('\n').append(failure);
- throw new ArgeoException("Errors when running the backup,"
+ for (String failure : failures) {
+ buf.append('\n').append(failureCount).append(" - ")
+ .append(failure);
+ failureCount++;
+ }
+ throw new ArgeoException(failureCount
+ + " error(s) when running the backup,"
+ " check the logs and the backups as soon as possible."
+ buf);
}