X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=inline;f=server%2Fruntime%2Forg.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fbackup%2FSystemBackup.java;h=92f73c7a6847837b70226b17cbcd740aa6b04fa6;hb=268d1f9bd80e47623f71a2496cf8959876cf6c00;hp=92b38c50bac14bc4dc7d3a7d62b7f1fc40a96f5a;hpb=9eb1585fe9b213d55398aedfdd48c998c30b46dc;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/SystemBackup.java b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/SystemBackup.java index 92b38c50b..92f73c7a6 100644 --- a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/SystemBackup.java +++ b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/backup/SystemBackup.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.backup; import java.util.ArrayList; @@ -29,7 +44,7 @@ public class SystemBackup implements Runnable { private UserAuthenticator userAuthenticator = null; private String backupsBase; - private String name; + private String systemName; private List atomicBackups = new ArrayList(); private BackupPurge backupPurge = new SimpleBackupPurge(); @@ -43,7 +58,7 @@ public class SystemBackup implements Runnable { List failures = new ArrayList(); SimpleBackupContext backupContext = new SimpleBackupContext( - fileSystemManager, backupsBase, name); + fileSystemManager, backupsBase, systemName); // purge older backups FileSystemOptions opts = new FileSystemOptions(); @@ -56,10 +71,10 @@ public class SystemBackup implements Runnable { try { - backupPurge.purge(fileSystemManager, backupsBase, name, + 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); } @@ -71,8 +86,14 @@ public class SystemBackup implements Runnable { 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); } } @@ -82,14 +103,20 @@ public class SystemBackup implements Runnable { 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, name, + 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 + '/' @@ -99,7 +126,9 @@ public class SystemBackup implements Runnable { 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 " @@ -109,11 +138,16 @@ public class SystemBackup implements Runnable { 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); } @@ -127,8 +161,8 @@ public class SystemBackup implements Runnable { this.backupsBase = backupsBase; } - public void setName(String name) { - this.name = name; + public void setSystemName(String name) { + this.systemName = name; } public void setAtomicBackups(List atomicBackups) { @@ -154,7 +188,7 @@ public class SystemBackup implements Runnable { fsm.init(); SystemBackup systemBackup = new SystemBackup(); - systemBackup.setName("mySystem"); + systemBackup.setSystemName("mySystem"); systemBackup .setBackupsBase("/home/mbaudier/dev/src/commons/server/runtime/org.argeo.server.core/target"); systemBackup.setFileSystemManager(fsm); @@ -163,6 +197,12 @@ public class SystemBackup implements Runnable { MySqlBackup mySqlBackup = new MySqlBackup("root", "", "test"); atomicBackups.add(mySqlBackup); + PostgreSqlBackup postgreSqlBackup = new PostgreSqlBackup( + "argeo", "argeo", "gis_template"); + atomicBackups.add(postgreSqlBackup); + SvnBackup svnBackup = new SvnBackup( + "/home/mbaudier/tmp/testsvnrepo"); + atomicBackups.add(svnBackup); systemBackup.setAtomicBackups(atomicBackups);