Merge branch 'backup-on-update' into develop

pull/4/head
Mark McDowall 11 years ago
commit 7261a4bd71

@ -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();

@ -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);

@ -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);

@ -60,6 +60,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UpdateContainerBuilder.cs" />
<Compile Include="UpdateEngine\BackupAndRestore.cs" />
<Compile Include="UpdateEngine\BackupAppData.cs" />
<Compile Include="UpdateEngine\DetectApplicationType.cs" />
<Compile Include="UpdateEngine\InstallUpdateService.cs" />
<Compile Include="UpdateEngine\StartNzbDrone.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);

@ -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());

@ -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);
}
}
}

@ -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");

Loading…
Cancel
Save