use of com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction in project Plan by plan-player-analytics.
the class DatabaseCommands method performBackup.
public void performBackup(CMDSender sender, Arguments arguments, String dbName, Database fromDB) {
Database toDB = null;
try {
String timeStamp = timestamp.apply(System.currentTimeMillis());
String fileName = dbName + "-backup-" + timeStamp;
sender.send(locale.getString(CommandLang.DB_BACKUP_CREATE, fileName, dbName));
toDB = sqliteFactory.usingFileCalled(fileName);
toDB.init();
toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
} catch (DBOpException | ExecutionException e) {
errorLogger.error(e, ErrorContext.builder().related(sender, arguments).build());
} catch (InterruptedException e) {
toDB.close();
Thread.currentThread().interrupt();
} finally {
if (toDB != null) {
toDB.close();
}
}
}
use of com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction in project Plan by plan-player-analytics.
the class DatabaseBackupTest method testBackupAndRestoreSQLite.
@Test
default void testBackupAndRestoreSQLite() throws Exception {
File tempFile = Files.createTempFile(system().getPlanFiles().getDataFolder().toPath(), "backup-", ".db").toFile();
tempFile.deleteOnExit();
SQLiteDB backup = dbSystem().getSqLiteFactory().usingFile(tempFile);
backup.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
try {
backup.init();
saveDataForBackup();
backup.executeTransaction(new BackupCopyTransaction(db(), backup));
assertQueryResultIsEqual(db(), backup, BaseUserQueries.fetchAllBaseUsers());
assertQueryResultIsEqual(db(), backup, UserInfoQueries.fetchAllUserInformation());
assertQueryResultIsEqual(db(), backup, NicknameQueries.fetchAllNicknameData());
assertQueryResultIsEqual(db(), backup, GeoInfoQueries.fetchAllGeoInformation());
assertQueryResultIsEqual(db(), backup, SessionQueries.fetchAllSessions());
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllWorldNames());
assertQueryResultIsEqual(db(), backup, LargeFetchQueries.fetchAllTPSData());
assertQueryResultIsEqual(db(), backup, ServerQueries.fetchPlanServerInformation());
assertQueryResultIsEqual(db(), backup, WebUserQueries.fetchAllUsers());
} finally {
backup.close();
}
}
use of com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction in project Plan by plan-player-analytics.
the class DatabaseCommands method performMove.
private void performMove(CMDSender sender, DBType fromDB, DBType toDB) {
try {
Database fromDatabase = dbSystem.getActiveDatabaseByType(fromDB);
Database toDatabase = dbSystem.getActiveDatabaseByType(toDB);
fromDatabase.init();
toDatabase.init();
sender.send(locale.getString(CommandLang.DB_WRITE, toDB.getName()));
toDatabase.executeTransaction(new BackupCopyTransaction(fromDatabase, toDatabase)).get();
sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
boolean movingToCurrentDB = toDatabase.getType() == dbSystem.getDatabase().getType();
if (movingToCurrentDB) {
sender.send(locale.getString(CommandLang.HOTSWAP_REMINDER, toDatabase.getType().getConfigName()));
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
errorLogger.error(e, ErrorContext.builder().related(sender, fromDB.getName() + "->" + toDB.getName()).build());
sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
}
}
use of com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction in project Plan by plan-player-analytics.
the class DatabaseCommands method performRestore.
public void performRestore(CMDSender sender, File backupDBFile, Database toDB) {
try {
SQLiteDB fromDB = sqliteFactory.usingFile(backupDBFile);
fromDB.init();
sender.send(locale.getString(CommandLang.DB_WRITE, toDB.getType().getName()));
toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (DBOpException | ExecutionException e) {
errorLogger.error(e, ErrorContext.builder().related(backupDBFile, toDB.getType(), toDB.getState()).build());
sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
}
}
Aggregations