1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2025-02-27 00:23:19 +00:00

Merge branch 'backup-on-update' into develop

This commit is contained in:
Mark McDowall 2014-02-07 22:55:12 -08:00
commit 7261a4bd71
8 changed files with 85 additions and 7 deletions

View file

@ -204,6 +204,20 @@ public void DeleteFile(string path)
File.Delete(path); 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) public void MoveFile(string source, string destination)
{ {
Ensure.That(source, () => source).IsValidPath(); Ensure.That(source, () => source).IsValidPath();

View file

@ -26,6 +26,7 @@ public interface IDiskProvider
void CopyFolder(string source, string destination); void CopyFolder(string source, string destination);
void MoveFolder(string source, string destination); void MoveFolder(string source, string destination);
void DeleteFile(string path); void DeleteFile(string path);
void CopyFile(string source, string destination, bool overwrite = false);
void MoveFile(string source, string destination); void MoveFile(string source, string destination);
void DeleteFolder(string path, bool recursive); void DeleteFolder(string path, bool recursive);
string ReadAllText(string filePath); string ReadAllText(string filePath);

View file

@ -18,6 +18,7 @@ public static class PathExtensions
private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar; 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_PACKAGE_FOLDER_NAME = "nzbdrone" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_BACKUP_FOLDER_NAME = "nzbdrone_backup" + 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_CLIENT_FOLDER_NAME = "NzbDrone.Update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar; private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar;
@ -155,6 +156,21 @@ public static string GetUpdateBackUpFolder(this IAppFolderInfo appFolderInfo)
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_BACKUP_FOLDER_NAME); 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) public static string GetUpdatePackageFolder(this IAppFolderInfo appFolderInfo)
{ {
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_PACKAGE_FOLDER_NAME); return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_PACKAGE_FOLDER_NAME);

View file

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

View file

@ -50,10 +50,10 @@ public static void Main(string[] args)
public void Start(string[] args) public void Start(string[] args)
{ {
int processId = ParseProcessId(args); var processId = ParseProcessId(args);
var exeFileInfo = new FileInfo(_processProvider.GetProcessById(processId).StartPath); 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); logger.Info("Starting update process. Target Path:{0}", targetFolder);
_installUpdateService.Start(targetFolder); _installUpdateService.Start(targetFolder);

View file

@ -7,7 +7,7 @@ namespace NzbDrone.Update.UpdateEngine
{ {
public interface IBackupAndRestore public interface IBackupAndRestore
{ {
void BackUp(string source); void Backup(string source);
void Restore(string target); void Restore(string target);
} }
@ -24,7 +24,7 @@ public BackupAndRestore(IDiskProvider diskProvider, IAppFolderInfo appFolderInfo
_logger = logger; _logger = logger;
} }
public void BackUp(string source) public void Backup(string source)
{ {
_logger.Info("Creating backup of existing installation"); _logger.Info("Creating backup of existing installation");
_diskProvider.CopyFolder(source, _appFolderInfo.GetUpdateBackUpFolder()); _diskProvider.CopyFolder(source, _appFolderInfo.GetUpdateBackUpFolder());

View file

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

View file

@ -19,17 +19,25 @@ public class InstallUpdateService : IInstallUpdateService
private readonly ITerminateNzbDrone _terminateNzbDrone; private readonly ITerminateNzbDrone _terminateNzbDrone;
private readonly IAppFolderInfo _appFolderInfo; private readonly IAppFolderInfo _appFolderInfo;
private readonly IBackupAndRestore _backupAndRestore; private readonly IBackupAndRestore _backupAndRestore;
private readonly IBackupAppData _backupAppData;
private readonly IStartNzbDrone _startNzbDrone; private readonly IStartNzbDrone _startNzbDrone;
private readonly Logger _logger; private readonly Logger _logger;
public InstallUpdateService(IDiskProvider diskProvider, IDetectApplicationType detectApplicationType, ITerminateNzbDrone terminateNzbDrone, public InstallUpdateService(IDiskProvider diskProvider,
IAppFolderInfo appFolderInfo, IBackupAndRestore backupAndRestore, IStartNzbDrone startNzbDrone, Logger logger) IDetectApplicationType detectApplicationType,
ITerminateNzbDrone terminateNzbDrone,
IAppFolderInfo appFolderInfo,
IBackupAndRestore backupAndRestore,
IBackupAppData backupAppData,
IStartNzbDrone startNzbDrone,
Logger logger)
{ {
_diskProvider = diskProvider; _diskProvider = diskProvider;
_detectApplicationType = detectApplicationType; _detectApplicationType = detectApplicationType;
_terminateNzbDrone = terminateNzbDrone; _terminateNzbDrone = terminateNzbDrone;
_appFolderInfo = appFolderInfo; _appFolderInfo = appFolderInfo;
_backupAndRestore = backupAndRestore; _backupAndRestore = backupAndRestore;
_backupAppData = backupAppData;
_startNzbDrone = startNzbDrone; _startNzbDrone = startNzbDrone;
_logger = logger; _logger = logger;
} }
@ -59,7 +67,8 @@ public void Start(string installationFolder)
{ {
_terminateNzbDrone.Terminate(); _terminateNzbDrone.Terminate();
_backupAndRestore.BackUp(installationFolder); _backupAndRestore.Backup(installationFolder);
_backupAppData.Backup();
_logger.Info("Moving update package to target"); _logger.Info("Moving update package to target");