mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-25 01:06:30 +00:00
Cleaned up Backup.
This commit is contained in:
parent
928bc55839
commit
8ce6e8a08e
5 changed files with 69 additions and 41 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
|
|
53
NzbDrone.Core/Providers/BackupProvider.cs
Normal file
53
NzbDrone.Core/Providers/BackupProvider.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,20 +10,8 @@ namespace NzbDrone.Core.Providers.Core
|
|||
{
|
||||
public class ArchiveProvider
|
||||
{
|
||||
private readonly EnviromentProvider _enviromentProvider;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[Inject]
|
||||
public ArchiveProvider(EnviromentProvider enviromentProvider)
|
||||
{
|
||||
_enviromentProvider = enviromentProvider;
|
||||
}
|
||||
|
||||
public ArchiveProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void ExtractArchive(string compressedFile, string destination)
|
||||
{
|
||||
logger.Trace("Extracting archive [{0}] to [{1}]", compressedFile, destination);
|
||||
|
@ -35,29 +23,5 @@ namespace NzbDrone.Core.Providers.Core
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,17 +19,17 @@ namespace NzbDrone.Web.Controllers
|
|||
private readonly IndexerProvider _indexerProvider;
|
||||
private readonly ConfigProvider _configProvider;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly ArchiveProvider _archiveProvider;
|
||||
private readonly BackupProvider _backupProvider;
|
||||
|
||||
public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider,
|
||||
ConfigProvider configProvider, DiskProvider diskProvider,
|
||||
ArchiveProvider archiveProvider)
|
||||
BackupProvider backupProvider)
|
||||
{
|
||||
_jobProvider = jobProvider;
|
||||
_indexerProvider = indexerProvider;
|
||||
_configProvider = configProvider;
|
||||
_diskProvider = diskProvider;
|
||||
_archiveProvider = archiveProvider;
|
||||
_backupProvider = backupProvider;
|
||||
}
|
||||
|
||||
public ActionResult Jobs()
|
||||
|
@ -149,8 +149,10 @@ namespace NzbDrone.Web.Controllers
|
|||
|
||||
public ActionResult Backup()
|
||||
{
|
||||
var file = _archiveProvider.CreateBackupZip();
|
||||
return File(file.FullName, "application/binary", file.Name);
|
||||
var file = _backupProvider.CreateBackupZip();
|
||||
var fileInfo = new FileInfo(file);
|
||||
|
||||
return File(fileInfo.FullName, "application/binary", fileInfo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue