1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00

System/Backup will backup Config.xml and NzbDrone.sdf to a zip file for the client to download.

This commit is contained in:
Mark McDowall 2012-01-25 23:56:05 -08:00
parent ab7d3ebcc5
commit 93ee97123f
3 changed files with 51 additions and 8 deletions

View File

@ -12,11 +12,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
[Test] [Test]
public void Should_extract_to_correct_folder() public void Should_extract_to_correct_folder()
{ {
var archiveProvider = new ArchiveProvider();
var destination = Path.Combine(TempFolder, "destination"); var destination = Path.Combine(TempFolder, "destination");
archiveProvider.ExtractArchive(GetTestFilePath("TestArchive.zip"), destination); Mocker.Resolve<ArchiveProvider>().ExtractArchive(GetTestFilePath("TestArchive.zip"), destination);
var destinationFolder = new DirectoryInfo(destination); var destinationFolder = new DirectoryInfo(destination);

View File

@ -1,13 +1,28 @@
using System.Linq; using System;
using System.IO;
using System.Linq;
using Ionic.Zip; using Ionic.Zip;
using NLog; using NLog;
using Ninject;
using NzbDrone.Common;
namespace NzbDrone.Core.Providers.Core namespace NzbDrone.Core.Providers.Core
{ {
public class ArchiveProvider public class ArchiveProvider
{ {
private readonly EnviromentProvider _enviromentProvider;
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
[Inject]
public ArchiveProvider(EnviromentProvider enviromentProvider)
{
_enviromentProvider = enviromentProvider;
}
public ArchiveProvider()
{
}
public virtual void ExtractArchive(string compressedFile, string destination) public virtual void ExtractArchive(string compressedFile, string destination)
{ {
@ -21,5 +36,28 @@ namespace NzbDrone.Core.Providers.Core
logger.Trace("Extraction complete."); logger.Trace("Extraction complete.");
} }
public virtual FileInfo CreateBackupZip()
{
try
{
var dbFile = PathExtentions.GetNzbDronoeDbFile(_enviromentProvider);
var configFile = PathExtentions.GetConfigPath(_enviromentProvider);
var zipFile = Path.Combine(PathExtentions.GetAppDataPath(_enviromentProvider), "NzbDrone_Backup.zip");
using (var zip = new ZipFile())
{
zip.AddFile(dbFile, String.Empty);
zip.AddFile(configFile, String.Empty);
zip.Save(zipFile);
}
return new FileInfo(zipFile);
}
catch(Exception ex)
{
logger.WarnException("Failed to create backup zip", ex);
return null;
}
}
} }
} }

View File

@ -19,13 +19,17 @@ namespace NzbDrone.Web.Controllers
private readonly IndexerProvider _indexerProvider; private readonly IndexerProvider _indexerProvider;
private readonly ConfigProvider _configProvider; private readonly ConfigProvider _configProvider;
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
private readonly ArchiveProvider _archiveProvider;
public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider, ConfigProvider configProvider, DiskProvider diskProvider) public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider,
ConfigProvider configProvider, DiskProvider diskProvider,
ArchiveProvider archiveProvider)
{ {
_jobProvider = jobProvider; _jobProvider = jobProvider;
_indexerProvider = indexerProvider; _indexerProvider = indexerProvider;
_configProvider = configProvider; _configProvider = configProvider;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_archiveProvider = archiveProvider;
} }
public ActionResult Jobs() public ActionResult Jobs()
@ -48,13 +52,11 @@ namespace NzbDrone.Web.Controllers
return View(_indexerProvider.All()); return View(_indexerProvider.All());
} }
public ActionResult Config() public ActionResult Config()
{ {
return View(_configProvider.All()); return View(_configProvider.All());
} }
[GridAction] [GridAction]
public ActionResult _SelectAjaxEditing() public ActionResult _SelectAjaxEditing()
{ {
@ -144,5 +146,11 @@ namespace NzbDrone.Web.Controllers
return JsonNotificationResult.Info("Job Queued"); return JsonNotificationResult.Info("Job Queued");
} }
public ActionResult Backup()
{
var file = _archiveProvider.CreateBackupZip();
return File(file.FullName, "application/binary", file.Name);
}
} }
} }