private async Task ProcessDbs(List <Database> offlineDbs) { _context.WriteLine($"Attempting to archiving {offlineDbs.Count}"); foreach (var db in offlineDbs) { using ( var server = new DatabaseServer($"Server={db.Hostname}; Database=Master; Trusted_Connection=true")) { if (!await server.Open()) { _context.Write($"Could not connect to master db on {db.Hostname}. Databases from this server will be skipped.", ConsoleTextColor.Yellow); continue; } if (!server.OnlineDatabase(db.Name)) { _context.Write($"Unable to online [{db.Hostname}]{db.Name}. This database will be skipped", ConsoleTextColor.Yellow); continue; } if (!await db.Open()) { _context.Write($"Could not connect to {db.Name} on {db.Hostname}. This databases will be skipped.", ConsoleTextColor.Yellow); continue; } if (await db.Backup()) { if (!await db.Delete()) { _context.Write($"Unable to delete [{db.Hostname}]{db.Name}", ConsoleTextColor.Yellow); _context.Write($"Attempting to offline [{db.Hostname}]{db.Name}", ConsoleTextColor.Yellow); server.OfflineDatabase(db.Name); } } else { _context.Write($"Unable to backup [{db.Hostname}]{db.Name}", ConsoleTextColor.Yellow); _context.Write($"Attempting to offline [{db.Hostname}]{db.Name}", ConsoleTextColor.Yellow); server.OfflineDatabase(db.Name); } } db.Dispose(); } }