1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-22 16:56:16 +00:00

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

View File

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