Merge pull request #7 from NzbDrone/config-backup

Config backup
This commit is contained in:
Keivan Beigi 2012-01-26 21:24:27 -08:00
commit 6cabbcb8b7
7 changed files with 86 additions and 10 deletions

View File

@ -17,6 +17,8 @@ namespace NzbDrone.Common
public const string NZBDRONE_DB_FILE = "nzbdrone.sdf";
public const string LOG_DB_FILE = "log.sdf";
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private const string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update\\";
private const string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone\\";
private const string UPDATE_BACKUP_FOLDER_NAME = "nzbdrone_backup\\";
@ -144,9 +146,15 @@ namespace NzbDrone.Common
{
return Path.Combine(enviromentProvider.ApplicationPath, "nzbdrone.log.txt");
}
public static string GetArchivedLogFileName(this EnviromentProvider enviromentProvider)
{
return Path.Combine(enviromentProvider.ApplicationPath, "nzbdrone.log.0.txt");
}
public static string GetConfigBackupFile(this EnviromentProvider enviromentProvider)
{
return Path.Combine(enviromentProvider.GetAppDataPath(), BACKUP_ZIP_FILE);
}
}
}

View File

@ -12,11 +12,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
[Test]
public void Should_extract_to_correct_folder()
{
var archiveProvider = new ArchiveProvider();
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);

View File

@ -256,6 +256,7 @@
<Compile Include="Model\Xbmc\TvShowResult.cs" />
<Compile Include="Model\Xbmc\ErrorResult.cs" />
<Compile Include="Model\Xbmc\IconType.cs" />
<Compile Include="Providers\BackupProvider.cs" />
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
<Compile Include="Providers\Converting\HandbrakeProvider.cs" />
<Compile Include="Providers\Indexer\Newznab.cs" />

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Ionic.Zip;
using NLog;
using Ninject;
using NzbDrone.Common;
namespace NzbDrone.Core.Providers
{
public class BackupProvider
{
private readonly EnviromentProvider _enviromentProvider;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
[Inject]
public BackupProvider(EnviromentProvider enviromentProvider)
{
_enviromentProvider = enviromentProvider;
}
public BackupProvider()
{
}
public virtual string CreateBackupZip()
{
try
{
var dbFile = _enviromentProvider.GetNzbDronoeDbFile();
var configFile = _enviromentProvider.GetConfigPath();
var zipFile = _enviromentProvider.GetConfigBackupFile();
using (var zip = new ZipFile())
{
zip.AddFile(dbFile, String.Empty);
zip.AddFile(configFile, String.Empty);
zip.Save(zipFile);
}
return zipFile;
}
catch (Exception ex)
{
logger.ErrorException("Failed to create backup zip", ex);
throw;
}
}
}
}

View File

@ -1,13 +1,16 @@
using System.Linq;
using System;
using System.IO;
using System.Linq;
using Ionic.Zip;
using NLog;
using Ninject;
using NzbDrone.Common;
namespace NzbDrone.Core.Providers.Core
{
public class ArchiveProvider
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public virtual void ExtractArchive(string compressedFile, string destination)
{
@ -20,6 +23,5 @@ namespace NzbDrone.Core.Providers.Core
logger.Trace("Extraction complete.");
}
}
}

View File

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

View File

@ -28,6 +28,11 @@
<span class="small">@Html.DescriptionFor(m => m.AuthenticationType)</span>
</label>
@Html.DropDownListFor(m => m.AuthenticationType, Model.AuthTypeSelectList, new { @class = "inputClass" })
<label class="labelClass"> Backup Configuration
<span class="small">Backup your Configuration file and Database</span>
</label>
<input type="button" value="Backup Now" onclick="window.location='../System/Backup'; return false;" class="inputClass" />
<button type="submit" class="save_button" disabled="disabled">
Save</button>