рефакторинг бекапов. бекапы для тестирования. бекапы по кнопке
++
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package _VisualDVM.ComponentsServer;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Objects.riDBObject;
|
||||
import Common.Database.RepositoryRefuseException;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
@@ -39,68 +40,6 @@ import java.util.Date;
|
||||
import java.util.Vector;
|
||||
public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
public CredentialsDatabase credentials_db = null;
|
||||
//--
|
||||
public static ZipFolderPass zip = new ZipFolderPass();
|
||||
public static UnzipFolderPass unzip = new UnzipFolderPass();
|
||||
public static ArchivesBackupPass backupSession = new ArchivesBackupPass();
|
||||
//-
|
||||
public static Vector<Pair<Machine, User>> storages = new Vector<>(
|
||||
Arrays.asList(new Pair<>(new Machine("titan",
|
||||
"dvmh.keldysh.ru",
|
||||
22, MachineType.Server),
|
||||
new User("dvmuser1", "mprit_2011")) // todo с этим паролем что-то сделать.
|
||||
));
|
||||
//-
|
||||
protected Thread backUp = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
//-------------------------------------
|
||||
Calendar rightNow = Calendar.getInstance();
|
||||
int year = rightNow.get(Calendar.YEAR);
|
||||
int month = rightNow.get(Calendar.MONTH);
|
||||
int day = rightNow.get(Calendar.DAY_OF_MONTH);
|
||||
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = rightNow.get(Calendar.MINUTE);
|
||||
if ((hour == Global.componentsServerProperties.BackupHour) && (minute == Global.componentsServerProperties.BackupMinute)) {
|
||||
//определить имя папки с багом.
|
||||
String backUpName = year + "_" + (month + 1) + "_" + (day);
|
||||
File todayBackUp = Paths.get(Global.DataBackUpsDirectory.getAbsolutePath(), backUpName).toFile();
|
||||
File todayBackUpArchive = Paths.get(Global.DataBackUpsDirectory.getAbsolutePath(), backUpName + ".zip").toFile();
|
||||
//-
|
||||
File bugsDBBackUp = Paths.get(todayBackUp.getAbsolutePath(), db.getFile().getName()).toFile();
|
||||
File bugsArchives = Paths.get(todayBackUp.getAbsolutePath(), "Bugs.zip").toFile();
|
||||
//-
|
||||
// Чистка старых бекапов на самом сервере.
|
||||
Utils.keepNewFiles(todayBackUp.getParentFile(), 2);
|
||||
if (!todayBackUpArchive.exists()) {
|
||||
FileUtils.forceMkdir(todayBackUp);
|
||||
Files.copy(db.getFile().toPath(), bugsDBBackUp.toPath());
|
||||
//-
|
||||
zip.Do("Bugs", bugsArchives.getAbsolutePath());
|
||||
zip.Do(todayBackUp.getAbsolutePath(), todayBackUpArchive.getAbsolutePath());
|
||||
Utils_.forceDeleteWithCheck(todayBackUp);
|
||||
//-
|
||||
for (Pair<Machine, User> cred : storages) {
|
||||
backupSession.Do(cred.getKey(), cred.getValue(), todayBackUpArchive);
|
||||
}
|
||||
//bonus backup
|
||||
//todo оформить как у планировщика, так как это нить, напрямую сервер трогать нельзя.
|
||||
if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
|
||||
EmailMessage message = new EmailMessage("db backup", "копия баз данных журнала ошибок");
|
||||
message.addAttachement(db.getFile());
|
||||
for (String address : Constants.admins_mails) {
|
||||
Email(message, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------------
|
||||
Thread.sleep(60000);
|
||||
} catch (Exception ex) {
|
||||
Utils_.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
public ComponentsServer() {
|
||||
super(BugReportsDatabase.class);
|
||||
}
|
||||
@@ -113,6 +52,10 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
return Constants.ComponentsServerPort;
|
||||
}
|
||||
@Override
|
||||
protected void extraBackup(File todayBackUp) {
|
||||
zip.Do("Bugs",new File (todayBackUp, "Bugs.zip").getAbsolutePath());
|
||||
}
|
||||
@Override
|
||||
protected void beforePublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof BugReport) {
|
||||
BugReport bugReport = (BugReport) object;
|
||||
@@ -151,10 +94,6 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void startAdditionalThreads() {
|
||||
backUp.start();
|
||||
}
|
||||
//-
|
||||
void DVMConvertProject() throws Exception {
|
||||
String[] args = request.arg.split("\n");
|
||||
|
||||
Reference in New Issue
Block a user