3
3
import java .io .File ;
4
4
import java .io .IOException ;
5
5
import java .time .Instant ;
6
+ import java .time .format .DateTimeFormatter ;
6
7
import java .util .List ;
7
8
import java .util .Optional ;
8
9
34
35
public class BackupController {
35
36
private final BackupService backupService ;
36
37
private final DatabaseService databaseService ;
38
+ private final DateTimeFormatter dateTimeFormatter ;
37
39
38
40
@ PreAuthorize ("hasAuthority('APPROLE_DatabaseBackupCreator') and hasAuthority('SCOPE_createBackup')" )
39
41
@ PostMapping ("/backup" )
40
42
@ ResponseBody
41
43
void create (
42
44
@ RequestParam ("retention_period" ) @ Min (1 ) @ Max (356 ) int retentionPeriod )
43
45
throws IOException , InterruptedException {
46
+
47
+ String timeString = dateTimeFormatter .format (Instant .now ());
44
48
databaseService .getDatabases ().forEach (databaseConfiguration -> {
45
49
try {
46
50
createDump (retentionPeriod , databaseConfiguration .getName (),
47
51
databaseConfiguration .getPrefix (),
48
- databaseConfiguration .getDumpFormat ().getValue ());
52
+ databaseConfiguration .getDumpFormat ().getValue (),
53
+ timeString );
49
54
50
55
if (databaseConfiguration .isCreatePlainDump ()) {
51
56
createDump (retentionPeriod , databaseConfiguration .getName (),
52
- databaseConfiguration .getPrefix (), "plain" );
57
+ databaseConfiguration .getPrefix (), "plain" ,
58
+ timeString );
53
59
}
54
60
} catch (IOException | InterruptedException e ) {
55
61
throw new RuntimeException (e );
@@ -58,9 +64,10 @@ void create(
58
64
}
59
65
60
66
private void createDump (int retentionPeriod , String name , String prefix ,
61
- String dumpFormat ) throws IOException , InterruptedException {
67
+ String dumpFormat , String timeString )
68
+ throws IOException , InterruptedException {
62
69
File dumpFile = databaseService .createDump (name , retentionPeriod ,
63
- dumpFormat );
70
+ dumpFormat , timeString );
64
71
backupService .createBackup (prefix , dumpFile );
65
72
66
73
dumpFile .delete ();
0 commit comments