Skip to content

Commit

Permalink
丰富eg命令。 fix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjusss committed Dec 24, 2018
1 parent 74d2142 commit 1b7d4b8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
6 changes: 3 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.1.0.0</AssemblyVersion>
<FileVersion>0.1.0.0</FileVersion>
<Version>0.1.0</Version>
<AssemblyVersion>0.2.0.0</AssemblyVersion>
<FileVersion>0.2.0.0</FileVersion>
<Version>0.2.0</Version>
<Authors>sanjusss</Authors>
<Company />
<Description>定时将服务器上的文件备份到云存储。</Description>
Expand Down
5 changes: 3 additions & 2 deletions Backup2Cloud/Conf/ExamplePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;

namespace Backup2Cloud.Conf
{
Expand Down Expand Up @@ -106,14 +107,14 @@ private static string GetExampleConfig(Dictionary<string, Type> uploaders, Dicti

if (uploaders.Count > 0)
{
var i = uploaders.GetEnumerator().Current;
var i = uploaders.First();
single.uploader = (Activator.CreateInstance(i.Value) as IUploader).GetExample() as IUploader;
single.name += i.Key;
}

if (dataSources.Count > 0)
{
var i = dataSources.GetEnumerator().Current;
var i = dataSources.First();
single.dataSource = (Activator.CreateInstance(i.Value) as IDataSource).GetExample() as IDataSource;
}

Expand Down
12 changes: 9 additions & 3 deletions Backup2Cloud/DataSource/FtpDataSource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Backup2Cloud.Conf;
using Backup2Cloud.Logging;
using FluentFTP;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
Expand All @@ -18,7 +19,12 @@ public string Tips
{
get
{
return string.Empty;
return "host:服务器主机名;" +
"port:服务器的FTP端口;" +
"user:用户名;" +
"password:密码;" +
"anonymous:是否使用匿名登陆;" +
"path:在ftp上的路径,可以是文件或文件夹。";
}
}

Expand All @@ -41,7 +47,7 @@ public void SaveData(string des)
client.Connect();
if (client.DirectoryExists(path))
{
int result = DownloadDirectory(path, "/", des, client);
int result = DownloadDirectory(path, "/", FormatDirectoryName(des), client);
Log.Print($"从 ftp://{ host }:{ port }{ path } 成功下载 { result } 个文件到 { des }");
}
else
Expand Down Expand Up @@ -96,7 +102,7 @@ private int DownloadDirectory(string baseSrc, string dir, string des, FtpClient

foreach (var i in dirs)
{
result += DownloadDirectory(baseSrc, dir + i + "/", des + i + "/", client);
result += DownloadDirectory(baseSrc, dir + i + "/", des, client);
}

return result;
Expand Down
11 changes: 10 additions & 1 deletion Backup2Cloud/Uploader/FtpUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

namespace Backup2Cloud.Uploader
{
/// <summary>
/// FTP上传实现类。
/// </summary>
[Name("ftp")]
public class FtpUploader : BaseFtpConf, IUploader
{
public string Tips
{
get
{
return string.Empty;
return "host:服务器主机名;" +
"port:服务器的FTP端口;" +
"user:用户名;" +
"password:密码;" +
"anonymous:是否使用匿名登陆;" +
"path:在ftp上的路径前缀。";
}
}

Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
|[金山云](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-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)||
||FTP|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)||
|自定义|FTP|![支持](https://img.shields.io/badge/support-Yes-green.svg)||

# 支持的数据源

Expand All @@ -41,8 +41,8 @@
|SQL Server|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)|
|Oracle|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)|
|自定义命令|![支持](https://img.shields.io/badge/support-Yes-green.svg)|
|FTP文件|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)|
|FTP文件文件夹|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)|
|FTP文件|![支持](https://img.shields.io/badge/support-Yes-green.svg)|
|FTP文件文件夹|![支持](https://img.shields.io/badge/support-Yes-green.svg)|

# 支持的备份触发方式

Expand All @@ -68,6 +68,7 @@ docker run --rm -v /D/share:/conf sanjusss/backup2cloud eg -s /conf/eg.json
运行后将在D:\share\eg.json生成示例配置文件。
如果省略`-s /conf/eg.json`,将不保存文件,仅在命令行下输出。
实际的配置文件中没有Tips一项。
其他配置参数见[查看示例](https://github.com/sanjusss/backup2cloud#查看示例)

# 使用方法(Windows)
### 下载
Expand All @@ -79,14 +80,36 @@ backup2cloud run -c D:\backup2cloud.json
```
运行后程序将加载配置文件backup2cloud.json。

### 查看示例配置文件
### 查看示例
1. 查看一个示例配置文件
```
backup2cloud eg -s D:\share\eg.json
```
运行后将在D:\share\eg.json生成示例配置文件。
如果省略`-s D:\share\eg.json`,将不保存文件,仅在命令行下输出。
实际的配置文件中没有Tips一项。

2. 查看所有上传类名称
```
backup2cloud eg -l uploader
```

3. 查看所有数据源类名称
```
backup2cloud eg -l datasource
```

4. 查看指定上传类示例
```
backup2cloud eg -u 上传类名称
```

5. 查看指定数据源类示例
```
backup2cloud eg -d 数据源类名称
```


# 配置文件说明
待补充

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.1.0.0.{build}
version: 0.2.0.0.{build}
image: Visual Studio 2017
shallow_clone: true
build_script:
Expand Down

0 comments on commit 1b7d4b8

Please sign in to comment.