tesses.backup/Tesses.Backup.Cli/Program.cs

71 lines
2.5 KiB
C#

/*
A simple Backup Client / Server
Copyright (C) 2023 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using CommandLine;
using Tesses.Backup.Models;
using Tesses.Backup;
using Tesses.VirtualFilesystem;
using Tesses.VirtualFilesystem.Filesystems;
using System.Net;
public class Program
{
[Verb("backup",true)]
public class Backup
{
[Option('s',"server",Required =true)]
public string Server {get;set;}="";
[Option('u',"username",Required = true)]
public string Username {get;set;}="";
[Option('p',"password",Required = true)]
public string Password {get;set;}="";
[Option('d',"device",Required =false,HelpText ="Device Name")]
public string Device {get;set;}="";
[Option('p',"path",Required =false,HelpText = "Folder to backup")]
public string Path {get;set;}="";
}
public static async Task Main(string[] args)
{
await Parser.Default.ParseArguments<Backup>(args).WithParsedAsync<Backup>(async(e)=>{
using(var fs = new LocalFileSystem())
{
BackupClient client = new BackupClient(e.Server);
var session= await client.LoginAsync(e.Username,e.Password);
UnixPath p;
if(string.IsNullOrWhiteSpace(e.Path))
{
p = Special.Home;
}else{
p = UnixPath.FromLocal(e.Path);
}
if(string.IsNullOrWhiteSpace(e.Device))
{
e.Device = Dns.GetHostName();
}
await session.SetDeviceAsync(e.Device);
var bkp=await session.PrepareBackupAsync(fs,p);
await bkp.PerformBackupAsync();
await session.LogoutAsync();
}
});
}
}