forked from ravendb/ravendb
/
Program.cs
80 lines (69 loc) · 1.91 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using NDesk.Options;
namespace Raven.Backup
{
class Program
{
static void Main(string[] args)
{
var doReadKeyOnExit = false;
var op = new BackupOperation { NoWait = false };
var incrementalBackup = false;
var optionSet = new OptionSet
{
{"url=", "RavenDB server {0:url}", url => op.ServerUrl = url},
{"dest=", "Full {0:path} to backup folder", path => op.BackupPath = path},
{"nowait", "Return immedialtey without waiting for a response from the server", _ => op.NoWait = true},
{"readkey", _ => doReadKeyOnExit = true},
{"incremental", s => incrementalBackup= true}
};
try
{
if (args.Length == 0)
PrintUsage(optionSet);
optionSet.Parse(args);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
PrintUsage(optionSet);
return;
}
op.Incremental = incrementalBackup;
if (string.IsNullOrWhiteSpace(op.ServerUrl))
{
Console.WriteLine("Enter RavenDB server URL:");
op.ServerUrl = Console.ReadLine();
}
if (string.IsNullOrWhiteSpace(op.BackupPath))
{
Console.WriteLine("Enter backup destination:");
op.BackupPath = Console.ReadLine();
}
if (string.IsNullOrWhiteSpace(op.BackupPath) || string.IsNullOrWhiteSpace(op.ServerUrl))
return;
try
{
if (op.InitBackup())
op.WaitForBackup();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
if (doReadKeyOnExit) Console.ReadKey();
}
private static void PrintUsage(OptionSet optionSet)
{
Console.WriteLine(
@"
Backup utility for RavenDB
----------------------------------------
Copyright (C) 2008 - {0} - Hibernating Rhinos
----------------------------------------
Command line ptions:", DateTime.UtcNow.Year);
optionSet.WriteOptionDescriptions(Console.Out);
Console.WriteLine();
}
}
}