Only create a database backup if there isn't one already. This prevents overwriting a perfectly fine backup with a more or less broken one in case a database update fails.

This commit is contained in:
Fabian Schlenz 2016-07-27 06:11:50 +02:00
parent eb9715cb09
commit 3e64b336a8
1 changed files with 4 additions and 2 deletions

View File

@ -41,6 +41,7 @@ import java.util.HashMap;
import java.util.Date;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.nio.file.FileAlreadyExistsException;
import java.text.SimpleDateFormat;
import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager;
@ -97,8 +98,9 @@ public class Database {
logger.debug("Copying {} to {}", src, dst);
Files.copy(
new File(src).toPath(),
new File(dst).toPath(),
StandardCopyOption.REPLACE_EXISTING);
new File(dst).toPath());
} catch (FileAlreadyExistsException e) {
logger.warn("Backup already exists:", e);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Could not create backup.");