package org.simantics.acorn.backup;
-import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import org.simantics.backup.IBackupProvider;
import org.simantics.db.server.ProCoreException;
import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Jani
*/
public class AcornBackupProvider implements IBackupProvider {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AcornBackupProvider.class);
+
private static final String IDENTIFIER = "AcornBackupProvider";
private long trId = -1;
private final Semaphore lock = new Semaphore(1);
throw new IllegalStateException(this + " backup provider is already locked");
trId = client.askWriteTransaction(-1).getTransactionId();
} catch (ProCoreException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to lock backup provider", e);
}
}
Files.move(restorePath, dbRoot);
}
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("Failed to restore database revision {} from backup {}", revision, fromPath.toString(), e);
}
}
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".tar.gz"))
return FileVisitResult.CONTINUE;
- System.out.println("Restore " + file + " to " + toPath.resolve(currentSubFolder.relativize(file)));
+ if (LOGGER.isTraceEnabled())
+ LOGGER.trace("Restore " + file + " to " + toPath.resolve(currentSubFolder.relativize(file)));
Files.copy(file, toPath.resolve(currentSubFolder.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
private void doBackup() throws IOException {
Path target = targetPath.resolve(String.valueOf(revision)).resolve(IDENTIFIER);
- if (!Files.exists(target))
- Files.createDirectories(target);
+ Files.createDirectories(target);
Files.walkFileTree(baseDir,
new BackupCopyVisitor(baseDir, target));
}
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
- System.out.println("Backup " + file + " to "
- + toPath.resolve(fromPath.relativize(file)));
+ if (LOGGER.isTraceEnabled())
+ LOGGER.trace("Backup " + file + " to " + toPath.resolve(fromPath.relativize(file)));
Files.copy(file, toPath.resolve(fromPath.relativize(file)),
StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
if (dropinsFolder == null) {
IPath state = Platform.getStateLocation(context.getBundle());
dropinsFolder = Paths.get(state.append("dropins").toOSString());
- if (!Files.exists(dropinsFolder))
- Files.createDirectories(dropinsFolder);
+ Files.createDirectories(dropinsFolder);
}
return dropinsFolder;
}
if (modelsFolder == null) {
IPath state = Platform.getStateLocation(context.getBundle());
modelsFolder = Paths.get(state.append("models").toOSString());
- if (!Files.exists(modelsFolder))
- Files.createDirectories(modelsFolder);
+ Files.createDirectories(modelsFolder);
}
return modelsFolder;
}