Only backup database and config file before update

pull/4/head
Mark McDowall 11 years ago
parent 85b211738b
commit e16a6f2b9c

@ -204,6 +204,20 @@ namespace NzbDrone.Common.Disk
File.Delete(path);
}
public void CopyFile(string source, string destination, bool overwrite = false)
{
Ensure.That(source, () => source).IsValidPath();
Ensure.That(destination, () => destination).IsValidPath();
if (source.PathEquals(destination))
{
Logger.Warn("Source and destination can't be the same {0}", source);
return;
}
File.Copy(source, destination, overwrite);
}
public void MoveFile(string source, string destination)
{
Ensure.That(source, () => source).IsValidPath();

@ -26,6 +26,7 @@ namespace NzbDrone.Common.Disk
void CopyFolder(string source, string destination);
void MoveFolder(string source, string destination);
void DeleteFile(string path);
void CopyFile(string source, string destination, bool overwrite = false);
void MoveFile(string source, string destination);
void DeleteFolder(string path, bool recursive);
string ReadAllText(string filePath);

@ -161,6 +161,16 @@ namespace NzbDrone.Common
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_BACKUP_APPDATA_FOLDER_NAME);
}
public static string GetUpdateBackupConfigFile(this IAppFolderInfo appFolderInfo)
{
return Path.Combine(GetUpdateBackUpAppDataFolder(appFolderInfo), APP_CONFIG_FILE);
}
public static string GetUpdateBackupDatabase(this IAppFolderInfo appFolderInfo)
{
return Path.Combine(GetUpdateBackUpAppDataFolder(appFolderInfo), NZBDRONE_DB);
}
public static string GetUpdatePackageFolder(this IAppFolderInfo appFolderInfo)
{
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_PACKAGE_FOLDER_NAME);

@ -27,18 +27,11 @@ namespace NzbDrone.Update.UpdateEngine
public void Backup()
{
_logger.Info("Backing up appdata (database/config)");
var appDataPath = _appFolderInfo.GetAppDataPath();
var backupFolderAppData = _appFolderInfo.GetUpdateBackUpAppDataFolder();
var binFolder = Path.Combine(backupFolderAppData, "bin");
_diskProvider.CreateFolder(backupFolderAppData);
_diskProvider.CopyFolder(appDataPath, backupFolderAppData);
if (_diskProvider.FolderExists(binFolder))
{
_logger.Info("Deleting bin folder from appdata");
_diskProvider.DeleteFolder(binFolder, true);
}
_diskProvider.CopyFile(_appFolderInfo.GetConfigPath(), _appFolderInfo.GetUpdateBackupConfigFile(), true);
_diskProvider.CopyFile(_appFolderInfo.GetNzbDroneDatabase(), _appFolderInfo.GetUpdateBackupDatabase(), true);
}
}
}

Loading…
Cancel
Save