Exemplo n.º 1
0
        private async Task <string[]> AskForItemsAgent(Guid serverId)
        {
            var server = await metaDB.GetWindowsServer(serverId, true);

            if (server == null)
            {
                return(null);
            }

            var proxy  = new WindowsProxy(server.Ip, server.Username, server.Password);
            var drives = await proxy.GetDrives();

            var items = new List <string>();

            await outStream.WriteLineAsync("Choose something to backup");

            var i = 0;

            foreach (var drive in drives)
            {
                await outStream.WriteLineAsync(
                    $"{i++} / {drive}");
            }
            await outStream.WriteAsync("number to add -or- g number to go deeper -or- b to go back > ");

            var rawInput = await inStream.ReadLineAsync() ?? "";

            var stringArray = rawInput.Split(' ', StringSplitOptions.RemoveEmptyEntries);

            return(items.ToArray());
        }
Exemplo n.º 2
0
        public async Task Details(Guid serverId)
        {
            var servertype = await metaDB.GetServerType(serverId);

            switch (servertype)
            {
            case ServerType.Windows:
                await PrintWindowsServer(await metaDB.GetWindowsServer(serverId));

                break;

            case ServerType.VMware:
                await PrintVMwareServer(await metaDB.GetVMWareServer(serverId));

                break;
            }
        }
Exemplo n.º 3
0
        private async Task <DBServer> GetServer(Guid id, bool withcreds = false)
        {
            var servertype = await metaDB.GetServerType(id);

            DBServer server = null;

            switch (servertype)
            {
            case ServerType.Windows:
                server = await metaDB.GetWindowsServer(id, withcreds);

                break;

            case ServerType.VMware:
                server = await metaDB.GetVMWareServer(id, withcreds);

                break;
            }

            return(server);
        }
Exemplo n.º 4
0
        public async Task Run(Guid serverId, string[] items, CancellationToken ctoken = default)
        {
            if (backup != null)
            {
                return;
            }

            this.ctoken = ctoken;

            var server = await metaDB.GetWindowsServer(serverId, withcreds : true);

            agentProxy = new WindowsProxy(server.Ip, server.Username, server.Password)
            {
                BackupServiceCallback = this
            };

            backup = new DBBackup {
                Server = serverId, StartDate = DateTime.Now.ToUniversalTime(), Status = Status.Running, Log = new List <string>()
            };
            backup.Id = await metaDB.AddBackup(backup);

            backupStatus = Status.Successful;

            IObserver <CancellationTokenSource> observer = default;

            Observable.Interval(TimeSpan.FromSeconds(5)).TakeUntil(
                Observable.Create <CancellationTokenSource>(o =>
            {
                observer = o;
                return(() => { });
            }))
            .Subscribe(_ =>
            {
                var b = metaDB.GetBackup(backup.Id).GetAwaiter().GetResult();
                if (b.Status == Status.Cancelled)
                {
                    ctokenCancelBackup.Cancel();
                    observer.OnNext(ctokenCancelBackup);
                }
            });

            try
            {
                await agentProxy.Backup(items, backup.Id);

                foreach (var item in itemsQueue.GetConsumingEnumerable(ctoken))
                {
                    switch (item.Type)
                    {
                    case BackupItemType.File:
                    {
                        await BackupFile(item);
                    }
                    break;

                    case BackupItemType.Folder:
                    {
                        await BackupFolder(item);
                    }
                    break;
                    }
                }
            }
            catch (EndpointNotFoundException)
            {
                backup.AppendLog($"Cannot connect to server {server.Name} [{server.Ip}]");
                backupStatus = Status.Failed;
            }
            catch (OperationCanceledException)
            {
                backupStatus = Status.Cancelled;
            }
            catch (Exception e)
            {
                backup.AppendLog($"General Error: {e.Message}");
                backupStatus = Status.Failed;
            }
            finally
            {
                try
                {
                    await agentProxy.BackupComplete(backup.Id);
                }
                catch (Exception) { }

                backup.Status  = backupStatus;
                backup.EndDate = DateTime.Now.ToUniversalTime();
                await metaDB.AddBackup(backup);
            }

            Console.WriteLine($"{DateTime.Now} - Backup ended");
            Console.WriteLine($"{DateTime.Now} - Status: {backup.Status}");

            backup = null;
        }