|
|
@ -1,6 +1,7 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data;
|
|
|
|
using System.Data;
|
|
|
|
|
|
|
|
using System.Data.SQLite;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
@ -25,6 +26,7 @@ namespace NzbDrone.Core.Backup
|
|
|
|
public class BackupService : IBackupService, IExecute<BackupCommand>
|
|
|
|
public class BackupService : IBackupService, IExecute<BackupCommand>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IMainDatabase _maindDb;
|
|
|
|
private readonly IMainDatabase _maindDb;
|
|
|
|
|
|
|
|
private readonly IMakeDatabaseBackup _makeDatabaseBackup;
|
|
|
|
private readonly IDiskTransferService _diskTransferService;
|
|
|
|
private readonly IDiskTransferService _diskTransferService;
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
@ -36,6 +38,7 @@ namespace NzbDrone.Core.Backup
|
|
|
|
private static readonly Regex BackupFileRegex = new Regex(@"nzbdrone_backup_[._0-9]+\.zip", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
private static readonly Regex BackupFileRegex = new Regex(@"nzbdrone_backup_[._0-9]+\.zip", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
|
|
|
|
public BackupService(IMainDatabase maindDb,
|
|
|
|
public BackupService(IMainDatabase maindDb,
|
|
|
|
|
|
|
|
IMakeDatabaseBackup makeDatabaseBackup,
|
|
|
|
IDiskTransferService diskTransferService,
|
|
|
|
IDiskTransferService diskTransferService,
|
|
|
|
IDiskProvider diskProvider,
|
|
|
|
IDiskProvider diskProvider,
|
|
|
|
IAppFolderInfo appFolderInfo,
|
|
|
|
IAppFolderInfo appFolderInfo,
|
|
|
@ -43,6 +46,7 @@ namespace NzbDrone.Core.Backup
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_maindDb = maindDb;
|
|
|
|
_maindDb = maindDb;
|
|
|
|
|
|
|
|
_makeDatabaseBackup = makeDatabaseBackup;
|
|
|
|
_diskTransferService = diskTransferService;
|
|
|
|
_diskTransferService = diskTransferService;
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
@ -68,7 +72,7 @@ namespace NzbDrone.Core.Backup
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CleanupOldBackups(backupType);
|
|
|
|
CleanupOldBackups(backupType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BackupConfigFile();
|
|
|
|
BackupConfigFile();
|
|
|
|
BackupDatabase();
|
|
|
|
BackupDatabase();
|
|
|
|
|
|
|
|
|
|
|
@ -111,17 +115,7 @@ namespace NzbDrone.Core.Backup
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.ProgressDebug("Backing up database");
|
|
|
|
_logger.ProgressDebug("Backing up database");
|
|
|
|
|
|
|
|
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => _maindDb.GetDataMapper()))
|
|
|
|
_makeDatabaseBackup.BackupDatabase(_maindDb, _backupTempFolder);
|
|
|
|
{
|
|
|
|
|
|
|
|
unitOfWork.BeginTransaction(IsolationLevel.Serializable);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var databaseFile = _appFolderInfo.GetNzbDroneDatabase();
|
|
|
|
|
|
|
|
var tempDatabaseFile = Path.Combine(_backupTempFolder, Path.GetFileName(databaseFile));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_diskTransferService.TransferFile(databaseFile, tempDatabaseFile, TransferMode.Copy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BackupConfigFile()
|
|
|
|
private void BackupConfigFile()
|
|
|
|