public void Backup() { _logger.Info("Backing up appdata (database/config)"); var backupFolderAppData = _appFolderInfo.GetUpdateBackUpAppDataFolder(); if (_diskProvider.FolderExists(backupFolderAppData)) { _diskProvider.EmptyFolder(backupFolderAppData); } else { _diskProvider.CreateFolder(backupFolderAppData); } try { _diskTransferService.TransferFile(_appFolderInfo.GetConfigPath(), _appFolderInfo.GetUpdateBackupConfigFile(), TransferMode.Copy); //Backup new db if exists, else try old then fail if (_diskProvider.FileExists(_appFolderInfo.GetDatabase())) { _diskTransferService.TransferFile(_appFolderInfo.GetDatabase(), _appFolderInfo.GetUpdateBackupDatabase(), TransferMode.Copy); } else { _diskTransferService.TransferFile(_appFolderInfo.GetV0Database(), _appFolderInfo.GetV0UpdateBackupDatabase(), TransferMode.Copy); } } catch (Exception e) { _logger.Error(e, "Couldn't create a data backup"); } }
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; } }
private void MigrateAppDataFolder() { try { var oldDbFile = Path.Combine(_appFolderInfo.AppDataFolder, "nzbdrone.db"); if (_startupContext.Args.ContainsKey(StartupContext.APPDATA)) { if (_diskProvider.FileExists(_appFolderInfo.GetDatabase())) { return; } if (!_diskProvider.FileExists(oldDbFile)) { return; } _diskProvider.MoveFile(oldDbFile, _appFolderInfo.GetDatabase()); CleanupSqLiteRollbackFiles(); RemovePidFile(); } // Exit if a prowlarr.db already exists if (_diskProvider.FileExists(_appFolderInfo.GetDatabase())) { return; } // Rename the DB file if (_diskProvider.FileExists(oldDbFile)) { _diskProvider.MoveFile(oldDbFile, _appFolderInfo.GetDatabase()); } // Remove SQLite rollback files CleanupSqLiteRollbackFiles(); // Remove Old PID file RemovePidFile(); } catch (Exception ex) { _logger.Debug(ex, ex.Message); throw new ProwlarrStartupException("Unable to migrate DB from nzbdrone.db to {0}. Migrate manually", _appFolderInfo.GetDatabase()); } }
public ConnectionStringFactory(IAppFolderInfo appFolderInfo, IConfigFileProvider configFileProvider) { _configFileProvider = configFileProvider; MainDbConnectionString = _configFileProvider.PostgresHost.IsNotNullOrWhiteSpace() ? GetPostgresConnectionString(_configFileProvider.PostgresMainDb) : GetConnectionString(appFolderInfo.GetDatabase()); LogDbConnectionString = _configFileProvider.PostgresHost.IsNotNullOrWhiteSpace() ? GetPostgresConnectionString(_configFileProvider.PostgresLogDb) : GetConnectionString(appFolderInfo.GetLogDatabase()); }
public ConnectionStringFactory(IAppFolderInfo appFolderInfo) { MainDbConnectionString = GetConnectionString(appFolderInfo.GetDatabase()); LogDbConnectionString = GetConnectionString(appFolderInfo.GetLogDatabase()); }
private void MigrateAppDataFolder() { try { var oldDbFile = Path.Combine(_appFolderInfo.AppDataFolder, "nzbdrone.db"); if (_startupContext.Args.ContainsKey(StartupContext.APPDATA)) { if (_diskProvider.FileExists(_appFolderInfo.GetDatabase())) { return; } if (!_diskProvider.FileExists(oldDbFile)) { return; } _diskProvider.MoveFile(oldDbFile, _appFolderInfo.GetDatabase()); CleanupSqLiteRollbackFiles(); RemovePidFile(); } if (_appFolderInfo.LegacyAppDataFolder.IsNullOrWhiteSpace()) { return; } if (_diskProvider.FileExists(_appFolderInfo.GetDatabase()) || _diskProvider.FileExists(_appFolderInfo.GetConfigPath())) { return; } if (!_diskProvider.FolderExists(_appFolderInfo.LegacyAppDataFolder)) { return; } // Delete the bin folder on Windows var binFolder = Path.Combine(_appFolderInfo.LegacyAppDataFolder, "bin"); if (OsInfo.IsWindows && _diskProvider.FolderExists(binFolder)) { _diskProvider.DeleteFolder(binFolder, true); } // Transfer other files and folders (with copy so a backup is maintained) _diskTransferService.TransferFolder(_appFolderInfo.LegacyAppDataFolder, _appFolderInfo.AppDataFolder, TransferMode.Copy); // Rename the DB file if (_diskProvider.FileExists(oldDbFile)) { _diskProvider.MoveFile(oldDbFile, _appFolderInfo.GetDatabase()); } // Remove SQLite rollback files CleanupSqLiteRollbackFiles(); // Remove Old PID file RemovePidFile(); // Delete the old files after everything has been copied _diskProvider.DeleteFolder(_appFolderInfo.LegacyAppDataFolder, true); } catch (Exception ex) { _logger.Debug(ex, ex.Message); throw new SonarrStartupException("Unable to migrate AppData folder from {0} to {1}. Migrate manually", _appFolderInfo.LegacyAppDataFolder, _appFolderInfo.AppDataFolder); } }