diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs
index b9c506a2e..b1af0ccaa 100644
--- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs
+++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs
@@ -204,6 +204,20 @@ namespace NzbDrone.Common.Disk
File.Delete(path);
}
+ public void CopyFile(string source, string destination, bool overwrite = false)
+ {
+ Ensure.That(source, () => source).IsValidPath();
+ Ensure.That(destination, () => destination).IsValidPath();
+
+ if (source.PathEquals(destination))
+ {
+ Logger.Warn("Source and destination can't be the same {0}", source);
+ return;
+ }
+
+ File.Copy(source, destination, overwrite);
+ }
+
public void MoveFile(string source, string destination)
{
Ensure.That(source, () => source).IsValidPath();
diff --git a/src/NzbDrone.Common/Disk/IDiskProvider.cs b/src/NzbDrone.Common/Disk/IDiskProvider.cs
index 3e8b8ceff..0bb415452 100644
--- a/src/NzbDrone.Common/Disk/IDiskProvider.cs
+++ b/src/NzbDrone.Common/Disk/IDiskProvider.cs
@@ -26,6 +26,7 @@ namespace NzbDrone.Common.Disk
void CopyFolder(string source, string destination);
void MoveFolder(string source, string destination);
void DeleteFile(string path);
+ void CopyFile(string source, string destination, bool overwrite = false);
void MoveFile(string source, string destination);
void DeleteFolder(string path, bool recursive);
string ReadAllText(string filePath);
diff --git a/src/NzbDrone.Common/PathExtensions.cs b/src/NzbDrone.Common/PathExtensions.cs
index 5bf143796..309fee9cb 100644
--- a/src/NzbDrone.Common/PathExtensions.cs
+++ b/src/NzbDrone.Common/PathExtensions.cs
@@ -18,6 +18,7 @@ namespace NzbDrone.Common
private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_BACKUP_FOLDER_NAME = "nzbdrone_backup" + Path.DirectorySeparatorChar;
+ private static readonly string UPDATE_BACKUP_APPDATA_FOLDER_NAME = "nzbdrone_appdata_backup" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_CLIENT_FOLDER_NAME = "NzbDrone.Update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar;
@@ -155,6 +156,21 @@ namespace NzbDrone.Common
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_BACKUP_FOLDER_NAME);
}
+ public static string GetUpdateBackUpAppDataFolder(this IAppFolderInfo appFolderInfo)
+ {
+ return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_BACKUP_APPDATA_FOLDER_NAME);
+ }
+
+ public static string GetUpdateBackupConfigFile(this IAppFolderInfo appFolderInfo)
+ {
+ return Path.Combine(GetUpdateBackUpAppDataFolder(appFolderInfo), APP_CONFIG_FILE);
+ }
+
+ public static string GetUpdateBackupDatabase(this IAppFolderInfo appFolderInfo)
+ {
+ return Path.Combine(GetUpdateBackUpAppDataFolder(appFolderInfo), NZBDRONE_DB);
+ }
+
public static string GetUpdatePackageFolder(this IAppFolderInfo appFolderInfo)
{
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_PACKAGE_FOLDER_NAME);
diff --git a/src/NzbDrone.Update/NzbDrone.Update.csproj b/src/NzbDrone.Update/NzbDrone.Update.csproj
index d09ab8021..908102ff9 100644
--- a/src/NzbDrone.Update/NzbDrone.Update.csproj
+++ b/src/NzbDrone.Update/NzbDrone.Update.csproj
@@ -60,6 +60,7 @@
+
diff --git a/src/NzbDrone.Update/UpdateApp.cs b/src/NzbDrone.Update/UpdateApp.cs
index 83531b153..35d7febca 100644
--- a/src/NzbDrone.Update/UpdateApp.cs
+++ b/src/NzbDrone.Update/UpdateApp.cs
@@ -50,10 +50,10 @@ namespace NzbDrone.Update
public void Start(string[] args)
{
- int processId = ParseProcessId(args);
+ var processId = ParseProcessId(args);
var exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath);
- string targetFolder = exeFileInfo.Directory.FullName;
+ var targetFolder = exeFileInfo.Directory.FullName;
logger.Info("Starting update process. Target Path:{0}", targetFolder);
_installUpdateService.Start(targetFolder);
diff --git a/src/NzbDrone.Update/UpdateEngine/BackupAndRestore.cs b/src/NzbDrone.Update/UpdateEngine/BackupAndRestore.cs
index 3787b25d3..a934e6fc6 100644
--- a/src/NzbDrone.Update/UpdateEngine/BackupAndRestore.cs
+++ b/src/NzbDrone.Update/UpdateEngine/BackupAndRestore.cs
@@ -7,7 +7,7 @@ namespace NzbDrone.Update.UpdateEngine
{
public interface IBackupAndRestore
{
- void BackUp(string source);
+ void Backup(string source);
void Restore(string target);
}
@@ -24,7 +24,7 @@ namespace NzbDrone.Update.UpdateEngine
_logger = logger;
}
- public void BackUp(string source)
+ public void Backup(string source)
{
_logger.Info("Creating backup of existing installation");
_diskProvider.CopyFolder(source, _appFolderInfo.GetUpdateBackUpFolder());
diff --git a/src/NzbDrone.Update/UpdateEngine/BackupAppData.cs b/src/NzbDrone.Update/UpdateEngine/BackupAppData.cs
new file mode 100644
index 000000000..038732367
--- /dev/null
+++ b/src/NzbDrone.Update/UpdateEngine/BackupAppData.cs
@@ -0,0 +1,37 @@
+using System.IO;
+using NLog;
+using NzbDrone.Common;
+using NzbDrone.Common.Disk;
+using NzbDrone.Common.EnvironmentInfo;
+
+namespace NzbDrone.Update.UpdateEngine
+{
+ public interface IBackupAppData
+ {
+ void Backup();
+ }
+
+ public class BackupAppData : IBackupAppData
+ {
+ private readonly IAppFolderInfo _appFolderInfo;
+ private readonly IDiskProvider _diskProvider;
+ private readonly Logger _logger;
+
+ public BackupAppData(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, Logger logger)
+ {
+ _appFolderInfo = appFolderInfo;
+ _diskProvider = diskProvider;
+ _logger = logger;
+ }
+
+ public void Backup()
+ {
+ _logger.Info("Backing up appdata (database/config)");
+ var backupFolderAppData = _appFolderInfo.GetUpdateBackUpAppDataFolder();
+
+ _diskProvider.CreateFolder(backupFolderAppData);
+ _diskProvider.CopyFile(_appFolderInfo.GetConfigPath(), _appFolderInfo.GetUpdateBackupConfigFile(), true);
+ _diskProvider.CopyFile(_appFolderInfo.GetNzbDroneDatabase(), _appFolderInfo.GetUpdateBackupDatabase(), true);
+ }
+ }
+}
diff --git a/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs b/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs
index 0e6001677..f1b731e34 100644
--- a/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs
+++ b/src/NzbDrone.Update/UpdateEngine/InstallUpdateService.cs
@@ -19,17 +19,25 @@ namespace NzbDrone.Update.UpdateEngine
private readonly ITerminateNzbDrone _terminateNzbDrone;
private readonly IAppFolderInfo _appFolderInfo;
private readonly IBackupAndRestore _backupAndRestore;
+ private readonly IBackupAppData _backupAppData;
private readonly IStartNzbDrone _startNzbDrone;
private readonly Logger _logger;
- public InstallUpdateService(IDiskProvider diskProvider, IDetectApplicationType detectApplicationType, ITerminateNzbDrone terminateNzbDrone,
- IAppFolderInfo appFolderInfo, IBackupAndRestore backupAndRestore, IStartNzbDrone startNzbDrone, Logger logger)
+ public InstallUpdateService(IDiskProvider diskProvider,
+ IDetectApplicationType detectApplicationType,
+ ITerminateNzbDrone terminateNzbDrone,
+ IAppFolderInfo appFolderInfo,
+ IBackupAndRestore backupAndRestore,
+ IBackupAppData backupAppData,
+ IStartNzbDrone startNzbDrone,
+ Logger logger)
{
_diskProvider = diskProvider;
_detectApplicationType = detectApplicationType;
_terminateNzbDrone = terminateNzbDrone;
_appFolderInfo = appFolderInfo;
_backupAndRestore = backupAndRestore;
+ _backupAppData = backupAppData;
_startNzbDrone = startNzbDrone;
_logger = logger;
}
@@ -59,7 +67,8 @@ namespace NzbDrone.Update.UpdateEngine
{
_terminateNzbDrone.Terminate();
- _backupAndRestore.BackUp(installationFolder);
+ _backupAndRestore.Backup(installationFolder);
+ _backupAppData.Backup();
_logger.Info("Moving update package to target");