pvWay.MsSqlBackup.nc6
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package pvWay.MsSqlBackup.nc6 --version 1.0.1
NuGet\Install-Package pvWay.MsSqlBackup.nc6 -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="pvWay.MsSqlBackup.nc6" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add pvWay.MsSqlBackup.nc6 --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: pvWay.MsSqlBackup.nc6, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install pvWay.MsSqlBackup.nc6 as a Cake Addin #addin nuget:?package=pvWay.MsSqlBackup.nc6&version=1.0.1 // Install pvWay.MsSqlBackup.nc6 as a Cake Tool #tool nuget:?package=pvWay.MsSqlBackup.nc6&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Ms Sql Backup dotNet Core 6
Tiny DAO utility that backs up any Ms Sql Db (any edition) to a local folder, a network drive or an Azure Container and executes maintenance plans
Interfaces
IMsSqlBackupCreator
The nuGet has several methods all in three modes sync, async and pure background.
using System;
using System.Threading.Tasks;
namespace pvWay.MsSqlBackup.Core
{
public interface IMsSqlBackupCreator
{
/// <summary>
/// Creates a full backup of the database
/// </summary>
/// <param name="bakFileName">Fully qualified backup file name where the running app has write access</param>
/// <returns>IResult</returns>
Task<IResult> BackupDbAsync(string bakFileName);
/// <summary>
/// Creates a full backup of the database
/// </summary>
/// <param name="bakFileName">Fully qualified backup file name where the running app has write access</param>
/// <returns>IResult</returns>
IResult BackupDb(string bakFileName);
/// <summary>
/// Creates a full backup of the database in background
/// </summary>
/// <param name="bakFileName">Fully qualified backup file name where the running app has write access</param>
/// <param name="callback">A method that will be called on completion</param>
/// <returns>void</returns>
void BgBackupDb(string bakFileName, Action<IResult> callback);
/// <summary>
/// (1) finds the last backup file in the <backupDestinationFolder>
/// by looking to files beginning with <backupFilePrefix> and ending with '.bak'
/// (2) gets the last backup file modification time.
/// (3) gets the elapsed time since this last backup.
/// (4) if no file were found or elapsed time is greater
/// than <backupInterval> then creates a new backup
/// with a constructed file name
/// <backupFilePrefix>_<yyyyMMdd_HHmmss>.bak;
/// and save this new backup file into the <backupDestinationFolder>
/// </summary>
/// <param name="backupDestinationFolder"></param>
/// <param name="backupFilePrefix"></param>
/// <param name="backupInterval"></param>
/// <returns>IExecuteMaintenancePlanResult</returns>
Task<IExecuteMaintenancePlanResult> ExecuteMaintenancePlanAsync(
string backupDestinationFolder,
string backupFilePrefix,
TimeSpan backupInterval);
/// <summary>
/// (1) finds the last backup file in the <backupDestinationFolder>
/// by looking to files beginning with <backupFilePrefix> and ending with '.bak'
/// (2) gets the last backup file modification time.
/// (3) gets the elapsed time since this last backup.
/// (4) if no file were found or elapsed time is greater
/// than <backupInterval> then creates a new backup
/// with a constructed file name
/// <backupFilePrefix>_<yyyyMMdd_HHmmss>.bak;
/// and save this new backup file into the <backupDestinationFolder>
/// </summary>
/// <param name="backupDestinationFolder">the folder where all backup files reside</param>
/// <param name="backupFilePrefix"></param>
/// <param name="backupInterval"></param>
/// <returns>IExecuteMaintenancePlanResult</returns>
IExecuteMaintenancePlanResult ExecuteMaintenancePlan(
string backupDestinationFolder,
string backupFilePrefix,
TimeSpan backupInterval);
/// <summary>
/// Performs the following task in background and callbacks on completion:
/// (1) finds the last backup file in the <backupDestinationFolder>
/// by looking to files beginning with <backupFilePrefix> and ending with '.bak'
/// (2) gets the last backup file modification time.
/// (3) gets the elapsed time since this last backup.
/// (4) if no file were found or elapsed time is greater
/// than <backupInterval> then creates a new backup
/// with a constructed file name
/// <backupFilePrefix>_<yyyyMMdd_HHmmss>.bak;
/// and save this new backup file into the <backupDestinationFolder>
/// </summary>
/// <param name="backupDestinationFolder"></param>
/// <param name="backupFilePrefix"></param>
/// <param name="backupInterval"></param>
/// <param name="callback"></param>
/// <returns>IExecuteMaintenancePlanResult</returns>
void BgExecuteMaintenancePlan(
string backupDestinationFolder,
string backupFilePrefix,
TimeSpan backupInterval,
Action<IExecuteMaintenancePlanResult> callback);
}
}
return values
using System;
namespace pvWay.MsSqlBackup.Core
{
public interface IResult
{
bool Success { get; }
bool Failure { get; }
Exception Exception { get; }
}
public interface IExecuteMaintenancePlanResult : IResult
{
bool BackupCreated { get; }
string BackupFileName { get; }
}
}
Usage
See here after a short Console that use the service
Principe
- need to pass a work folder where the Ms Sql Server has write access
- need to pass the connection string
- need to pass a destination file where the app has write access
- you can follow up on progress by passing a notifier callback
The code
using System;
using pvWay.MsSqlBackup.Core;
namespace MsSqlBackupLab.Core
{
internal static class Program
{
private static void Main(/*string[] args*/)
{
// make sure Ms Sql Server has write access to this work folder
const string localWorkFolder = "d:\\temp";
// the connection string to the db you want to back up
const string connectionString = "data source = localhost; " +
"initial catalog = TCM004_DEV; " +
"integrated security = True; " +
"MultipleActiveResultSets = True; ";
var backupCreator = new MsSqlBackupCreator(
localWorkFolder,
connectionString,
// let's redirect progress notifications to the console
Console.WriteLine);
// let's generate a unique bak file name using a GUID
var id = Guid.NewGuid().ToString();
var bakFileNameNwDrive = $"y:\\MsSqlBak\\Tcm004_{id}.bak";
// ok now launch the backup
var res = backupCreator
.BackupDbAsync(bakFileNameNwDrive).Result;
/*
CONSOLE Should display this
---------------------------
nuGet pvWay.MsSqlBackup connecting to localhost
nuGet pvWay.MsSqlBackup backing up database TCM004_DEV to local work folder d:\temp\
nuGet pvWay.MsSqlBackup copying backup file to destination: y:\MsSqlBak\Tcm004_85daa4de-d2b3-42e8-99bb-aad2252f1b41.bak
nuGet pvWay.MsSqlBackup removing temp file from d:\temp
*/
if (res.Failure)
{
Console.WriteLine(res.Exception);
}
else
{
Console.WriteLine("Backup completed");
}
Console.WriteLine("hit a key to quit");
Console.ReadKey();
}
}
}
Happy coding
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Azure.Storage.Blobs (>= 12.13.0)
- System.Data.SqlClient (>= 4.8.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
update azure storage nuGet