in Source/NuGetGallery.Operations/Tasks/Backups/ExportWarehouseBackupsTask.cs [43:80]
public override void ExecuteCommand()
{
WithMasterConnection((connection, db) =>
{
// Snap the current date just in case we are running right on the cusp
var today = DateTime.UtcNow;
// Get the list of database backups
var backups = db.Query<Db>(
"SELECT name, state FROM sys.databases WHERE name LIKE 'WarehouseBackup_%' AND state = @state",
new { state = Util.OnlineState })
.Select(d => new OnlineDatabaseBackup(Util.GetDatabaseServerName(ConnectionString), d.Name, d.State))
.Where(b => b.Timestamp != null)
.OrderByDescending(b => b.Timestamp)
.ToList();
// Grab any end-of-day backups
var dailyBackups = backups
.Where(b => b.Timestamp.Value.Hour == 23 && b.Timestamp.Value.Minute > 30)
.ToList();
Log.Info("Found {0} daily backups to export", dailyBackups.Count);
// Start exporting them
foreach (var dailyBackup in dailyBackups)
{
Log.Info("Exporting '{0}'...", dailyBackup.DatabaseName);
(new ExportDatabaseTask()
{
ConnectionString = ConnectionString,
DestinationStorage = StorageAccount,
DatabaseName = dailyBackup.DatabaseName,
DestinationContainer = "warehouse-backups",
SqlDacEndpoint = SqlDacEndpoint,
WhatIf = WhatIf
}).Execute();
}
});
}