2012-01-27 06:05:09 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Ionic.Zip;
|
|
|
|
|
using NLog;
|
|
|
|
|
using Ninject;
|
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
|
|
|
|
public class BackupProvider
|
|
|
|
|
{
|
2012-03-07 03:59:43 +01:00
|
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
2012-01-27 06:05:09 +01:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
[Inject]
|
2012-03-07 03:59:43 +01:00
|
|
|
|
public BackupProvider(EnvironmentProvider environmentProvider)
|
2012-01-27 06:05:09 +01:00
|
|
|
|
{
|
2012-03-07 03:59:43 +01:00
|
|
|
|
_environmentProvider = environmentProvider;
|
2012-01-27 06:05:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BackupProvider()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual string CreateBackupZip()
|
|
|
|
|
{
|
2012-08-14 20:51:25 +02:00
|
|
|
|
var dbFile = _environmentProvider.GetNzbDroneDbFile();
|
2012-03-07 03:59:43 +01:00
|
|
|
|
var configFile = _environmentProvider.GetConfigPath();
|
|
|
|
|
var zipFile = _environmentProvider.GetConfigBackupFile();
|
2012-01-27 06:05:09 +01:00
|
|
|
|
|
2012-01-27 06:24:41 +01:00
|
|
|
|
using (var zip = new ZipFile())
|
2012-01-27 06:05:09 +01:00
|
|
|
|
{
|
2012-01-27 06:24:41 +01:00
|
|
|
|
zip.AddFile(dbFile, String.Empty);
|
|
|
|
|
zip.AddFile(configFile, String.Empty);
|
|
|
|
|
zip.Save(zipFile);
|
2012-01-27 06:05:09 +01:00
|
|
|
|
}
|
2012-01-27 06:24:41 +01:00
|
|
|
|
|
|
|
|
|
return zipFile;
|
2012-01-27 06:05:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|