Skip to content

Commit

Permalink
fix #1 支持Azure Blob 存储。
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjusss committed Sep 16, 2018
1 parent f577def commit b0ad8e4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Backup2Cloud/Backup2Cloud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<NeutralLanguage></NeutralLanguage>
<AssemblyVersion>0.0.7.0</AssemblyVersion>
<FileVersion>0.0.7.0</FileVersion>
<Version>0.0.7</Version>
<AssemblyVersion>0.0.8.0</AssemblyVersion>
<FileVersion>0.0.8.0</FileVersion>
<Version>0.0.8</Version>
<Authors>sanjusss</Authors>
<Company />
<Description>定时将服务器上的文件备份到云存储。</Description>
Expand All @@ -30,6 +30,7 @@
<PackageReference Include="Quartz" Version="3.0.6" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="UCloudSDK.NetCore" Version="1.0.11" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions Backup2Cloud/Worker/Uploader/AzureBlobUploader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;

namespace Backup2Cloud.Worker.Uploader
{
/// <summary>
/// Azure Blob上传实现类。
/// </summary>
[ProviderName("azure")]
public class AzureBlobUploader : IUploader
{
/// <summary>
/// 连接字符串
/// </summary>
public string connectionString;
/// <summary>
/// 存储容器名
/// </summary>
public string container;
/// <summary>
/// 文件在Bucket下的路径,作为上传路径前缀。
/// </summary>
public string path;
/// <summary>
/// 提示信息
/// </summary>
public string Tips
{
get
{
return "connectionString:连接字符串;" +
"container:存储容器名;" +
"path:文件在Bucket下的路径,作为上传路径前缀";
}
}

/// <summary>
/// 获取示例实例。
/// </summary>
/// <returns>示例配置实例</returns>
public IUploader GetExample()
{
return new AzureBlobUploader()
{
connectionString = "connectionStringxxx",
container = "backup",
path = "data/some"
};
}

/// <summary>
/// 上传指定文件。
/// </summary>
/// <param name="file">待上传的文件</param>
/// <param name="suffix">文件在云空间里的后缀</param>
/// <exception cref="Exception"/>
public async Task Upload(string file, string suffix)
{
var account = CloudStorageAccount.Parse(connectionString);
var client = account.CreateCloudBlobClient();
var rc = client.GetContainerReference(container);
var blob = rc.GetBlockBlobReference(path + suffix);
await blob.UploadFromFileAsync(file);
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
|[京东云](https://www.jdcloud.com)|[对象存储](https://www.jdcloud.com/products/cloudstorag)|![支持](https://img.shields.io/badge/support-Yes-green.svg)||
|[青云](https://www.qingcloud.com)|[对象存储](https://www.qingcloud.com/products/qingstor/)|![支持](https://img.shields.io/badge/support-Yes-green.svg)||
|[金山云](https://www.ksyun.com)|[对象存储](https://www.ksyun.com/post/product/KS3)|![不支持](https://img.shields.io/badge/support-No-red.svg)|仅限企业用户|
|[Azure](https://www.azure.cn/zh-cn/)|[Blob 存储](https://www.azure.cn/zh-cn/home/features/storage/blobs/)|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)||
|[Azure](https://www.azure.cn/zh-cn/)|[Blob 存储](https://www.azure.cn/zh-cn/home/features/storage/blobs/)|![支持](https://img.shields.io/badge/support-Yes-green.svg)||
|[Google Cloud](https://cloud.google.com)|[Google Cloud Storage](https://cloud.google.com/storage/)|![支持](https://img.shields.io/badge/support-Yes-green.svg)||

# 支持的数据源
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: 0.0.7.0.{build}
version: 0.0.8.0.{build}
image: Visual Studio 2017
shallow_clone: true
build_script:
Expand Down
17 changes: 17 additions & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
},
"Tips": "name:任务名称;provider:上传服务提供商;path:需要备份的文件夹或文件在本地的路径;crontab:启动备份的时间集合,可以参考http://cron.qqe2.com/,使用时需要注意时区;command:打包备份文件夹或文件之前额外执行的命令,例如备份数据库等,使用docker容器时须注意执行环境,可以为空;commandArgs:打包备份文件夹或文件之前额外执行的命令的参数,,可以为空;uploader:上传设置"
},
{
"name": "上传到 azure",
"provider": "azure",
"path": "/data",
"crontab": [
"0,30 * * * * ?"
],
"command": "echo",
"commandArgs": "Hello World!",
"uploader": {
"connectionString": "connectionStringxxx",
"container": "backup",
"path": "data/some",
"Tips": "connectionString:连接字符串;container:存储容器名;path:文件在Bucket下的路径,作为上传路径前缀"
},
"Tips": "name:任务名称;provider:上传服务提供商;path:需要备份的文件夹或文件在本地的路径;crontab:启动备份的时间集合,可以参考http://cron.qqe2.com/,使用时需要注意时区;command:打包备份文件夹或文件之前额外执行的命令,例如备份数据库等,使用docker容器时须注意执行环境,可以为空;commandArgs:打包备份文件夹或文件之前额外执行的命令的参数,,可以为空;uploader:上传设置"
},
{
"name": "上传到 baidu",
"provider": "baidu",
Expand Down

0 comments on commit b0ad8e4

Please sign in to comment.