parent
fdbe45c0ab
commit
81d6c0d210
@ -0,0 +1,16 @@
|
||||
using System.Net;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
|
||||
namespace NzbDrone.Core.Backup
|
||||
{
|
||||
public class RestoreBackupFailedException : NzbDroneClientException
|
||||
{
|
||||
public RestoreBackupFailedException(HttpStatusCode statusCode, string message, params object[] args) : base(statusCode, message, args)
|
||||
{
|
||||
}
|
||||
|
||||
public RestoreBackupFailedException(HttpStatusCode statusCode, string message) : base(statusCode, message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public interface IRestoreDatabase
|
||||
{
|
||||
void Restore();
|
||||
}
|
||||
|
||||
public class DatabaseRestorationService : IRestoreDatabase
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IAppFolderInfo _appFolderInfo;
|
||||
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(DatabaseRestorationService));
|
||||
|
||||
public DatabaseRestorationService(IDiskProvider diskProvider, IAppFolderInfo appFolderInfo)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_appFolderInfo = appFolderInfo;
|
||||
}
|
||||
|
||||
public void Restore()
|
||||
{
|
||||
var dbRestorePath = _appFolderInfo.GetDatabaseRestore();
|
||||
|
||||
if (!_diskProvider.FileExists(dbRestorePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Logger.Info("Restoring Database");
|
||||
|
||||
var dbPath = _appFolderInfo.GetDatabase();
|
||||
|
||||
_diskProvider.DeleteFile(dbPath + "-shm");
|
||||
_diskProvider.DeleteFile(dbPath + "-wal");
|
||||
_diskProvider.DeleteFile(dbPath + "-journal");
|
||||
_diskProvider.DeleteFile(dbPath);
|
||||
|
||||
_diskProvider.MoveFile(dbRestorePath, dbPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, "Failed to restore database");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using Nancy;
|
||||
using Sonarr.Http.Exceptions;
|
||||
|
||||
namespace Sonarr.Http.REST
|
||||
{
|
||||
public class UnsupportedMediaTypeException : ApiException
|
||||
{
|
||||
public UnsupportedMediaTypeException(object content = null)
|
||||
: base(HttpStatusCode.UnsupportedMediaType, content)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue