[longomatch] Fix backup of database



commit 922708cf8e00b1c63300766b91fffdd24321d9a0
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Sep 29 21:16:38 2011 +0200

    Fix backup of database

 LongoMatch/Services/DataBase.cs |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/LongoMatch/Services/DataBase.cs b/LongoMatch/Services/DataBase.cs
index a922b81..a26803a 100644
--- a/LongoMatch/Services/DataBase.cs
+++ b/LongoMatch/Services/DataBase.cs
@@ -69,7 +69,12 @@ namespace LongoMatch.DB
 		{
 			this.file = file;
 			Init();
-			BackupDB();
+			try {
+				BackupDB();
+			} catch (Exception e) {
+				Log.Error("Error creating databse backup");
+				Log.Exception(e);
+			}
 		}
 		
 		/// <value>
@@ -356,11 +361,16 @@ namespace LongoMatch.DB
 		}
 		
 		private void BackupDB () {
+			string backupFilepath;
 			DateTime now = DateTime.UtcNow;
 			if (lastBackup.Date + maxDaysWithoutBackup >= now)
 				return;
-		
-			File.Move(file, Path.Combine(MainClass.DBDir(), backupFilename));
+			
+			backupFilepath = Path.Combine(MainClass.DBDir(), backupFilename);
+			if (File.Exists(backupFilepath))
+				File.Delete(backupFilepath);
+
+			File.Move(file, backupFilepath);
 			Log.Information ("Created backup for database at ", backupFilename);
 			lastBackup = new BackupDate {Date = now};
 			UpdateBackupDate();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]