A C# library and command-line to backup your items from any source to any destination.
Below are the current available sources and destinations:
- Sources
- FTP
- Local folder
- MySQL
- Destinations
- Dropbox
- Local Folder
- Zip
mono BackupSharp.CommandLine.exe --help
-
-s, --sourceName
The backup source class name
-
-r, --sourceArgs
The backup source class constructor args
-
-d, --destinationName
The backup destination class name
-
-t, --destinationArgs
The backup destination class constructor args
-
-f, --file
Required. The backup configuration file
-
-b, --backupName
Only backup with specified name will be run
-
--sourceStartsWith
Only backup with source ID that starts with specified text
-
--sourceEndsWith
Only backup with source ID that ends with specified text
-
-v, --verbose
Should log everything
mono BackupSharp.CommandLine.exe
--sourceName=FTP
--sourceArgs=[server address],[username],[password]
--destinationName=[destination]
--destinationArgs=[destination args]
Where:
- [server address] = The address/IP of the source FTP server.
- [username] = The username used to connect on FTP server.
- [password] = The password used to connect on FTP server.
mono BackupSharp.CommandLine.exe
--sourceName=LocalFolder
--sourceArgs=[source id],[source folder]
--destinationName=[destination]
--destinationArgs=[destination args]
Where:
- [source id] = The ID used to identify source.
- [source folder] = The path to the source folder.
mono BackupSharp.CommandLine.exe
--sourceName=MySql
--sourceArgs=[connection string]
--destinationName=[destination]
--destinationArgs=[destination args]
Where:
- [connection string] = The connection string to MySQL database.
mono BackupSharp.CommandLine.exe
--sourceName=[source]
--sourceArgs=[source args]
--destinationName=Dropbox
--destinationArgs=[API key],[API secret],[access token]
Where:
- [API key] = App key from Dropbox developer App Console.
- [API secret] = App secrect from Dropbox developer App Console.
- [access token] = Access token from Dropbox developer App Console.
To use the Dropbox destination you will need to create an app on Dropbox developer App Console (https://www.dropbox.com/developers/apps), then access the app details where you can get the API key, API secret and the access token ('Generate acces token`).
####Local folder
mono BackupSharp.CommandLine.exe
--sourceName=[source]
--sourceArgs=[source args]
--destinationName=LocalFolder
--destinationArgs=[destination folder]
Where:
- [destination folder] = The destination folder path.
mono BackupSharp.CommandLine.exe
--sourceName=[source]
--sourceArgs=[source args]
--destinationName=Zip
--destinationArgs=[destination folder]
Where:
- [destination folder] = The destination folder where the Zip file will be generated.
Backup items from a FTP server to a Dropbox account:
mono BackupSharp.CommandLine.exe
--sourceName=FTP
--sourceArgs=[server address],[username],[password]
--destinationName=Dropbox
--destinationArgs=[API key],[API secret],[access token]
Backup items from a FTP server to a local folder:
mono BackupSharp.CommandLine.exe
--sourceName=FTP
--sourceArgs=[server address],[username],[password]
--destinationName=LocalFolder
--destinationArgs=[destination folder]
Backup items from a FTP server to a Zip file:
mono BackupSharp.CommandLine.exe
--sourceName=FTP
--sourceArgs=[server address],[username],[password]
--destinationName=Zip
--destinationArgs=[destination folder]
Backup items from a local folder to a Zip file:
mono BackupSharp.CommandLine.exe
--sourceName=LocalFolder
--sourceArgs=[source id],[source folder]
--destinationName=Zip
--destinationArgs=[destination folder]
<?xml version="1.0" encoding="UTF-8"?>
<backupSharp>
<sources>
<source type="LocalFolder" id="SourceFolder" args="temp/source" />
<source type="MySql" id="SourceMySql" args="server=my_server_address;user=my_user;pwd=my_password;database=my_database_name;allowzerodatetime=true;" />
</sources>
<destinations>
<destination type="Zip" id="DestinationZip" args="temp" />
</destinations>
<backups>
<backup source="SourceFolder" destination="DestinationZip" />
<backup source="SourceMySql" destination="DestinationZip" />
</backups>
</backupSharp>
mono BackupSharp.CommandLine.exe -f my_backups.config
var source = new MySqlBackupSource(connectionString);
var destination = new ZipBackupDestination(destinationFolderPath);
var backup = new Backup(source, destination);
backup.Run();
To implement a new backup source you can implement the IBackupSource interface or inherit from BackupSourceBase:
public class SampleBackupSource : BackupSourceBase
{
/// <summary>
/// Gets the items.
/// </summary>
/// <returns>
/// The available items on source.
/// </returns>
public override IEnumerable<IBackupItem> GetItems()
{
// Get the available items on backup source.
// Remember to use yield ;)
}
/// <summary>
/// Reads the item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>
/// The item byte array.
/// </returns>
public override byte[] ReadItem(IBackupItem item)
{
// Reads the backup item in an array of bytes.
}
}
To implement a new backup destination you can implement the IBackupDestination interface or inherit from BackupDestinationBase:
public class SampleBackupDestination : BackupDestinationBase
{
/// <summary>
/// Stores the item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="data">The data.</param>
public override void StoreItem(IBackupItem item, byte[] data)
{
// Writes the item using information on item.DestinationFullName and the bytes from data argument.
}
}
To run the tests from BackupSharp.FunctionalTests project you will need to set some environment variables:
- FTP
- BackupSharpFtpServer
- BackupSharpFtpUserName
- BackupSharpFtpPassword
- BackupSharpFtpFolder
- MySQL
- BackupSharpMySqlServer
- BackupSharpMySqlUserName
- BackupSharpMySqlPassword
- BackupSharpMySqlDatabase
- Dropbox
- BackupSharpDropboxApiKey
- BackupSharpDropboxApiSecret
- BackupSharpDropboxAccessToken
We use environment variables to define those arguments to functional/integration tests because with environment variables we can encrypt the data to Travis-CI, like described in this tutorial "Using sensitive data on your Travis-CI build".
- Ask on Stack Overflow
- Package command-line to GitHub releases section.
- Publish NuGet package.
- New sources
- MS SQL Server
- Create a fork of BackupSharp.
- Did you change it? Submit a pull request.
Licensed under the The MIT License (MIT). In others words, you can use this library for developement any kind of software: open source, commercial, proprietary and alien.