Skip to content

A .Net Framework and .Net Standard library with multi-purpose backup compatibility

Notifications You must be signed in to change notification settings

aliarabbasi5155/multi-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SaaedBackup

N|Solid

Build Status

SaaedBackup is a backup library for .Net & .Net Standard written in C#.

Features

  • Support for Single-File backup
  • Support for Directory backup
  • Support for SQL database backup
  • Support for FTP directory backup
  • Support for store sources into local directories
  • Support for store sources into FTP
  • Compress all types of sources into Password-Protected archives
  • Check all types of sources to validate all containing files
  • Full-cover logging service

You can also visit https://www.saaedco.com

Releases

SaaedBackup supports .Net Standard 2.0 and lower and it can be used with .Net Framework up to 4.6.1.
Also SaaedBackup supports Mono 4.6, Xamarin.iOS 10.14, Xamarin.Android 3.8, Xamarin.Mac 3.8 and UWP 10.0.16299 via .Net Standard 2.0.

Example Usage

//create a file source to get backup from pic.jpg file 
var fileSource = new FileSource(@"X:\pic.jpg");

//create a folder source to get backup from files in test directory var folderSource = new FolderSource(@"X:\test");

//create a SQL source to get full backup from databases of a SQL server var sqlSource = new SqlSource("serverName", "databaseName", "username", "password", "backupName", SqlSource.BackupMode.FullBackup);

//create a compress source from sources above var compressSource = new CompressSource(new [] { fileSource, folderSource, sqlSource }, CompressMode.Zip, null, null, SourceBase.ValidationMode.Validate);

//create a folder store to store sources in test diectory var folderStore = new FolderStore(@"X:\test");

//create a FTP store to store sources in FTP test diectory var ftpStore = new FtpStore(@"ftp://serverNameOrAddress/test", "username", "password");

//getting backup from sources (tempFolder is customizable) var backup = new Backupper(); backup.Backup(new SourceBase[] { fileSource, compressSource }, new StoreBase[] { folderStore, ftpStore }, @"X:\tempFolder");

This code snippet will backup from a file, a folder and an SQL database, then will combine them and put them into a compress file and finally store compress file and file in a folder and FTP destination.

Documentation

Sources

FileSource

FileSource is used to backup from a single file like jpg, doc, exe, etc.

FileSource(string fullPath, ValidationMode validationMode, string meta)

fullPath: The complete path of the file like: C:\Directory\File.exe
validationMode: If validation is necessary it should be set as 1 otherwise set as 0
meta: Additional information about source.

FolderSource

FolderSource is used to backup from a directory and recursively all of its sub files and sub directories.

FolderSource(string path, ValidationMode validationMode, string meta)

path: The complete path of specified directory
validationMode: If validation is necessary it should be set as 1 otherwise set as 0
meta: Additional information about source.

SqlSource

SqlSource is used to get full or differential backup from a database on a SQL server.

SqlSource(string serverName, string databaseName, string databaseUsername, string databasePassword, string backupName, BackupMode backupMode, string meta)

serverName: The name or IP address of the destination server.
databaseName: The name of the destination database on the server.
databaseUsername: The username of the server to use for authentication.
databasePassword: The password of the server to use for authentication.
backupName: The name of final backed up file.
backupMode: Determine type of the backup (Full or Differential).
meta: Additional information about source. directory

CompressSource

CompressSource is used when you want to put some other sources in a compress archive.

CompressSource(IEnumerable<Base.SourceBase> sources, CompressMode compressMode, string password, string compressFileName, ValidationMode validationMode)

sources: The intended sources to compress.
compressMode: The type of compression (zip, rar, etc.).
password: The password of the output file.
CompressFileName: The name of the output file.
validationMode: If validation is necessary it should be set as 1 otherwise set as 0.

Store

FolderStore

FolderStore is used to store any type of sources into a directory.

FolderStore(string fullPath)

fullPath: The complete path of destination directory.

FtpStore

FtpStore is used to store any type of sources into a FTP directory.

FtpStore(string destPath, string username, string password)

destPath: The full path of destination directory on FTP server starting with ftp:// .
username: The username of the FTP server.
password: The password of the FTP server.

Backup Process

Backupper

Backupper object is used to get start backup process and bring sources and stores together.

Backup(IEnumerable<SourceBase> sources, IEnumerable<StoreBase> stores, string tempDir)

sources: The input source objects to backup.
stores: The output store objects to store file.
tempDir: The temporary directory to store temporary files (default: %tmp%).

Events

Sources

SourceStatus: Invokes when source backup process has completed or has failed.
ValidationResultEvent: Invokes when source validation process is completed.

Stores

StoreStatus: Invokes when store process has completed or has failed.

Backupper

SourcesStatus: Invokes when a source backup process has completed or has failed.
StoresStatus: Invokes when a store process has completed or has failed.
SourcesAndStoresStatus: Invokes when a source backup process has fully backed up and has stored or has failed.
BackupperStatus: Invokes when an exception has occurred in Backupper.Backup() or it has completed without error.
AllErrors: Invokes when any exception has occurred in any part of backup process or each part has completed without error.

Dependencies

SaaedBackup has some dependencies which is listed below:

FluentFTP (https://github.com/robinrodricks/FluentFTP)
SharpZipLib (https://github.com/icsharpcode/SharpZipLib)

FAQ

1.How to backup from a single file?
var fileSource = new FileSource(@"X:\pic.jpg");
var folderStore = new FolderStore(@"X:\test");
var backup = new Backupper();
backup.Backup(new SourceBase[] { fileSource }, new StoreBase[] { folderStore }, @"X:\tempFolder");
2.How to backup from a directory?
var folderSource = new FolderSource(@"X:\sourceDir");
var folderStore = new FolderStore(@"X:\test");
var backup = new Backupper();
backup.Backup(new SourceBase[] { folderSource }, new StoreBase[] { folderStore }, @"X:\tempFolder");
3.How to backup from a SQL server database?
var sqlSource = new SqlSource("serverName", "databaseName", "username", "password", "backupName", SqlSource.BackupMode.FullBackup);
var folderStore = new FolderStore(@"X:\test");
var backup = new Backupper();
backup.Backup(new SourceBase[] { sqlSource }, new StoreBase[] { folderStore }, @"X:\tempFolder");
4.How to backup from some sources and compress them into an archive?
var fileSource = new FileSource(@"X:\pic.jpg");
var folderSource = new FolderSource(@"X:\sourceDir");
var sqlSource = new SqlSource("serverName", "databaseName", "username", "password", "backupName", SqlSource.BackupMode.FullBackup);
var compressSource = new CompressSource(new [] { fileSource, folderSource, sqlSource }, CompressMode.Zip, "archivePassword", "archiveName", SourceBase.ValidationMode.Validate);
backup.Backup(new SourceBase[] { compressSource }, new StoreBase[] { folderStore }, @"X:\tempFolder");
5.How to backup from a source and store in a directory?
var fileSource = new FileSource(@"X:\pic.jpg");
var folderStore = new FolderStore(@"X:\test");
var backup = new Backupper();
backup.Backup(new SourceBase[] { fileSource }, new StoreBase[] { folderStore }, @"X:\tempFolder");
6.How to backup from a source and store in a FTP server?
var fileSource = new FileSource(@"X:\pic.jpg");
var ftpStore = new FtpStore("ftp://127.0.0.1", "username", "password");
var backup = new Backupper();
backup.Backup(new SourceBase[] { fileSource }, new StoreBase[] { ftpStore }, @"X:\tempFolder");
7.How to backup from multiple sources?
var fileSource0 = new FileSource(@"X:\pic.jpg");
var fileSource1 = new FileSource(@"X:\mydoc.docx");
var folderSource = new FolderSource(@"X:\sourceDir");
var sqlSource = new SqlSource("serverName", "databaseName", "username", "password", "backupName", SqlSource.BackupMode.FullBackup);
var compressSource = new CompressSource(new [] { fileSource1, folderSource}, CompressMode.Zip, "archivePassword", "archiveName", SourceBase.ValidationMode.Validate);
var folderStore = new FolderStore(@"X:\test");
var backup = new Backupper();
backup.Backup(new SourceBase[] { fileSource0, fileSource1 , folderSource, sqlSource, compressSource }, new StoreBase[] { folderStore }, @"X:\tempFolder");
8.How to backup from a source and store in multiple places?
var fileSource = new FileSource(@"X:\pic.jpg");
var ftpStore = new FtpStore("ftp://127.0.0.1", "username", "password");
var folderStore = new FolderStore(@"X:\test");
var backup = new Backupper();
backup.Backup(new SourceBase[] { fileSource }, new StoreBase[] { ftpStore, folderStore }, @"X:\tempFolder");

About

A .Net Framework and .Net Standard library with multi-purpose backup compatibility

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages