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