├── .gitattributes ├── .gitignore ├── Backup2Cloud ├── Args │ ├── ExampleOptions.cs │ └── NormalOptions.cs ├── Backup2Cloud.csproj ├── Conf │ ├── BaseFtpConf.cs │ ├── ConfigurationConverter.cs │ ├── ExamplePrinter.cs │ ├── IConfigurable.cs │ ├── IExampled.cs │ ├── Loader.cs │ ├── NameAttribute.cs │ ├── NameConverter.cs │ ├── NamedInterfaceLoader.cs │ └── SingleConfiguration.cs ├── DataSource │ ├── CustomDataSource.cs │ ├── FtpDataSource.cs │ └── IDataSource.cs ├── Logging │ └── Log.cs ├── Program.cs ├── Uploader │ ├── AliyunUploader.cs │ ├── AwsUploader.cs │ ├── AzureBlobUploader.cs │ ├── BaiduUploader.cs │ ├── FtpUploader.cs │ ├── GoogleCloudStorageUploader.cs │ ├── HuaweiCloudUploader.cs │ ├── IUploader.cs │ ├── JDCloudUploader.cs │ ├── QCloudUploader.cs │ ├── QingStorUploader.cs │ ├── QiniuUploader.cs │ └── UCloudUploader.cs └── Worker │ ├── BackupWorker.cs │ └── WorkScheduler.cs ├── Dockerfile ├── LICENSE ├── README.md ├── appveyor.yml └── backup2cloud.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | #Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /Backup2Cloud/Args/ExampleOptions.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | 3 | namespace Backup2Cloud.Args 4 | { 5 | [Verb("eg", HelpText = "显示示例配置文件。")] 6 | public class ExampleOptions 7 | { 8 | [Option('s', "save", Required = false, Default = null, HelpText = "示例配置文件保存地址。")] 9 | public string Path { get; set; } 10 | 11 | [Option('l', "list", Required = false, Default = null, HelpText = "获取datasource或uploader的名称。可以为 datasource 或 uploader")] 12 | 13 | public string List { get; set; } 14 | 15 | [Option('d', "datasource", Required = false, Default = null, HelpText = "获取datasource的格式,需填写名称。")] 16 | public string DataSource { get; set; } 17 | 18 | 19 | [Option('u', "uploader", Required = false, Default = null, HelpText = "获取uploader的格式,需填写名称。")] 20 | public string Uploader { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Backup2Cloud/Args/NormalOptions.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | 3 | namespace Backup2Cloud.Args 4 | { 5 | [Verb("run", HelpText = "载入并运行配置。")] 6 | public class NormalOptions 7 | { 8 | [Option('c', "conf", Required = true, HelpText = "设置配置文件地址。")] 9 | public string Conf { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Backup2Cloud/Backup2Cloud.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | false 7 | 8 | 0.2.0.0 9 | 0.2.0.0 10 | 0.2.0 11 | sanjusss 12 | 13 | 定时将服务器上的文件备份到云存储。 14 | https://github.com/sanjusss/backup2cloud/blob/master/LICENSE 15 | https://github.com/sanjusss/backup2cloud 16 | https://github.com/sanjusss/backup2cloud 17 | git 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/BaseFtpConf.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Backup2Cloud.Conf 6 | { 7 | /// 8 | /// FTP基本配置。 9 | /// 10 | public abstract class BaseFtpConf 11 | { 12 | /// 13 | /// 服务器主机名。 14 | /// 默认为本机。 15 | /// 16 | public string host { get; set; } = "localhost"; 17 | 18 | /// 19 | /// 服务器的FTP端口。 20 | /// 默认为21。 21 | /// 22 | public int port { get; set; } = 21; 23 | 24 | /// 25 | /// 用户名。 26 | /// 默认为anonymous。 27 | /// 28 | public string user { get; set; } = "anonymous"; 29 | 30 | /// 31 | /// 密码。 32 | /// 33 | public string password { get; set; } = string.Empty; 34 | 35 | /// 36 | /// 是否使用匿名登陆。 37 | /// 默认为false。 38 | /// 39 | public bool anonymous { get; set; } = false; 40 | 41 | /// 42 | /// 在ftp上的路径。 43 | /// 44 | public string path { get; set; } = "/"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/ConfigurationConverter.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.DataSource; 2 | using Backup2Cloud.Uploader; 3 | using Newtonsoft.Json; 4 | using Newtonsoft.Json.Linq; 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | namespace Backup2Cloud.Conf 9 | { 10 | /// 11 | /// 将Json转为SingleConfiguration类型的转换器。 12 | /// 自动实例化uploader。 13 | /// 14 | public class ConfigurationConverter : JsonConverter 15 | { 16 | /// 17 | /// 所有支持的dataSource类型。 18 | /// key表示上传服务提供商。 19 | /// 20 | private readonly Dictionary _supportDataSourceTypes = null; 21 | /// 22 | /// 所有支持的uploader类型。 23 | /// key表示上传服务提供商。 24 | /// 25 | private readonly Dictionary _supportUploaderTypes = null; 26 | /// 27 | /// 初始化 28 | /// 29 | public ConfigurationConverter() 30 | { 31 | _supportDataSourceTypes = NamedInterfaceLoader.Load(typeof(IDataSource)); 32 | _supportUploaderTypes = NamedInterfaceLoader.Load(typeof(IUploader)); 33 | } 34 | 35 | /// 36 | /// 禁止写操作。 37 | /// 38 | public override bool CanWrite => false; 39 | 40 | /// 41 | /// 判断是否可以进行类型转换。 42 | /// 43 | /// 目标类型 44 | /// 是否可以进行类型转换 45 | public override bool CanConvert(Type objectType) 46 | { 47 | return objectType == typeof(SingleConfiguration); 48 | } 49 | 50 | /// 51 | /// 将Json转为SingleConfiguration类型。 52 | /// 53 | /// Json读取器 54 | /// 目标类型 55 | /// 已存在的值 56 | /// 序列化生成器 57 | /// SingleConfiguration实例 58 | /// 59 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 60 | { 61 | var jsonObject = JObject.Load(reader); 62 | SingleConfiguration target = new SingleConfiguration() 63 | { 64 | name = jsonObject["name"].ToString(), 65 | path = jsonObject["path"].ToString(), 66 | crontab = jsonObject["crontab"].ToObject>() 67 | }; 68 | 69 | var dataSource = jsonObject["dataSource"]; 70 | if (dataSource.Type != JTokenType.Null) 71 | { 72 | string dsName = dataSource["name"].ToString(); 73 | if (_supportDataSourceTypes.ContainsKey(dsName)) 74 | { 75 | target.dataSource = jsonObject["dataSource"].ToObject(_supportDataSourceTypes[dsName]) as IDataSource; 76 | } 77 | else 78 | { 79 | throw new InvalidCastException(string.Format("没有找到\"{0}\"的数据源实现。", dsName)); 80 | } 81 | } 82 | 83 | var uploader = jsonObject["uploader"]; 84 | string uploaderName = uploader["name"].ToString(); 85 | if (_supportUploaderTypes.ContainsKey(uploaderName)) 86 | { 87 | target.uploader = jsonObject["uploader"].ToObject(_supportUploaderTypes[uploaderName]) as IUploader; 88 | } 89 | else 90 | { 91 | throw new InvalidCastException(string.Format("没有找到\"{0}\"的上传实现。", uploaderName)); 92 | } 93 | 94 | return target; 95 | } 96 | 97 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 98 | { 99 | throw new NotImplementedException(); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/ExamplePrinter.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Args; 2 | using Backup2Cloud.DataSource; 3 | using Backup2Cloud.Logging; 4 | using Backup2Cloud.Uploader; 5 | using Newtonsoft.Json; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IO; 9 | using System.Text; 10 | using System.Linq; 11 | 12 | namespace Backup2Cloud.Conf 13 | { 14 | /// 15 | /// 示例打印类。 16 | /// 17 | public class ExamplePrinter 18 | { 19 | /// 20 | /// 根据命令行参数打印示例。 21 | /// 22 | /// 命令行参数 23 | public static void Print(ExampleOptions options) 24 | { 25 | var uploaders = NamedInterfaceLoader.Load(typeof(IUploader)); 26 | var dataSources = NamedInterfaceLoader.Load(typeof(IDataSource)); 27 | string content = string.Empty; 28 | if (string.IsNullOrEmpty(options.List) == false) 29 | { 30 | if (options.List == "datasource") 31 | { 32 | content = string.Join('\n', dataSources.Keys); 33 | Console.WriteLine("已支持以下数据源:"); 34 | } 35 | else if (options.List == "uploader") 36 | { 37 | content = string.Join('\n', uploaders.Keys); 38 | Console.WriteLine("已支持以下上传类:"); 39 | } 40 | else 41 | { 42 | Console.WriteLine("只能列出 datasource 或 uploader"); 43 | } 44 | } 45 | else if (string.IsNullOrEmpty(options.Uploader) == false) 46 | { 47 | if (uploaders.ContainsKey(options.Uploader)) 48 | { 49 | content = JsonConvert.SerializeObject((Activator.CreateInstance(uploaders[options.Uploader]) as IExampled).GetExample(), 50 | Formatting.Indented, 51 | new NameConverter()); 52 | } 53 | else 54 | { 55 | Console.WriteLine($"不存在uploader类: { options.Uploader }"); 56 | } 57 | } 58 | else if (string.IsNullOrEmpty(options.DataSource) == false) 59 | { 60 | if (dataSources.ContainsKey(options.DataSource)) 61 | { 62 | content = JsonConvert.SerializeObject((Activator.CreateInstance(dataSources[options.DataSource]) as IExampled).GetExample(), 63 | Formatting.Indented, 64 | new NameConverter()); 65 | } 66 | else 67 | { 68 | Console.WriteLine($"不存在datasource类: { options.DataSource }"); 69 | } 70 | } 71 | else 72 | { 73 | content = GetExampleConfig(uploaders, dataSources); 74 | } 75 | 76 | if (string.IsNullOrEmpty(content) == false) 77 | { 78 | Console.WriteLine(content); 79 | if (string.IsNullOrEmpty(options.Path) == false) 80 | { 81 | //保存到文件。 82 | using (StreamWriter stream = new StreamWriter(options.Path, false, Encoding.UTF8)) 83 | { 84 | stream.Write(content); 85 | } 86 | 87 | Console.WriteLine("\n\n"); 88 | Log.Info(string.Format("文件已经保存到\"{0}\"。", options.Path)); 89 | } 90 | } 91 | 92 | #if !DEBUG 93 | Environment.Exit(0); 94 | #endif 95 | } 96 | 97 | private static string GetExampleConfig(Dictionary uploaders, Dictionary dataSources) 98 | { 99 | string[] crontab = { "0,30 * * * * ?" }; 100 | List configurations = new List(); 101 | SingleConfiguration single = new SingleConfiguration() 102 | { 103 | name = "上传到 ", 104 | path = "/data", 105 | crontab = new HashSet(crontab) 106 | }; 107 | 108 | if (uploaders.Count > 0) 109 | { 110 | var i = uploaders.First(); 111 | single.uploader = (Activator.CreateInstance(i.Value) as IUploader).GetExample() as IUploader; 112 | single.name += i.Key; 113 | } 114 | 115 | if (dataSources.Count > 0) 116 | { 117 | var i = dataSources.First(); 118 | single.dataSource = (Activator.CreateInstance(i.Value) as IDataSource).GetExample() as IDataSource; 119 | } 120 | 121 | configurations.Add(single); 122 | return JsonConvert.SerializeObject(configurations, Formatting.Indented, new NameConverter()); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/IConfigurable.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Backup2Cloud.Conf 4 | { 5 | /// 6 | /// 表明可以由用户配置的结构/类的接口。 7 | /// 8 | public interface IConfigurable 9 | { 10 | /// 11 | /// 提示信息 12 | /// 13 | [JsonProperty("tips")] 14 | string Tips { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/IExampled.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Backup2Cloud.Conf 6 | { 7 | /// 8 | /// 举例接口。 9 | /// 10 | public interface IExampled 11 | { 12 | /// 13 | /// 获取示例配置。 14 | /// 15 | /// 示例的配置 16 | object GetExample(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/Loader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Args; 2 | using Backup2Cloud.Logging; 3 | using Backup2Cloud.Worker; 4 | using Newtonsoft.Json; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Text; 9 | using System.Threading; 10 | 11 | namespace Backup2Cloud.Conf 12 | { 13 | /// 14 | /// 配置加载器 15 | /// 16 | public static class Loader 17 | { 18 | /// 19 | /// 载入设置 20 | /// 21 | /// 相关设置 22 | public static void Load(NormalOptions options) 23 | { 24 | if (File.Exists(options.Conf) == false) 25 | { 26 | Log.Warn(string.Format("没有找到配置文件\"{0}\"!", options.Conf)); 27 | Environment.Exit(1); 28 | return; 29 | } 30 | 31 | string content; 32 | using (StreamReader reader = new StreamReader(options.Conf, Encoding.UTF8)) 33 | { 34 | content = reader.ReadToEnd(); 35 | } 36 | 37 | Log.Info("成功获取配置文件,正在加载……"); 38 | List configurations = JsonConvert.DeserializeObject>(content, new ConfigurationConverter()); 39 | Log.Info(string.Format("成功加载配置文件,共有{0}条配置。", configurations.Count)); 40 | if (configurations.Count == 0) 41 | { 42 | Environment.Exit(0); 43 | } 44 | 45 | WorkScheduler scheduler = new WorkScheduler(); 46 | foreach (var i in configurations) 47 | { 48 | scheduler.StartWork(i); 49 | Log.Info(string.Format("成功启动任务\"{0}\"。", i.name)); 50 | } 51 | 52 | Log.Info("成功启动所有备份任务。"); 53 | #if !DEBUG 54 | Thread.Sleep(Timeout.Infinite);//加载完成后主线程休眠。 55 | #endif 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/NameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Backup2Cloud.Conf 4 | { 5 | /// 6 | /// 名称特性。 7 | /// 8 | public class NameAttribute : Attribute 9 | { 10 | /// 11 | /// 名称 12 | /// 13 | private readonly string _name; 14 | 15 | /// 16 | /// 名称 17 | /// 18 | public string Name 19 | { 20 | get 21 | { 22 | return _name; 23 | } 24 | } 25 | 26 | /// 27 | /// 定义名称。 28 | /// 29 | /// 名称 30 | public NameAttribute(string name) 31 | { 32 | _name = name; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/NameConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Backup2Cloud.Conf 8 | { 9 | /// 10 | /// 转换所有有NameAttribute特性的对象为Json字符串。 11 | /// 12 | public class NameConverter : JsonConverter 13 | { 14 | /// 15 | /// 禁止读操作。 16 | /// 17 | public override bool CanRead => false; 18 | 19 | /// 20 | /// 判断是否可以进行类型转换。 21 | /// 22 | /// 目标类型 23 | /// 是否可以进行类型转换 24 | public override bool CanConvert(Type objectType) 25 | { 26 | return objectType.GetCustomAttributes(typeof(NameAttribute), true).Length == 1; 27 | } 28 | 29 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 30 | { 31 | throw new NotImplementedException(); 32 | } 33 | 34 | /// 35 | /// 为对象增加name属性。 36 | /// 37 | /// Json写入器 38 | /// 对象实例 39 | /// 序列化方式 40 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 41 | { 42 | var obj = JObject.FromObject(value); 43 | if (obj.Type == JTokenType.Object) 44 | { 45 | Type type = value.GetType(); 46 | var attrs = type.GetCustomAttributes(typeof(NameAttribute), true); 47 | if (attrs.Length != 1) 48 | { 49 | throw new InvalidCastException(string.Format("{0}不包含唯一特性{1}", type, typeof(NameAttribute))); 50 | } 51 | 52 | var attr = attrs[0] as NameAttribute; 53 | obj.AddFirst(new JProperty("name", attr.Name)); 54 | } 55 | 56 | obj.WriteTo(writer); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/NamedInterfaceLoader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Logging; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Backup2Cloud.Conf 7 | { 8 | /// 9 | /// 已命名的接口实现类的载入类。 10 | /// 11 | public static class NamedInterfaceLoader 12 | { 13 | /// 14 | /// 遍历所有上传接口的实现类,返回集合。 15 | /// 16 | /// 返回上传接口实现类的集合。key是上传服务的提供商名称,value是上传接口的实现类类型。 17 | public static Dictionary Load(Type targetInterface) 18 | { 19 | Dictionary supportTypes = new Dictionary(); 20 | 21 | var assemblies = AppDomain.CurrentDomain.GetAssemblies(); 22 | foreach (var assembly in assemblies) 23 | { 24 | var types = assembly.GetTypes(); 25 | foreach (var type in types) 26 | { 27 | try 28 | { 29 | if (type.IsClass == false || 30 | type.IsAbstract || 31 | targetInterface.IsAssignableFrom(type) == false) 32 | { 33 | continue; 34 | } 35 | 36 | var attrs = type.GetCustomAttributes(typeof(NameAttribute), true); 37 | if (attrs.Length == 0) 38 | { 39 | Log.Debug(string.Format("类{0}没有定义{1}特性,跳过。", type.ToString(), typeof(NameAttribute).ToString())); 40 | continue; 41 | } 42 | 43 | if (attrs.Length > 1) 44 | { 45 | Log.Warn(string.Format("类{0}定义了多个{1}特性,只取第一个。", type.ToString(), typeof(NameAttribute).ToString())); 46 | } 47 | 48 | var attr = attrs[0] as NameAttribute; 49 | if (supportTypes.ContainsKey(attr.Name)) 50 | { 51 | Log.Warn(string.Format("类{0}的命名与{1}相同,{0}将被跳过。", type.ToString(), supportTypes[attr.Name].ToString())); 52 | continue; 53 | } 54 | else 55 | { 56 | supportTypes[attr.Name] = type; 57 | Log.Info(string.Format("初始化类{0}({1})完成。", type.ToString(), attr.Name)); 58 | } 59 | } 60 | catch (Exception e) 61 | { 62 | Log.Error(string.Format("反射类{0}时出现错误,跳过。", type.ToString())); 63 | Log.Error(e.ToString()); 64 | } 65 | } 66 | } 67 | 68 | return supportTypes; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Backup2Cloud/Conf/SingleConfiguration.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.DataSource; 2 | using Backup2Cloud.Uploader; 3 | using System.Collections.Generic; 4 | 5 | namespace Backup2Cloud.Conf 6 | { 7 | /// 8 | /// 单条备份配置 9 | /// 10 | public class SingleConfiguration : IConfigurable 11 | { 12 | /// 13 | /// 任务名称 14 | /// 15 | public string name; 16 | 17 | /// 18 | /// 需要备份的文件夹或文件路径 19 | /// 20 | public string path; 21 | 22 | /// 23 | /// 备份开始时间 24 | /// 25 | public HashSet crontab; 26 | 27 | /// 28 | /// 数据源。 29 | /// 用来将数据保存到path。 30 | /// 31 | public IDataSource dataSource; 32 | 33 | /// 34 | /// 上传设置 35 | /// 36 | public IUploader uploader; 37 | 38 | /// 39 | /// 提示信息 40 | /// 41 | public string Tips 42 | { 43 | get 44 | { 45 | return "name:任务名称;" + 46 | "path:需要备份的文件夹或文件在本地的路径;" + 47 | "crontab:启动备份的时间集合,可以参考http://cron.qqe2.com/,使用时需要注意时区;" + 48 | "dataSource:数据源,可以为空;" + 49 | "uploader:上传设置"; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Backup2Cloud/DataSource/CustomDataSource.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Backup2Cloud.Logging; 3 | using Newtonsoft.Json; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Text; 8 | 9 | namespace Backup2Cloud.DataSource 10 | { 11 | /// 12 | /// 自定义数据源。 13 | /// 14 | [Name("custom")] 15 | public class CustomDataSource : IDataSource 16 | { 17 | /// 18 | /// 自定义命令。 19 | /// 20 | [JsonProperty("command")] 21 | public virtual string Command { get; set; } 22 | /// 23 | /// 自定义命令参数。 24 | /// 可以为空。 25 | /// 26 | [JsonProperty("params")] 27 | public virtual string Params { get; set; } 28 | 29 | /// 30 | /// 数据源提示信息。 31 | /// 32 | public virtual string Tips 33 | { 34 | get 35 | { 36 | return "command:自定义命令;" + 37 | "params:自定义命令参数,可以为空。如果包含\"{0}\"(没有空格),将用配置文件的path替代。"; 38 | } 39 | } 40 | 41 | /// 42 | /// 获取示例。 43 | /// 44 | /// 示例 45 | public virtual object GetExample() 46 | { 47 | return new CustomDataSource() 48 | { 49 | Command = "echo", 50 | Params = "Hello" 51 | }; 52 | } 53 | 54 | /// 55 | /// 运行自定义命令。 56 | /// 57 | /// 58 | public void SaveData(string des) 59 | { 60 | Process process = string.IsNullOrWhiteSpace(Params) ? 61 | Process.Start(Command) : 62 | Process.Start(Command, Params.Contains("{0}") ? string.Format(Params, des) : Params); 63 | #if DEBUG 64 | process.OutputDataReceived += (sender, e) => Log.Info(e.Data); 65 | process.BeginOutputReadLine(); 66 | #endif 67 | process.WaitForExit(); 68 | if (process.ExitCode == 0) 69 | { 70 | throw new OperationCanceledException(string.Format("自定义命令返回了错误码 {0}。", process.ExitCode)); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Backup2Cloud/DataSource/FtpDataSource.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Backup2Cloud.Logging; 3 | using FluentFTP; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Net; 8 | using System.Text; 9 | 10 | namespace Backup2Cloud.DataSource 11 | { 12 | /// 13 | /// FTP数据源。从远端FTP获取数据。 14 | /// 15 | [Name("ftp")] 16 | public class FtpDataSource : BaseFtpConf, IDataSource 17 | { 18 | public string Tips 19 | { 20 | get 21 | { 22 | return "host:服务器主机名;" + 23 | "port:服务器的FTP端口;" + 24 | "user:用户名;" + 25 | "password:密码;" + 26 | "anonymous:是否使用匿名登陆;" + 27 | "path:在ftp上的路径,可以是文件或文件夹。"; 28 | } 29 | } 30 | 31 | public object GetExample() 32 | { 33 | return new FtpDataSource(); 34 | } 35 | 36 | public void SaveData(string des) 37 | { 38 | using (FtpClient client = new FtpClient(host)) 39 | { 40 | client.Port = port; 41 | client.Encoding = Encoding.UTF8; 42 | if (anonymous == false) 43 | { 44 | client.Credentials = new NetworkCredential(user, password); 45 | } 46 | 47 | client.Connect(); 48 | if (client.DirectoryExists(path)) 49 | { 50 | int result = DownloadDirectory(path, "/", FormatDirectoryName(des), client); 51 | Log.Print($"从 ftp://{ host }:{ port }{ path } 成功下载 { result } 个文件到 { des } 。"); 52 | } 53 | else 54 | { 55 | if (client.DownloadFile(des, path) == false) 56 | { 57 | throw new IOException($"下载 ftp://{ host }:{ port }{ path } 失败。"); 58 | } 59 | 60 | Log.Print($"成功下载 ftp://{ host }:{ port }{ path } 到 { des } 。"); 61 | } 62 | 63 | client.Disconnect(); 64 | } 65 | } 66 | 67 | private int DownloadDirectory(string baseSrc, string dir, string des, FtpClient client) 68 | { 69 | string target = FormatDirectoryName(des + dir); 70 | if (Directory.Exists(target)) 71 | { 72 | Directory.Delete(target, true); 73 | } 74 | 75 | Directory.CreateDirectory(target); 76 | var list = client.GetListing(FormatDirectoryName(baseSrc + dir)); 77 | List dirs = new List(); 78 | int result = 0; 79 | foreach (var i in list) 80 | { 81 | switch (i.Type) 82 | { 83 | case FtpFileSystemObjectType.File: 84 | if (client.DownloadFile(target + i.Name, i.FullName)) 85 | { 86 | ++result; 87 | } 88 | 89 | break; 90 | 91 | case FtpFileSystemObjectType.Directory: 92 | dirs.Add(i.Name); 93 | break; 94 | 95 | case FtpFileSystemObjectType.Link: 96 | break; 97 | 98 | default: 99 | break; 100 | } 101 | } 102 | 103 | foreach (var i in dirs) 104 | { 105 | result += DownloadDirectory(baseSrc, dir + i + "/", des, client); 106 | } 107 | 108 | return result; 109 | } 110 | 111 | private string FormatDirectoryName(string name) 112 | { 113 | name = name.Replace("\\", "/"); 114 | name = name.Replace("//", "/"); 115 | if (name.EndsWith("/") == false) 116 | { 117 | name += "/"; 118 | } 119 | 120 | return name; 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Backup2Cloud/DataSource/IDataSource.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | 3 | namespace Backup2Cloud.DataSource 4 | { 5 | /// 6 | /// 数据源接口,实现此接口需要同时引用NameAttribute表明数据源类型。 7 | /// 8 | public interface IDataSource : IConfigurable, IExampled 9 | { 10 | /// 11 | /// 保存数据。 12 | /// 13 | /// 保存的路径 14 | void SaveData(string des); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Backup2Cloud/Logging/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Backup2Cloud.Logging 4 | { 5 | /// 6 | /// 日志打印类 7 | /// 8 | public static class Log 9 | { 10 | /// 11 | /// 打印DEBUG类型日志 12 | /// 13 | /// 日志消息 14 | /// 模块 15 | public static void Debug(string msg, string module = null) 16 | { 17 | msg = "[DEBUG]" + msg; 18 | if (string.IsNullOrWhiteSpace(module) == false) 19 | { 20 | msg = "[" + module + "]" + msg; 21 | } 22 | 23 | Print(msg); 24 | } 25 | 26 | /// 27 | /// 打印INFO类型日志 28 | /// 29 | /// 日志消息 30 | /// 模块 31 | public static void Info(string msg, string module = null) 32 | { 33 | msg = "[INFO]" + msg; 34 | if (string.IsNullOrWhiteSpace(module) == false) 35 | { 36 | msg = "[" + module + "]" + msg; 37 | } 38 | 39 | Print(msg); 40 | } 41 | 42 | /// 43 | /// 打印WARN类型日志 44 | /// 45 | /// 日志消息 46 | /// 模块 47 | public static void Warn(string msg, string module = null) 48 | { 49 | msg = "[WARN]" + msg; 50 | if (string.IsNullOrWhiteSpace(module) == false) 51 | { 52 | msg = "[" + module + "]" + msg; 53 | } 54 | 55 | Print(msg); 56 | } 57 | 58 | /// 59 | /// 打印ERROR类型日志 60 | /// 61 | /// 日志消息 62 | /// 模块 63 | public static void Error(string msg, string module = null) 64 | { 65 | msg = "[ERROR]" + msg; 66 | if (string.IsNullOrWhiteSpace(module) == false) 67 | { 68 | msg = "[" + module + "]" + msg; 69 | } 70 | 71 | Print(msg); 72 | } 73 | 74 | /// 75 | /// 打印FATAL类型日志 76 | /// 77 | /// 日志消息 78 | /// 模块 79 | public static void Fatal(string msg, string module = null) 80 | { 81 | msg = "[FATAL]" + msg; 82 | if (string.IsNullOrWhiteSpace(module) == false) 83 | { 84 | msg = "[" + module + "]" + msg; 85 | } 86 | 87 | Print(msg); 88 | } 89 | 90 | /// 91 | /// 打印日志。 92 | /// 93 | /// 日志消息 94 | public static void Print(string msg) 95 | { 96 | string prefix = string.Format("[{0}]", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff zz")); 97 | Console.WriteLine(prefix + msg); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Backup2Cloud/Program.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Args; 2 | using Backup2Cloud.Conf; 3 | using Backup2Cloud.Logging; 4 | using CommandLine; 5 | using System; 6 | 7 | namespace Backup2Cloud 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | #if !DEBUG 14 | try 15 | { 16 | #endif 17 | //防止docker下Console.WindowWidth为0,避免命令行解析时崩溃。 18 | if (Console.WindowWidth <= 10) 19 | { 20 | Parser.Default.Settings.MaximumDisplayWidth = 80; 21 | } 22 | 23 | //解析命令行 24 | Parser.Default.ParseArguments(args) 25 | .WithParsed(ExamplePrinter.Print) 26 | .WithParsed(Loader.Load); 27 | #if !DEBUG 28 | } 29 | catch (Exception e) 30 | { 31 | Log.Fatal(e.ToString()); 32 | Environment.Exit(1); 33 | } 34 | #endif 35 | #if DEBUG 36 | Console.Read(); 37 | #endif 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/AliyunUploader.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.OSS; 2 | using Aliyun.OSS.Common; 3 | using Backup2Cloud.Conf; 4 | using System; 5 | using System.Threading.Tasks; 6 | 7 | namespace Backup2Cloud.Uploader 8 | { 9 | /// 10 | /// 阿里云上传实现类。 11 | /// 12 | [Name("aliyun")] 13 | public class AliyunUploader : IUploader 14 | { 15 | /// 16 | /// 访问域名(可以在控制台查看) 17 | /// 18 | public string endpoint; 19 | /// 20 | /// 阿里云AccessKeyId 21 | /// 22 | public string id; 23 | /// 24 | /// 阿里云AccessKeySecret 25 | /// 26 | public string secret; 27 | /// 28 | /// 存储空间名 29 | /// 30 | public string bucket; 31 | /// 32 | /// 文件在存储空间下的路径,作为上传路径前缀。 33 | /// 34 | public string path; 35 | /// 36 | /// 上传超时时间,单位毫秒。小于等于0时表示不超时。 37 | /// 38 | public int timeout = 0; 39 | /// 40 | /// 提示信息 41 | /// 42 | public string Tips 43 | { 44 | get 45 | { 46 | return "endpoint:地域节点(可以在控制台查看);" + 47 | "id:阿里云AccessKeyId(可以在控制台查看);" + 48 | "secret:阿里云AccessKeySecret(可以在控制台查看);" + 49 | "bucket:存储空间名" + 50 | "path:文件在存储空间下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件;" + 51 | "timeout:上传超时时间,单位毫秒,可以不设置"; 52 | } 53 | } 54 | 55 | /// 56 | /// 获取阿里云示例实例。 57 | /// 58 | /// 阿里云示例配置实例 59 | public object GetExample() 60 | { 61 | return new AliyunUploader() 62 | { 63 | endpoint = "oss-cn-hangzhou.aliyuncs.com", 64 | id = "阿里云AccessKeyId", 65 | secret = "阿里云AccessKeySecret", 66 | bucket = "backup", 67 | path = "data/some", 68 | timeout = 200000 69 | }; 70 | } 71 | 72 | /// 73 | /// 上传指定文件到阿里云OSS。 74 | /// 75 | /// 待上传的文件 76 | /// 文件在云空间里的后缀 77 | /// 78 | public Task Upload(string file, string suffix) 79 | { 80 | OssClient client; 81 | if (timeout > 0) 82 | { 83 | var clientconf = new ClientConfiguration(); 84 | clientconf.ConnectionTimeout = 20000; 85 | client = new OssClient(endpoint, id, secret, clientconf); 86 | } 87 | else 88 | { 89 | client = new OssClient(endpoint, id, secret); 90 | } 91 | 92 | client.PutObject(bucket, path + suffix, file); 93 | return Task.CompletedTask; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/AwsUploader.cs: -------------------------------------------------------------------------------- 1 | using Amazon; 2 | using Amazon.S3; 3 | using Amazon.S3.Model; 4 | using Backup2Cloud.Conf; 5 | using System; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | 9 | namespace Backup2Cloud.Uploader 10 | { 11 | /// 12 | /// AWS S3上传实现类。 13 | /// 14 | [Name("aws")] 15 | public class AwsUploader : IUploader 16 | { 17 | /// 18 | /// 区域的系统名 19 | /// 20 | public string regionSystemName; 21 | /// 22 | /// AWS Access Key ID 23 | /// 24 | public string awsAccessKeyId; 25 | /// 26 | /// AWS Secret Access Key 27 | /// 28 | public string awsSecretAccessKey; 29 | /// 30 | /// AWS S3 Bucket/桶 31 | /// 32 | public string bucket; 33 | /// 34 | /// 文件在Bucket下的路径,作为上传路径前缀。 35 | /// 36 | public string path; 37 | /// 38 | /// 提示信息 39 | /// 40 | public string Tips 41 | { 42 | get 43 | { 44 | return "regionSystemName:区域的系统名,例如 us-west-1" + 45 | "awsAccessKeyId:AWS Access Key ID;" + 46 | "awsSecretAccessKey:AWS Secret Access Key;" + 47 | "bucket:Bucket/桶;" + 48 | "path:文件在Bucket/桶下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件"; 49 | } 50 | } 51 | /// 52 | /// 获取示例实例。 53 | /// 54 | /// 示例配置实例 55 | public object GetExample() 56 | { 57 | return new AwsUploader() 58 | { 59 | regionSystemName = "us-west-1", 60 | awsAccessKeyId = "xxxx", 61 | awsSecretAccessKey = "yyy", 62 | bucket = "backup", 63 | path = "data/file" 64 | }; 65 | } 66 | 67 | /// 68 | /// 上传指定文件。 69 | /// 70 | /// 待上传的文件 71 | /// 文件在云空间里的后缀 72 | /// 73 | public async Task Upload(string file, string suffix) 74 | { 75 | var region = RegionEndpoint.GetBySystemName(regionSystemName); 76 | using (FileStream stream = new FileStream(file, FileMode.Open)) 77 | { 78 | using (AmazonS3Client client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, region)) 79 | { 80 | PutObjectRequest request = new PutObjectRequest() 81 | { 82 | BucketName = bucket, 83 | Key = path + suffix, 84 | InputStream = stream 85 | }; 86 | 87 | await client.PutObjectAsync(request); 88 | } 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/AzureBlobUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Microsoft.WindowsAzure.Storage; 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | namespace Backup2Cloud.Uploader 7 | { 8 | /// 9 | /// Azure Blob上传实现类。 10 | /// 11 | [Name("azure")] 12 | public class AzureBlobUploader : IUploader 13 | { 14 | /// 15 | /// 连接字符串 16 | /// 17 | public string connectionString; 18 | /// 19 | /// 存储容器名 20 | /// 21 | public string container; 22 | /// 23 | /// 文件在Bucket下的路径,作为上传路径前缀。 24 | /// 25 | public string path; 26 | /// 27 | /// 提示信息 28 | /// 29 | public string Tips 30 | { 31 | get 32 | { 33 | return "connectionString:连接字符串;" + 34 | "container:存储容器名;" + 35 | "path:文件在Bucket下的路径,作为上传路径前缀"; 36 | } 37 | } 38 | 39 | /// 40 | /// 获取示例实例。 41 | /// 42 | /// 示例配置实例 43 | public object GetExample() 44 | { 45 | return new AzureBlobUploader() 46 | { 47 | connectionString = "connectionStringxxx", 48 | container = "backup", 49 | path = "data/some" 50 | }; 51 | } 52 | 53 | /// 54 | /// 上传指定文件。 55 | /// 56 | /// 待上传的文件 57 | /// 文件在云空间里的后缀 58 | /// 59 | public async Task Upload(string file, string suffix) 60 | { 61 | var account = CloudStorageAccount.Parse(connectionString); 62 | var client = account.CreateCloudBlobClient(); 63 | var rc = client.GetContainerReference(container); 64 | var blob = rc.GetBlockBlobReference(path + suffix); 65 | await blob.UploadFromFileAsync(file); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/BaiduUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using BaiduBce; 3 | using BaiduBce.Auth; 4 | using BaiduBce.Services.Bos; 5 | using System; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | 9 | namespace Backup2Cloud.Uploader 10 | { 11 | /// 12 | /// 百度云上传实现类。 13 | /// 14 | [Name("baidu")] 15 | public class BaiduUploader : IUploader 16 | { 17 | /// 18 | /// 访问域名(可以在控制台查看) 19 | /// 20 | public string endpoint; 21 | /// 22 | /// 百度云AccessKeyId 23 | /// 24 | public string id; 25 | /// 26 | /// 百度云AccessKeySecret 27 | /// 28 | public string key; 29 | /// 30 | /// 存储空间名 31 | /// 32 | public string bucket; 33 | /// 34 | /// 文件在存储空间下的路径,作为上传路径前缀。 35 | /// 36 | public string path; 37 | /// 38 | /// 上传超时时间,单位毫秒。小于等于0时表示不超时。 39 | /// 40 | public int timeout = 0; 41 | /// 42 | /// 提示信息 43 | /// 44 | public string Tips 45 | { 46 | get 47 | { 48 | return "endpoint:地域节点北京区域:https://bj.bcebos.com ,广州区域:https://gz.bcebos.com, 苏州区域:https://su.bcebos.com (可以在控制台查看);" + 49 | "id:百度云AccessKeyId(可以在控制台查看);" + 50 | "secret:百度云SecretAccessKey(可以在控制台查看);" + 51 | "bucket:存储空间名" + 52 | "path:文件在存储空间下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件;" + 53 | "timeout:上传超时时间,单位毫秒"; 54 | } 55 | } 56 | /// 57 | /// 获取百度云示例实例。 58 | /// 59 | /// 百度云示例配置实例 60 | public object GetExample() 61 | { 62 | return new BaiduUploader() 63 | { 64 | endpoint = "https://su.bcebos.com", 65 | id = "百度云AccessKeyId", 66 | key = "百度云SecretAccessKey", 67 | bucket = "backup", 68 | path = "data/some", 69 | timeout = 200000 70 | }; 71 | } 72 | 73 | /// 74 | /// 上传指定文件到百度云BOS。 75 | /// 76 | /// 待上传的文件 77 | /// 文件在云空间里的后缀 78 | /// 79 | public Task Upload(string file, string suffix) 80 | { 81 | BceClientConfiguration config = new BceClientConfiguration(); 82 | config.Credentials = new DefaultBceCredentials(id, key); 83 | config.Endpoint = endpoint; 84 | if (timeout > 0) 85 | { 86 | config.ReadWriteTimeoutInMillis = timeout; 87 | } 88 | 89 | BosClient client = new BosClient(config); 90 | client.PutObject(bucket, path + suffix, new FileInfo(file)); 91 | return Task.CompletedTask; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/FtpUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using FluentFTP; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Net; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Backup2Cloud.Uploader 11 | { 12 | /// 13 | /// FTP上传实现类。 14 | /// 15 | [Name("ftp")] 16 | public class FtpUploader : BaseFtpConf, IUploader 17 | { 18 | public string Tips 19 | { 20 | get 21 | { 22 | return "host:服务器主机名;" + 23 | "port:服务器的FTP端口;" + 24 | "user:用户名;" + 25 | "password:密码;" + 26 | "anonymous:是否使用匿名登陆;" + 27 | "path:在ftp上的路径前缀。"; 28 | } 29 | } 30 | 31 | public object GetExample() 32 | { 33 | return new FtpUploader(); 34 | } 35 | 36 | public Task Upload(string file, string suffix) 37 | { 38 | using (FtpClient client = new FtpClient(host)) 39 | { 40 | client.Port = port; 41 | client.Encoding = Encoding.UTF8; 42 | if (anonymous == false) 43 | { 44 | client.Credentials = new NetworkCredential(user, password); 45 | } 46 | 47 | client.Connect(); 48 | if (client.UploadFile(file, path + suffix) == false) 49 | { 50 | throw new IOException($"上传 ftp://{ host }:{ port }{ path }{ suffix } 失败。"); 51 | } 52 | 53 | client.Disconnect(); 54 | } 55 | 56 | return Task.CompletedTask; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/GoogleCloudStorageUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Google.Apis.Auth.OAuth2; 3 | using Google.Cloud.Storage.V1; 4 | using System; 5 | using System.IO; 6 | using System.Threading.Tasks; 7 | 8 | namespace Backup2Cloud.Uploader 9 | { 10 | /// 11 | /// 谷歌云存储上传实现类 12 | /// 13 | [Name("google")] 14 | public class GoogleCloudStorageUploader : IUploader 15 | { 16 | /// 17 | /// 服务账号密钥文件位置 18 | /// 19 | public string jsonKeyFile; 20 | /// 21 | /// 存储空间名 22 | /// 23 | public string bucket; 24 | /// 25 | /// 文件在Bucket下的路径,作为上传路径前缀。 26 | /// 27 | public string path; 28 | /// 29 | /// 提示信息 30 | /// 31 | public string Tips 32 | { 33 | get 34 | { 35 | return "jsonKeyFile:服务账号密钥文件位置" + 36 | "bucket:存储空间名;" + 37 | "path:文件在Bucket/桶下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件"; 38 | } 39 | } 40 | 41 | /// 42 | /// 获取示例实例。 43 | /// 44 | /// 示例配置实例 45 | public object GetExample() 46 | { 47 | return new GoogleCloudStorageUploader() 48 | { 49 | jsonKeyFile = "/conf/xxx.json", 50 | bucket = "backup", 51 | path = "data/some" 52 | }; 53 | } 54 | 55 | /// 56 | /// 上传指定文件。 57 | /// 58 | /// 待上传的文件 59 | /// 文件在云空间里的后缀 60 | /// 61 | public Task Upload(string file, string suffix) 62 | { 63 | using (FileStream stream = new FileStream(file, FileMode.Open)) 64 | { 65 | GoogleCredential credential = GoogleCredential.FromFile(jsonKeyFile); 66 | var client = StorageClient.Create(credential); 67 | client.UploadObject(bucket, path + suffix, "application/x-zip-compressed", stream); 68 | } 69 | 70 | return Task.CompletedTask; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/HuaweiCloudUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using OBS; 3 | using OBS.Model; 4 | using System; 5 | using System.Threading.Tasks; 6 | 7 | namespace Backup2Cloud.Uploader 8 | { 9 | /// 10 | /// 华为云上传实现类。 11 | /// 12 | [Name("huawei")] 13 | public class HuaweiCloudUploader : IUploader 14 | { 15 | /// 16 | /// 访问域名(可以在控制台查看) 17 | /// 18 | public string endpoint; 19 | /// 20 | /// 华为云 Access Key Id 21 | /// 22 | public string accessKeyId; 23 | /// 24 | /// 华为云 Secret Access Key 25 | /// 26 | public string secretAccessKey; 27 | /// 28 | /// 桶名称 29 | /// 30 | public string bucket; 31 | /// 32 | /// 文件在存储空间下的路径,作为上传路径前缀。 33 | /// 34 | public string path; 35 | /// 36 | /// 上传到云端多少天后自动删除该文件,如果不设置(即保持默认默认)则不删除 37 | /// 38 | public int? deleteAfterDays; 39 | /// 40 | /// 提示信息 41 | /// 42 | public string Tips 43 | { 44 | get 45 | { 46 | return "endpoint:地域节点(可以在控制台查看);" + 47 | "accessKeyId:华为云 Access Key Id(可以在控制台查看);" + 48 | "secretAccessKey:华为云 Secret Access Key(可以在控制台查看);" + 49 | "bucket:桶名称" + 50 | "path:文件在存储空间下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件;" + 51 | "deleteAfterDays:多少天后自动删除,可以不设置"; 52 | } 53 | } 54 | 55 | /// 56 | /// 获取华为云示例实例。 57 | /// 58 | /// 华为云示例配置实例 59 | public object GetExample() 60 | { 61 | return new HuaweiCloudUploader() 62 | { 63 | endpoint = "obs.cn-north-1.myhwclouds.com", 64 | accessKeyId = "xxxx", 65 | secretAccessKey = "yyyy", 66 | bucket = "backup", 67 | path = "data/some", 68 | deleteAfterDays = 20 69 | }; 70 | } 71 | 72 | /// 73 | /// 上传指定文件到华为云BOS。 74 | /// 75 | /// 待上传的文件 76 | /// 文件在云空间里的后缀 77 | /// 78 | public Task Upload(string file, string suffix) 79 | { 80 | var client = new ObsClient(accessKeyId, secretAccessKey, endpoint); 81 | PutObjectRequest request = new PutObjectRequest() 82 | { 83 | BucketName = bucket, 84 | ObjectKey = path + suffix, 85 | FilePath = file, 86 | Expires = deleteAfterDays 87 | }; 88 | client.PutObject(request); 89 | return Task.CompletedTask; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/IUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace Backup2Cloud.Uploader 6 | { 7 | /// 8 | /// 上传文件接口,实现此接口需要同时引用NameAttribute表明服务商。 9 | /// 10 | public interface IUploader : IConfigurable, IExampled 11 | { 12 | /// 13 | /// 上传文件。 14 | /// 15 | /// 待上传的文件 16 | /// 文件在云空间里的后缀 17 | /// 18 | Task Upload(string file, string suffix); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/JDCloudUploader.cs: -------------------------------------------------------------------------------- 1 | using Amazon.S3; 2 | using Amazon.S3.Model; 3 | using Backup2Cloud.Conf; 4 | using System; 5 | using System.IO; 6 | using System.Text.RegularExpressions; 7 | using System.Threading.Tasks; 8 | 9 | namespace Backup2Cloud.Uploader 10 | { 11 | /// 12 | /// 京东云对象存储上传实现类。 13 | /// 14 | [Name("jdcloud")] 15 | public class JDCloudUploader : IUploader 16 | { 17 | /// 18 | /// 对象存储空间的外网访问域名 19 | /// 20 | public string domain; 21 | /// 22 | /// 京东云 Access Key ID 23 | /// 24 | public string accessKeyId; 25 | /// 26 | /// 京东云 Secret Access Key 27 | /// 28 | public string secretAccessKey; 29 | /// 30 | /// 文件在Bucket下的路径,作为上传路径前缀。 31 | /// 32 | public string path; 33 | /// 34 | /// 提示信息 35 | /// 36 | public string Tips 37 | { 38 | get 39 | { 40 | return "domain:对象存储空间的外网访问域名,在 对象存储-空间管理-空间信息 里查看,例如backup.oss.cn-east-2.jcloudcs.com" + 41 | "accessKeyId:Access Key ID;" + 42 | "secretAccessKey:Secret Access Key;" + 43 | "path:文件在Bucket/桶下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件"; 44 | } 45 | } 46 | /// 47 | /// 获取示例实例。 48 | /// 49 | /// 示例配置实例 50 | public object GetExample() 51 | { 52 | return new JDCloudUploader() 53 | { 54 | domain = "backup.oss.cn-east-2.jcloudcs.com", 55 | accessKeyId = "xxxx", 56 | secretAccessKey = "yyy", 57 | path = "data/file" 58 | }; 59 | } 60 | 61 | /// 62 | /// 上传指定文件。 63 | /// 64 | /// 待上传的文件 65 | /// 文件在云空间里的后缀 66 | /// 67 | public async Task Upload(string file, string suffix) 68 | { 69 | string pattern = @"^([^\.]+)\.oss\.([^\.]+)\.jcloudcs\.com$"; 70 | var matches = Regex.Matches(domain.Trim(), pattern); 71 | if (matches.Count != 1) 72 | { 73 | throw new Exception(string.Format("域名{0}不符合京东云对象存储空间的外网访问域名的格式。", domain)); 74 | } 75 | 76 | var groups = matches[0].Groups; 77 | string bucket = groups[1].Value; 78 | string systemName = groups[2].Value; 79 | string serverUrl = "http://s3." + systemName + ".jcloudcs.com"; 80 | AmazonS3Config config = new AmazonS3Config() 81 | { 82 | UseHttp = true, 83 | ServiceURL = serverUrl, 84 | SignatureVersion = "v4" 85 | }; 86 | 87 | using (FileStream stream = new FileStream(file, FileMode.Open)) 88 | { 89 | using (AmazonS3Client client = new AmazonS3Client(accessKeyId, secretAccessKey, config)) 90 | { 91 | PutObjectRequest request = new PutObjectRequest() 92 | { 93 | BucketName = bucket, 94 | Key = path + suffix, 95 | InputStream = stream, 96 | UseChunkEncoding = false 97 | }; 98 | 99 | await client.PutObjectAsync(request); 100 | } 101 | } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/QCloudUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using QCloudSDK.COS; 3 | using System; 4 | using System.IO; 5 | using System.Threading.Tasks; 6 | 7 | namespace Backup2Cloud.Uploader 8 | { 9 | /// 10 | /// 腾讯云COS上传实现类。 11 | /// 12 | [Name("qcloud")] 13 | public class QCloudUploader : IUploader 14 | { 15 | /// 16 | /// 腾讯云 APPID 17 | /// 18 | public string appId; 19 | /// 20 | /// 腾讯云 SecretId 21 | /// 22 | public string secretId; 23 | /// 24 | /// 腾讯云 SecretKey 25 | /// 26 | public string secretKey; 27 | /// 28 | /// 文件绝对路径,作为前缀使用。 29 | /// 30 | public string url; 31 | /// 32 | /// 提示信息 33 | /// 34 | public string Tips 35 | { 36 | get 37 | { 38 | return "appId:腾讯云 APPID(可以在控制台查看);" + 39 | "secretId:腾讯云 SecretId(可以在控制台查看);" + 40 | "secretKey:腾讯云 SecretKey(可以在控制台查看);" + 41 | "url:绝对路径,例如\"https://backup-123456.cos.ap-chengdu.myqcloud.com/test\"," + 42 | "最终会生成类似\"https://backup-123456.cos.ap-chengdu.myqcloud.com/test201809092054.zip\"之类的文件," + 43 | "可以在 控制台-对象存储-存储桶列表-点击实际的桶名称-基础设置-访问域名 中找到url的前部分,后部分是文件相对于桶的路径"; 44 | } 45 | } 46 | 47 | /// 48 | /// 获取腾讯云示例实例。 49 | /// 50 | /// 腾讯云示例配置实例 51 | public object GetExample() 52 | { 53 | return new QCloudUploader() 54 | { 55 | appId = "123456", 56 | secretId = "xxxx", 57 | secretKey = "yyyy", 58 | url = "https://backup-123456.cos.ap-chengdu.myqcloud.com/test" 59 | }; 60 | } 61 | 62 | /// 63 | /// 上传指定文件到腾讯云COS。 64 | /// 65 | /// 待上传的文件 66 | /// 文件在云空间里的后缀 67 | /// 68 | public async Task Upload(string file, string suffix) 69 | { 70 | Client client = new Client(new Configuration() 71 | { 72 | AppId = appId, 73 | SecretId = secretId, 74 | SecretKey = secretKey 75 | }); 76 | using (FileStream stream = new FileStream(file, FileMode.Open)) 77 | { 78 | await client.PutObjectAsync(url + suffix, stream); 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/QingStorUploader.cs: -------------------------------------------------------------------------------- 1 | using Amazon.S3; 2 | using Amazon.S3.Model; 3 | using Backup2Cloud.Conf; 4 | using System; 5 | using System.IO; 6 | using System.Text.RegularExpressions; 7 | using System.Threading.Tasks; 8 | 9 | namespace Backup2Cloud.Uploader 10 | { 11 | /// 12 | /// 青云对象存储上传实现类。 13 | /// 14 | [Name("qinstor")] 15 | public class QingStorUploader : IUploader 16 | { 17 | /// 18 | /// 对象存储空间的外网访问域名 19 | /// 20 | public string url; 21 | /// 22 | /// 青云 Access Key ID 23 | /// 24 | public string accessKeyId; 25 | /// 26 | /// 青云 Secret Access Key 27 | /// 28 | public string secretAccessKey; 29 | /// 30 | /// 文件在Bucket下的路径,作为上传路径前缀。 31 | /// 32 | public string path; 33 | /// 34 | /// 提示信息 35 | /// 36 | public string Tips 37 | { 38 | get 39 | { 40 | return "url:Url (API访问用),在 对象存储 里查看,例如 http://backup.pek3b.qingstor.com" + 41 | "accessKeyId:Access Key ID;" + 42 | "secretAccessKey:Secret Access Key;" + 43 | "path:文件在Bucket/桶下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件"; 44 | } 45 | } 46 | /// 47 | /// 获取示例实例。 48 | /// 49 | /// 示例配置实例 50 | public object GetExample() 51 | { 52 | return new QingStorUploader() 53 | { 54 | url = "http://backup.pek3b.qingstor.com", 55 | accessKeyId = "xxxx", 56 | secretAccessKey = "yyy", 57 | path = "data/file" 58 | }; 59 | } 60 | 61 | /// 62 | /// 上传指定文件。 63 | /// 64 | /// 待上传的文件 65 | /// 文件在云空间里的后缀 66 | /// 67 | public async Task Upload(string file, string suffix) 68 | { 69 | string pattern = @"^http://([^\.]+)\.([^\.]+)\.qingstor\.com$"; 70 | var matches = Regex.Matches(url.Trim(), pattern); 71 | if (matches.Count != 1) 72 | { 73 | throw new Exception(string.Format("域名{0}不符合青云对象存储空间的api url的格式。", url)); 74 | } 75 | 76 | var groups = matches[0].Groups; 77 | string bucket = groups[1].Value; 78 | string systemName = groups[2].Value; 79 | string serverUrl = string.Format("https://s3.{0}.qingstor.com", systemName, bucket); 80 | AmazonS3Config config = new AmazonS3Config() 81 | { 82 | ServiceURL = serverUrl, 83 | SignatureVersion = "v4" 84 | }; 85 | 86 | using (FileStream stream = new FileStream(file, FileMode.Open)) 87 | { 88 | using (AmazonS3Client client = new AmazonS3Client(accessKeyId, secretAccessKey, config)) 89 | { 90 | 91 | PutObjectRequest request = new PutObjectRequest() 92 | { 93 | BucketName = bucket, 94 | Key = path + suffix, 95 | InputStream = stream 96 | }; 97 | 98 | await client.PutObjectAsync(request); 99 | } 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/QiniuUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Qiniu.IO; 3 | using Qiniu.IO.Model; 4 | using Qiniu.Util; 5 | using System; 6 | using System.Threading.Tasks; 7 | 8 | namespace Backup2Cloud.Uploader 9 | { 10 | /// 11 | /// 七牛云对象存储上传实现类。 12 | /// 13 | [Name("qiniu")] 14 | public class QiniuUploader : IUploader 15 | { 16 | /// 17 | /// 七牛云AccessKey 18 | /// 19 | public string accessKey; 20 | /// 21 | /// 七牛云SecretKey 22 | /// 23 | public string secretKey; 24 | /// 25 | /// 七牛云存储空间 26 | /// 27 | public string bucket; 28 | /// 29 | /// 文件在存储空间下的路径,作为上传路径前缀。 30 | /// 31 | public string path; 32 | /// 33 | /// 上传超时时间,单位毫秒 34 | /// 35 | public int? timeout; 36 | /// 37 | /// 上传到云端多少天后自动删除该文件,如果不设置(即保持默认默认)则不删除 38 | /// 39 | public int? deleteAfterDays; 40 | 41 | /// 42 | /// 提示信息 43 | /// 44 | public string Tips 45 | { 46 | get 47 | { 48 | return "accessKey:七牛云AccessKey(可以在控制台查看);" + 49 | "secretKey:七牛云SecretKey(可以在控制台查看);" + 50 | "bucket:存储空间名" + 51 | "path:文件在存储空间下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件;" + 52 | "timeout:上传超时时间,单位毫秒,可以不设置;" + 53 | "deleteAfterDays:多少天后自动删除,可以不设置"; 54 | } 55 | } 56 | 57 | /// 58 | /// 获取七牛云示例实例。 59 | /// 60 | /// 七牛云示例配置实例 61 | public object GetExample() 62 | { 63 | return new QiniuUploader() 64 | { 65 | accessKey = "accessKey", 66 | secretKey = "secretKey", 67 | bucket = "backup", 68 | path = "data/some", 69 | timeout = 200 * 1000, 70 | deleteAfterDays = 5 71 | }; 72 | } 73 | 74 | /// 75 | /// 上传指定文件到七牛云对象存储。 76 | /// 77 | /// 待上传的文件 78 | /// 文件在云空间里的后缀 79 | /// 80 | public async Task Upload(string file, string suffix) 81 | { 82 | string key = path + suffix; 83 | Mac mac = new Mac(accessKey, secretKey); 84 | 85 | PutPolicy putPolicy = new PutPolicy(); 86 | putPolicy.Scope = bucket + ":" + key; 87 | putPolicy.Scope = bucket; 88 | if (timeout.HasValue && timeout.Value > 0) 89 | { 90 | putPolicy.SetExpires(timeout.Value / 1000); 91 | } 92 | 93 | if (deleteAfterDays.HasValue && deleteAfterDays.Value > 0) 94 | { 95 | putPolicy.DeleteAfterDays = deleteAfterDays; 96 | } 97 | 98 | string json = putPolicy.ToJsonString(); 99 | string token = Auth.CreateUploadToken(mac, json); 100 | UploadManager um = new UploadManager(); 101 | var result = await um.UploadFileAsync(file, key, token); 102 | if (result.Code != 200) 103 | { 104 | throw new Exception("上传失败,服务器返回错误信息:" + result.Text); 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Backup2Cloud/Uploader/UCloudUploader.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using System; 3 | using System.Threading.Tasks; 4 | using UCloudSDK; 5 | 6 | namespace Backup2Cloud.Uploader 7 | { 8 | /// 9 | /// UCloud对象存储上传实现类。 10 | /// 11 | [Name("ucloud")] 12 | public class UCloudUploader : IUploader 13 | { 14 | /// 15 | /// UCloud 公钥 16 | /// 17 | public string publicKey; 18 | /// 19 | /// UCloud 私钥 20 | /// 21 | public string privateKey; 22 | /// 23 | /// UCloud 存储空间 24 | /// 25 | public string bucket; 26 | /// 27 | /// UCloud 存储空间域名 28 | /// 29 | public string bucketDomain; 30 | /// 31 | /// 文件在存储空间下的路径,作为上传路径前缀。 32 | /// 33 | public string path; 34 | 35 | /// 36 | /// 提示信息 37 | /// 38 | public string Tips 39 | { 40 | get 41 | { 42 | return "accessKey:UCloud 公钥(可以在控制台-产品服务-API 产品-API密钥 查看);" + 43 | "secretKey:UCloud 私钥(可以在控制台-产品服务-API 产品-API密钥 查看);" + 44 | "bucket:存储空间名;" + 45 | "bucketDomain:存储空间域名 类似.cn-sh2.ufileos.com;" + 46 | "path:文件在存储空间下的路径前缀,例如\"data/some\",最终会生成类似\"data/some201809092054.zip\"之类的文件"; 47 | } 48 | } 49 | 50 | /// 51 | /// 获取UCloud示例实例。 52 | /// 53 | /// UCloud示例配置实例 54 | public object GetExample() 55 | { 56 | return new UCloudUploader() 57 | { 58 | publicKey = "publicKey", 59 | privateKey = "privateKey", 60 | bucket = "backup", 61 | bucketDomain = "backup.cn-sh2.ufileos.com", 62 | path = "data/some" 63 | }; 64 | } 65 | 66 | /// 67 | /// 上传指定文件到UCloud对象存储。 68 | /// 69 | /// 待上传的文件 70 | /// 文件在云空间里的后缀 71 | /// 72 | public Task Upload(string file, string suffix) 73 | { 74 | if (bucketDomain.StartsWith(bucket) == false) 75 | { 76 | throw new Exception(string.Format("Bucket\"{0}\"的BucketDomain不是\"{1}\"!", bucket, bucketDomain)); 77 | } 78 | 79 | UFile u = new UFile(publicKey, privateKey); 80 | u.FileUrl = "http://{0}" + bucketDomain.Substring(bucket.Length); 81 | var res = u.PutFile(file, path + suffix, bucket); 82 | if (res.RetCode != 0) 83 | { 84 | throw new Exception(string.Format("上传失败。\n\tXSessionId:{0}\n\t错误信息:{1}", res.XSessionId, res.ErrMsg)); 85 | } 86 | 87 | return Task.CompletedTask; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Backup2Cloud/Worker/BackupWorker.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Backup2Cloud.Logging; 3 | using Quartz; 4 | using SharpCompress.Archives; 5 | using SharpCompress.Common; 6 | using System; 7 | using System.Diagnostics; 8 | using System.IO; 9 | using System.Threading.Tasks; 10 | 11 | namespace Backup2Cloud.Worker 12 | { 13 | /// 14 | /// 执行备份的工作类。 15 | /// 16 | public class BackupWorker : IJob 17 | { 18 | /// 19 | /// 执行备份。 20 | /// 21 | public async Task Execute(IJobExecutionContext context) 22 | { 23 | try 24 | { 25 | var conf = (SingleConfiguration)(context.MergedJobDataMap[WorkScheduler.ConfKey]); 26 | string file = null; 27 | try 28 | { 29 | DateTime start = DateTime.Now; 30 | Log.Info(string.Format("开始执行任务\"{0}\"。", conf.name), conf.name); 31 | 32 | if (conf.dataSource != null) 33 | { 34 | conf.dataSource.SaveData(conf.path); 35 | Log.Info("成功为数据源执行保存命令。", conf.name); 36 | } 37 | 38 | string suffix = start.ToString("yyyyMMddHHmmss") + ".zip"; 39 | file = Compress(conf.path); 40 | Log.Info("成功打包备份文件。", conf.name); 41 | await conf.uploader.Upload(file, suffix); 42 | Log.Info("成功上传文件。", conf.name); 43 | 44 | DateTime end = DateTime.Now; 45 | Log.Info($"任务\"{ conf.name }\"执行成功,用时{ (end - start).TotalSeconds }秒。", conf.name); 46 | } 47 | catch (Exception e) 48 | { 49 | Log.Error(e.Message, conf.name);//此处只显示基本异常信息。 50 | } 51 | finally 52 | { 53 | if (string.IsNullOrEmpty(file) == false && 54 | File.Exists(file)) 55 | { 56 | File.Delete(file);//删除压缩包 57 | } 58 | } 59 | } 60 | catch (Exception e) 61 | { 62 | Log.Error(e.ToString()); 63 | } 64 | } 65 | 66 | /// 67 | /// 压缩文件或文件夹为zip文件。 68 | /// 69 | /// 待压缩的路径 70 | /// zip路径 71 | private string Compress(string path) 72 | { 73 | string dir = AppDomain.CurrentDomain.BaseDirectory + "/tmp"; 74 | if (Directory.Exists(dir) == false) 75 | { 76 | Directory.CreateDirectory(dir); 77 | } 78 | 79 | string zip = dir + "/" + Guid.NewGuid().ToString("N") + ".zip"; 80 | if (File.Exists(zip)) 81 | { 82 | File.Delete(zip); 83 | } 84 | 85 | if (File.Exists(path)) 86 | { 87 | // 是文件 88 | FileInfo fi = new FileInfo(path); 89 | if (fi.FullName.EndsWith(".zip"))//如果是zip文件,就直接复制,而不是压缩。 90 | { 91 | fi.CopyTo(zip, true); 92 | } 93 | else 94 | { 95 | using (var archive = SharpCompress.Archives.Zip.ZipArchive.Create()) 96 | { 97 | archive.AddEntry(fi.Name, fi); 98 | archive.SaveTo(zip, CompressionType.Deflate); 99 | } 100 | } 101 | } 102 | else if (Directory.Exists(path)) 103 | { 104 | // 是文件夹 105 | using (var archive = SharpCompress.Archives.Zip.ZipArchive.Create()) 106 | { 107 | archive.AddAllFromDirectory(path); 108 | archive.SaveTo(zip, CompressionType.Deflate); 109 | } 110 | } 111 | else 112 | { 113 | // 都不是 114 | throw new FileNotFoundException($"没有找到文件或目录\"{ path }\"。"); 115 | } 116 | 117 | return zip; 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Backup2Cloud/Worker/WorkScheduler.cs: -------------------------------------------------------------------------------- 1 | using Backup2Cloud.Conf; 2 | using Backup2Cloud.Logging; 3 | using Quartz; 4 | using Quartz.Impl; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Collections.Specialized; 8 | 9 | namespace Backup2Cloud.Worker 10 | { 11 | /// 12 | /// 工作调度类。 13 | /// 14 | public class WorkScheduler 15 | { 16 | /// 17 | /// 配置在JobDataMap中的key名称。 18 | /// 19 | public static string ConfKey => "conf"; 20 | /// 21 | /// 工作调度实例。 22 | /// 23 | private readonly IScheduler _scheduler = null; 24 | /// 25 | /// 组名。 26 | /// 27 | private readonly string _groupName = "group_" + Guid.NewGuid().ToString("N"); 28 | /// 29 | /// 已经创建的工作名的集合。 30 | /// 31 | private HashSet _jobNames = new HashSet(); 32 | 33 | /// 34 | /// 构造函数。 35 | /// 36 | public WorkScheduler() 37 | { 38 | NameValueCollection props = new NameValueCollection 39 | { 40 | { "quartz.serializer.type", "binary" } 41 | }; 42 | StdSchedulerFactory factory = new StdSchedulerFactory(props); 43 | _scheduler = factory.GetScheduler().Result; 44 | _scheduler.Start().Wait(); 45 | } 46 | 47 | /// 48 | /// 开始工作。 49 | /// 50 | /// 工作相关配置 51 | public void StartWork(SingleConfiguration configuration) 52 | { 53 | if (_jobNames.Contains(configuration.name)) 54 | { 55 | string newName = configuration.name + Guid.NewGuid().ToString("N"); 56 | Log.Warn(string.Format("已存在名为\"{0}\"的任务,当前任务将改名为\"{1}\"。", configuration.name, newName)); 57 | configuration.name = newName; 58 | } 59 | 60 | _jobNames.Add(configuration.name); 61 | if (configuration.crontab == null || configuration.crontab.Count == 0) 62 | { 63 | throw new ArgumentException(string.Format("任务\"{0}\"的crontab字段为空。", configuration.name)); 64 | } 65 | 66 | JobDataMap map = new JobDataMap 67 | { 68 | [ConfKey] = configuration 69 | }; 70 | IJobDetail job = JobBuilder.Create() 71 | .WithIdentity("job_" + configuration.name, _groupName) 72 | .UsingJobData(map) 73 | .Build(); 74 | 75 | TriggerBuilder triggerBuilder = TriggerBuilder.Create() 76 | .WithIdentity("trigger_" + configuration.name, _groupName) 77 | .StartNow(); 78 | foreach (var i in configuration.crontab) 79 | { 80 | triggerBuilder.WithCronSchedule(i); 81 | } 82 | 83 | ITrigger trigger = triggerBuilder.Build(); 84 | _scheduler.ScheduleJob(job, trigger); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 |  2 | FROM microsoft/dotnet:2.1-sdk AS build 3 | MAINTAINER sanjusss 4 | WORKDIR /src 5 | COPY . /src 6 | #RUN dotnet restore 7 | #RUN dotnet build -c Release 8 | RUN dotnet publish -c Release -o /app 9 | 10 | FROM microsoft/dotnet:2.1-runtime AS final 11 | MAINTAINER sanjusss 12 | WORKDIR /app 13 | COPY --from=build /app . 14 | ENTRYPOINT ["dotnet", "Backup2Cloud.dll"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | [![Docker Build Status](https://img.shields.io/docker/build/sanjusss/backup2cloud.svg)](https://hub.docker.com/r/sanjusss/backup2cloud) 3 | [![Build status](https://ci.appveyor.com/api/projects/status/9sa1mtm53jxket5t?svg=true)](https://ci.appveyor.com/project/sanjusss/backup2cloud) 4 | [![GitHub release](https://img.shields.io/github/release/sanjusss/backup2cloud.svg)](https://github.com/sanjusss/backup2cloud/releases/latest) 5 | [![GitHub license](https://img.shields.io/github/license/sanjusss/backup2cloud.svg)](https://github.com/sanjusss/backup2cloud/blob/master/LICENSE) 6 | [![GitHub tag](https://img.shields.io/github/tag/sanjusss/backup2cloud.svg)](https://github.com/sanjusss/backup2cloud/tags) 7 | [![GitHub issues](https://img.shields.io/github/issues/sanjusss/backup2cloud.svg)](https://github.com/sanjusss/backup2cloud/issues) 8 | [![GitHub forks](https://img.shields.io/github/forks/sanjusss/backup2cloud.svg)](https://github.com/sanjusss/backup2cloud/network) 9 | [![GitHub stars](https://img.shields.io/github/stars/sanjusss/backup2cloud.svg)](https://github.com/sanjusss/backup2cloud/stargazers) 10 | [![GitHub repo size in bytes](https://img.shields.io/github/repo-size/sanjusss/backup2cloud.svg)](#) 11 | 12 | # 用途 13 | 定时将服务器上的文件或文件夹备份到网络云存储(OSS或S3)。 14 | 可以设置在多个时间点,备份多个文件或文件夹到多个网络云存储。 15 | 16 | # 支持的云存储 17 | 18 | | 服务提供商 | 产品名称 | 是否支持 | 备注 | 19 | |---|---|---|----| 20 | |[阿里云](https://www.aliyun.com)|[OSS](https://www.aliyun.com/product/oss)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 21 | |[腾讯云](https://cloud.tencent.com)|[COS](https://cloud.tencent.com/product/cos)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 22 | |[百度云](https://cloud.baidu.com)|[BOS](https://cloud.baidu.com/product/bos.html)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 23 | |[七牛云](https://www.qiniu.com)|[对象存储](https://www.qiniu.com/products/kodo)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 24 | |[AWS](https://amazonaws-china.com/cn/)|[S3](https://amazonaws-china.com/cn/s3/)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 25 | |[UCloud](https://www.ucloud.cn)|[UFile](https://www.ucloud.cn/site/product/ufile.html)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 26 | |[华为云](https://www.huaweicloud.com)|[OBS](https://www.huaweicloud.com/product/obs.html)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 27 | |[京东云](https://www.jdcloud.com)|[对象存储](https://www.jdcloud.com/products/cloudstorag)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 28 | |[青云](https://www.qingcloud.com)|[对象存储](https://www.qingcloud.com/products/qingstor/)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 29 | |[金山云](https://www.ksyun.com)|[对象存储](https://www.ksyun.com/post/product/KS3)|![不支持](https://img.shields.io/badge/support-No-red.svg)|仅限企业用户| 30 | |[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)|| 31 | |[Google Cloud](https://cloud.google.com)|[Google Cloud Storage](https://cloud.google.com/storage/)|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 32 | |自定义|FTP|![支持](https://img.shields.io/badge/support-Yes-green.svg)|| 33 | 34 | # 支持的数据源 35 | 36 | |数据源|是否支持| 37 | |-|-| 38 | |本地文件|![支持](https://img.shields.io/badge/support-Yes-green.svg)| 39 | |本地文件夹|![支持](https://img.shields.io/badge/support-Yes-green.svg)| 40 | |MySQL|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)| 41 | |SQL Server|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)| 42 | |Oracle|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)| 43 | |自定义命令|![支持](https://img.shields.io/badge/support-Yes-green.svg)| 44 | |FTP文件|![支持](https://img.shields.io/badge/support-Yes-green.svg)| 45 | |FTP文件文件夹|![支持](https://img.shields.io/badge/support-Yes-green.svg)| 46 | 47 | # 支持的备份触发方式 48 | 49 | |触发方式|是否支持| 50 | |-|-| 51 | |Cron 表达式|![支持](https://img.shields.io/badge/support-Yes-green.svg)| 52 | |本地文件发生变化|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)| 53 | |本地文件夹发生变化|![即将到来](https://img.shields.io/badge/support-Future-yellow.svg)| 54 | 55 | # 使用方法(Docker) 56 | ### 运行 57 | ``` 58 | docker run -d --restart=always -v /etc/localtime:/etc/localtime:ro -v /xxx/yyy:/data -v /etc/backup2cloud:/conf sanjusss/backup2cloud run -c /conf/backup2cloud.json 59 | ``` 60 | 运行后程序将加载配置文件backup2cloud.json。 61 | `-v /etc/localtime:/etc/localtime:ro`保证了docker容器内时区和外部环境一样,否则默认使用UTC时间。 62 | 注意文件夹的挂载。 63 | 64 | ### 查看示例配置文件 65 | ``` 66 | docker run --rm -v /D/share:/conf sanjusss/backup2cloud eg -s /conf/eg.json 67 | ``` 68 | 运行后将在D:\share\eg.json生成示例配置文件。 69 | 如果省略`-s /conf/eg.json`,将不保存文件,仅在命令行下输出。 70 | 实际的配置文件中没有Tips一项。 71 | 其他配置参数见[查看示例](https://github.com/sanjusss/backup2cloud#查看示例)。 72 | 73 | # 使用方法(Windows) 74 | ### 下载 75 | [点我打开软件下载页面](https://github.com/sanjusss/backup2cloud/releases/latest) 76 | 77 | ### 运行 78 | ``` 79 | backup2cloud run -c D:\backup2cloud.json 80 | ``` 81 | 运行后程序将加载配置文件backup2cloud.json。 82 | 83 | ### 查看示例 84 | 1. 查看一个示例配置文件 85 | ``` 86 | backup2cloud eg -s D:\share\eg.json 87 | ``` 88 | 运行后将在D:\share\eg.json生成示例配置文件。 89 | 如果省略`-s D:\share\eg.json`,将不保存文件,仅在命令行下输出。 90 | 实际的配置文件中没有Tips一项。 91 | 92 | 2. 查看所有上传类名称 93 | ``` 94 | backup2cloud eg -l uploader 95 | ``` 96 | 97 | 3. 查看所有数据源类名称 98 | ``` 99 | backup2cloud eg -l datasource 100 | ``` 101 | 102 | 4. 查看指定上传类示例 103 | ``` 104 | backup2cloud eg -u 上传类名称 105 | ``` 106 | 107 | 5. 查看指定数据源类示例 108 | ``` 109 | backup2cloud eg -d 数据源类名称 110 | ``` 111 | 112 | 113 | # 配置文件说明 114 | 待补充 115 | 116 | # 引用项目 117 | https://www.newtonsoft.com/json 118 | https://github.com/vla/aliyun-oss-csharp-sdk 119 | https://github.com/commandlineparser/commandline 120 | https://github.com/zhengchun/qcloud-sdk-net 121 | https://github.com/adamhathcock/sharpcompress 122 | https://www.quartz-scheduler.net 123 | https://github.com/sanjusss/backup2cloud 124 | https://github.com/fengyhack/csharp-sdk 125 | https://github.com/sanjusss/ucloud-csharp-sdk 126 | https://github.com/aws/aws-sdk-net/ 127 | https://github.com/awslabs/aws-sdk-net-samples 128 | https://support.huaweicloud.com/devg-obs_csharp_sdk_doc_zh/zh-cn_topic_0120606335.html 129 | https://github.com/GoogleCloudPlatform/google-cloud-dotnet 130 | https://github.com/Azure/azure-storage-net 131 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 |  2 | version: 0.2.0.0.{build} 3 | image: Visual Studio 2017 4 | shallow_clone: true 5 | build_script: 6 | - cmd: >- 7 | dotnet build -c Release -o result . 8 | 9 | dotnet publish -c Release -o publish . 10 | 11 | dotnet publish -c Release -r win-x86 -o publishwin86 . 12 | 13 | dotnet publish -c Release -r win-x64 -o publishwin64 . 14 | artifacts: 15 | - path: Backup2Cloud\publish 16 | name: backup2cloud-$(APPVEYOR_BUILD_VERSION)-dotnet-core 17 | type: WebDeployPackage 18 | - path: Backup2Cloud\publishwin86 19 | name: backup2cloud-$(APPVEYOR_BUILD_VERSION)-win-x86 20 | type: WebDeployPackage 21 | - path: Backup2Cloud\publishwin64 22 | name: backup2cloud-$(APPVEYOR_BUILD_VERSION)-win-x64 23 | type: WebDeployPackage 24 | deploy: 25 | - provider: GitHub 26 | auth_token: 27 | secure: VFLWVehXTfNaqBsG5F8ZkEWTFKvDxhk71wQJ+ZDspUEoqfvXpbQwkB0OA/N+r/qD 28 | draft: false 29 | force_update: true 30 | on: 31 | APPVEYOR_REPO_TAG: true -------------------------------------------------------------------------------- /backup2cloud.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2019 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backup2Cloud", "Backup2Cloud\Backup2Cloud.csproj", "{C783855D-BD60-44CE-86E0-974046BAD6BE}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EB540FC-0438-454B-9515-2FA2B25B5BCA}" 9 | ProjectSection(SolutionItems) = preProject 10 | appveyor.yml = appveyor.yml 11 | Dockerfile = Dockerfile 12 | LICENSE = LICENSE 13 | README.md = README.md 14 | EndProjectSection 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {C783855D-BD60-44CE-86E0-974046BAD6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {C783855D-BD60-44CE-86E0-974046BAD6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {C783855D-BD60-44CE-86E0-974046BAD6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {C783855D-BD60-44CE-86E0-974046BAD6BE}.Release|Any CPU.Build.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ExtensibilityGlobals) = postSolution 31 | SolutionGuid = {30FCB114-C6AD-4271-8ED7-C05CA7B05EE3} 32 | EndGlobalSection 33 | EndGlobal 34 | --------------------------------------------------------------------------------