4040import java .nio .file .FileSystems ;
4141import java .nio .file .Path ;
4242import java .nio .file .Paths ;
43+ import java .time .Duration ;
4344import java .time .LocalDateTime ;
4445import java .time .ZonedDateTime ;
4546import java .time .format .DateTimeFormatter ;
@@ -66,6 +67,7 @@ public class UploadThread implements Runnable {
6667 private CommandSender initiator ;
6768 private final UploadLogger logger ;
6869 private final FileUtil fileUtil ;
70+ private Timer totalTimer ;
6971
7072 /**
7173 * The current status of the backup thread
@@ -80,7 +82,9 @@ enum BackupStatus {
8082 * The backup thread is compressing the files to be backed up.
8183 */
8284 COMPRESSING ,
83-
85+
86+ STARTING ,
87+ PRUNING ,
8488 /**
8589 * The backup thread is uploading the files
8690 */
@@ -147,6 +151,7 @@ public void log(String input, String... placeholders) {
147151 }
148152 };
149153 fileUtil = new FileUtil (logger );
154+ totalTimer = new Timer ();
150155 }
151156
152157 /**
@@ -181,16 +186,18 @@ public void initiatorError(String input, String... placeholders) {
181186 */
182187 @ Override
183188 public void run () {
184- if (!locationsToBePruned .isEmpty ()) {
185- locationsToBePruned .clear ();
186- }
187189 Config config = ConfigParser .getConfig ();
188190 if (initiator != null && backupStatus != BackupStatus .NOT_RUNNING ) {
189191 logger .initiatorError (
190192 intl ("backup-already-running" ),
191193 "backup-status" , getBackupStatus ());
192194 return ;
193195 }
196+ totalTimer .start ();
197+ backupStatus = BackupStatus .STARTING ;
198+ if (!locationsToBePruned .isEmpty ()) {
199+ locationsToBePruned .clear ();
200+ }
194201 if (initiator == null ) {
195202 updateNextIntervalBackupTime ();
196203 }
@@ -203,7 +210,7 @@ public void run() {
203210 }
204211 boolean errorOccurred = false ;
205212 List <ExternalBackupSource > externalBackupList = Arrays .asList (config .externalBackups .sources );
206- backupList = new ArrayList <BackupListEntry >(Arrays .asList (config .backupList .list ));
213+ backupList = new ArrayList <>(Arrays .asList (config .backupList .list ));
207214 if (externalBackupList .isEmpty () && backupList .isEmpty ()) {
208215 logger .log (intl ("backup-empty-list" ));
209216 return ;
@@ -262,7 +269,6 @@ public void run() {
262269 uploadBackupFiles (uploaders );
263270 FileUtil .deleteFolder (new File ("external-backups" ));
264271 logger .log (intl ("backup-upload-complete" ));
265- backupStatus = BackupStatus .NOT_RUNNING ;
266272 logger .log (intl ("upload-error-check" ));
267273 for (Uploader uploader : uploaders ) {
268274 uploader .close ();
@@ -288,7 +294,13 @@ public void run() {
288294 PlayerListener .setAutoBackupsActive (false );
289295 }
290296 lastBackupSuccessful = !errorOccurred ;
297+ backupStatus = BackupStatus .PRUNING ;
291298 pruneLocalBackups ();
299+ totalTimer .end ();
300+ long totalBackupTime = totalTimer .getTime ();
301+ long totalSeconds = Duration .of (totalBackupTime , ChronoUnit .MILLIS ).getSeconds ();
302+ logger .log (intl ("backup-total-time" ), "<time>" , String .valueOf (totalSeconds ));
303+ backupStatus = BackupStatus .NOT_RUNNING ;
292304 if (errorOccurred ) {
293305 DriveBackupApi .backupError ();
294306 } else {
@@ -545,6 +557,12 @@ public static String getBackupStatus() {
545557 case UPLOADING :
546558 message = intl ("backup-status-uploading" );
547559 break ;
560+ case STARTING :
561+ message = intl ("backup-status-starting" );
562+ break ;
563+ case PRUNING :
564+ message = intl ("backup-status-pruning" );
565+ break ;
548566 default :
549567 return intl ("backup-status-not-running" );
550568 }
0 commit comments