SQLBackupService 1.0.0

dotnet add package SQLBackupService --version 1.0.0                
NuGet\Install-Package SQLBackupService -Version 1.0.0                
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="SQLBackupService" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SQLBackupService --version 1.0.0                
#r "nuget: SQLBackupService, 1.0.0"                
#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 SQLBackupService as a Cake Addin
#addin nuget:?package=SQLBackupService&version=1.0.0

// Install SQLBackupService as a Cake Tool
#tool nuget:?package=SQLBackupService&version=1.0.0                

SQLBackupService DLL

Overview

The SQLBackupService DLL provides a set of utilities to manage SQL database backups. It allows you to create database backups, retrieve backup files from a directory, and delete backup files either by specifying the oldest or directly by file path.

Usage

Prerequisites

  • SQL Server installed and accessible

Installation

  1. Download the SQLBackupService DLL from https://github.com/Erfan4708/SQLBackupService .
  2. Add a reference to the DLL in your Visual Studio project.
  3. Ensure the required NuGet packages for SqlConnection and other dependencies are installed.

Example Usage

using SQLBackupService.Services;
using System;
using System.Data.SqlClient;

namespace YourNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Replace with your SQL Server connection string
            string connectionString = "Server=YOUR_SERVER_NAME;Database=YOUR_DATABASE_NAME;User Id=YOUR_USERNAME;Password=YOUR_PASSWORD;";

            // Create a SqlConnection instance
            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                // Create an instance of SQLBackupService
                var backupService = new SQLBackupService(sqlConnection);

                // Create a backup of the connected database
                backupService.CreateBackupFile();

                // Get all backup files from the default directory
                var backupFiles = backupService.GetAllBackupsFromDirectory();

                // Example: Delete the oldest backup file
                backupService.DeleteOldestBackupFile();

                // Example: Delete a backup file by specifying the file path
                string backupFilePathToDelete = @"C:\BackupFiles\ServerName-DatabaseName-20240712111327.bak";
                backupService.DeleteBackupFile(backupFilePathToDelete);
            }
        }
    }
}

Methods

CreateBackupFile(string directoryPath = null)
  • Creates a backup file of the connected SQL database.
  • Optionally, specify a directory path to store the backup.
GetAllBackupsFromDirectory(string backupFilePath = null)
  • Retrieves a list of all backup files in the specified directory.
  • Optionally, specify a directory path containing backup files.
DeleteOldestBackupFile(string backupFilePath = null)
  • Deletes the oldest backup file from the specified directory.
  • Optionally, specify a directory path containing backup files.
DeleteBackupFile(string backupFilePath)
  • Deletes the specified backup file by providing its file path.

Thread Safety

  • The SQLBackupService class uses locking mechanisms to ensure thread safety during critical operations (e.g., backup creation, file deletion).

Error Handling

  • Errors during directory creation, permission setting, backup execution, and file deletion are caught and logged to the console with descriptive messages.
Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 45 7/12/2024

Summary of changes made in this release of the package.