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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
|
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Duplicati.Library.Interface;
namespace Duplicati.Library.Main
{
/// <summary>
/// A class for keeping all Duplicati options in one place,
/// and provide typesafe access to the options
/// </summary>
public class Options
{
private const string DEFAULT_BLOCK_HASH_LOOKUP_SIZE = "64mb";
private const string DEFAULT_METADATA_HASH_LOOKUP_SIZE = "64mb";
private const string DEFAULT_FILE_HASH_LOOKUP_SIZE = "32mb";
private const string DEFAULT_BLOCK_HASH_ALGORITHM = "SHA256";
private const string DEFAULT_FILE_HASH_ALGORITHM = "SHA256";
/// <summary>
/// The default block size
/// </summary>
private const string DEFAULT_BLOCKSIZE = "100kb";
/// <summary>
/// The default size of the read-ahead buffer
/// </summary>
private const string DEFAULT_READ_BUFFER_SIZE = "5mb";
/// <summary>
/// The default threshold value
/// </summary>
private const long DEFAULT_THRESHOLD = 25;
/// <summary>
/// The default value for maximum number of small files
/// </summary>
private const long DEFAULT_SMALL_FILE_MAX_COUNT = 20;
/// <summary>
/// Default size of volumes
/// </summary>
private const string DEFAULT_VOLUME_SIZE = "50mb";
/// <summary>
/// Default value for keep-versions
/// </summary>
private const int DEFAULT_KEEP_VERSIONS = 0;
/// <summary>
/// The default threshold for purging log data
/// </summary>
private const string DEFAULT_LOG_RETENTION = "30D";
/// <summary>
/// An enumeration that describes the supported strategies for an optimization
/// </summary>
public enum OptimizationStrategy
{
/// <summary>
/// The optimization feature is created if possible, but silently ignored if it fails
/// </summary>
Auto,
/// <summary>
/// The optimization feature is created if possible, but an error is logged if it fails
/// </summary>
On,
/// <summary>
/// The optimization feature is deactivated
/// </summary>
Off,
/// <summary>
/// The optimization feature is created, and the backup is aborted if it fails
/// </summary>
Required
}
/// <summary>
/// The possible settings for the symlink strategy
/// </summary>
public enum SymlinkStrategy
{
/// <summary>
/// Store information about the symlink
/// </summary>
Store,
/// <summary>
/// Treat symlinks as normal files or folders
/// </summary>
Follow,
/// <summary>
/// Ignore all symlinks
/// </summary>
Ignore
}
/// <summary>
/// The possible settings for the hardlink strategy
/// </summary>
public enum HardlinkStrategy
{
/// <summary>
/// Process only the first hardlink
/// </summary>
First,
/// <summary>
/// Process all hardlinks
/// </summary>
All,
/// <summary>
/// Ignore all hardlinks
/// </summary>
None
}
/// <summary>
/// The possible settings for index file usage
/// </summary>
public enum IndexFileStrategy
{
/// <summary>
/// Disables usage of index files
/// </summary>
None,
/// <summary>
/// Stores only block lookup information in the index files
/// </summary>
Lookup,
/// <summary>
/// Stores both block lookup and block lists in the index files
/// </summary>
Full
}
private static string[] GetSupportedHashes()
{
var r = new List<string>();
foreach(var h in new string[] {"SHA1", "MD5", "SHA256", "SHA384", "SHA512"})
try
{
var p = System.Security.Cryptography.HashAlgorithm.Create(h);
if (p != null)
r.Add(h);
}
catch
{
}
return r.ToArray();
}
private static readonly string DEFAULT_COMPRESSED_EXTENSION_FILE = System.IO.Path.Combine(Duplicati.Library.AutoUpdater.UpdaterManager.InstalledBaseDir, "default_compressed_extensions.txt");
/// <summary>
/// Lock that protects the options collection
/// </summary>
protected object m_lock = new object();
protected Dictionary<string, string> m_options;
protected List<KeyValuePair<bool, Library.Interface.IGenericModule>> m_loadedModules = new List<KeyValuePair<bool, IGenericModule>>();
/// <summary>
/// Lookup table for compression hints
/// </summary>
private Dictionary<string, CompressionHint> m_compressionHints;
public Options(Dictionary<string, string> options)
{
m_options = options;
}
public Dictionary<string, string> RawOptions { get { return m_options; } }
/// <summary>
/// Returns a list of strings that are not supported on the commandline as options, but used internally
/// </summary>
public static string[] InternalOptions
{
get
{
return new string[] {
"main-action"
};
}
}
/// <summary>
/// Returns a list of options that are intentionally duplicate
/// </summary>
public static string[] KnownDuplicates
{
get { return new string[] { "auth-password", "auth-username" }; }
}
/// <summary>
/// Gets all commands that effect a backup
/// </summary>
public static string[] BackupOptions
{
get
{
return new string[] {
"dblock-size",
"disable-autocreate-folder",
"disable-filetime-check",
"disable-time-tolerance",
"allow-missing-source",
"skip-files-larger-than",
"upload-unchanged-backups",
"list-verify-uploads",
"control-files",
"snapshot-policy",
"vss-exclude-writers",
"vss-use-mapping",
"usn-policy",
"hyperv-backup-vm",
"symlink-policy",
"hardlink-policy",
"exclude-files-attributes",
"compression-extension-file",
"full-remote-verification"
};
}
}
/// <summary>
/// Gets all options that affect a connection
/// </summary>
public static string[] ConnectionOptions
{
get
{
return new string[] {
"thread-priority",
"number-of-retries",
"retry-delay",
"synchronous-upload",
"asynchronous-upload-limit",
"asynchronous-upload-folder",
"disable-streaming-transfer",
"max-upload-pr-second",
"max-download-pr-second",
"no-connection-reuse",
"allow-sleep"
};
}
}
/// <summary>
/// Gets all options that affect a filename parsing
/// </summary>
public static string[] FilenameOptions
{
get
{
return new string[] {
"prefix",
"tempdir"
};
}
}
/// <summary>
/// Gets all options that can be used for debugging
/// </summary>
public static string[] DebugOptions
{
get
{
return new string[] {
"debug-output",
"debug-retry-errors",
"log-file",
"log-level",
};
}
}
/// <summary>
/// Gets all options that affect module loading
/// </summary>
public static string[] ModuleOptions
{
get
{
return new string[] {
"encryption-module",
"compression-module",
"enable-module",
"disable-module",
"no-encryption"
};
}
}
/// <summary>
/// Gets all options that affect encryption
/// </summary>
public static string[] EncryptionOptions
{
get
{
return new string[] {
"encryption-module",
"passphrase",
"no-encryption"
};
}
}
/// <summary>
/// Gets all options that affect cleanup commands
/// </summary>
public static string[] CleanupOptions
{
get
{
return new string[] {
"dry-run"
};
}
}
/// <summary>
/// Gets all options that affect restore commands
/// </summary>
public static string[] RestoreOptions
{
get
{
return new string[] {
"skip-file-hash-checks",
"dont-read-manifests",
"restore-path",
"time",
"version",
"allow-passphrase-change",
"no-local-db",
"no-local-blocks",
"full-block-verification"
};
}
}
/// <summary>
/// A default backup name
/// </summary>
public static string DefaultBackupName
{
get
{
return System.IO.Path.GetFileNameWithoutExtension(Library.Utility.Utility.getEntryAssembly().Location);
}
}
/// <summary>
/// Gets all supported commands
/// </summary>
public IList<ICommandLineArgument> SupportedCommands
{
get
{
var lst = new List<ICommandLineArgument>(new ICommandLineArgument[] {
new CommandLineArgument("dblock-size", CommandLineArgument.ArgumentType.Size, Strings.Options.DblocksizeShort, Strings.Options.DblocksizeLong, DEFAULT_VOLUME_SIZE),
new CommandLineArgument("auto-cleanup", CommandLineArgument.ArgumentType.Boolean, Strings.Options.AutocleanupShort, Strings.Options.AutocleanupLong, "false"),
new CommandLineArgument("control-files", CommandLineArgument.ArgumentType.Path, Strings.Options.ControlfilesShort, Strings.Options.ControlfilesLong),
new CommandLineArgument("skip-file-hash-checks", CommandLineArgument.ArgumentType.Boolean, Strings.Options.SkipfilehashchecksShort, Strings.Options.SkipfilehashchecksLong, "false"),
new CommandLineArgument("dont-read-manifests", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DontreadmanifestsShort, Strings.Options.DontreadmanifestsLong, "false"),
new CommandLineArgument("restore-path", CommandLineArgument.ArgumentType.String, Strings.Options.RestorepathShort, Strings.Options.RestorepathLong),
new CommandLineArgument("time", CommandLineArgument.ArgumentType.Timespan, Strings.Options.TimeShort, Strings.Options.TimeLong, "now"),
new CommandLineArgument("version", CommandLineArgument.ArgumentType.String, Strings.Options.VersionShort, Strings.Options.VersionLong, ""),
new CommandLineArgument("all-versions", CommandLineArgument.ArgumentType.Boolean, Strings.Options.AllversionsShort, Strings.Options.AllversionsLong, "false"),
new CommandLineArgument("list-prefix-only", CommandLineArgument.ArgumentType.Boolean, Strings.Options.ListprefixonlyShort, Strings.Options.ListprefixonlyLong, "false"),
new CommandLineArgument("list-folder-contents", CommandLineArgument.ArgumentType.Boolean, Strings.Options.ListfoldercontentsShort, Strings.Options.ListfoldercontentsLong, "false"),
new CommandLineArgument("list-sets-only", CommandLineArgument.ArgumentType.Boolean, Strings.Options.ListsetsonlyShort, Strings.Options.ListsetsonlyLong, "false"),
new CommandLineArgument("disable-autocreate-folder", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisableautocreatefolderShort, Strings.Options.DisableautocreatefolderLong, "false"),
new CommandLineArgument("allow-missing-source", CommandLineArgument.ArgumentType.Boolean, Strings.Options.AllowmissingsourceShort, Strings.Options.AllowmissingsourceLong, "false"),
new CommandLineArgument("disable-filetime-check", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisablefiletimecheckShort, Strings.Options.DisablefiletimecheckLong, "false"),
//new CommandLineArgument("disable-usn-diff-check", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisableusndiffcheckShort, Strings.Options.DisableusndiffcheckLong, "false"),
new CommandLineArgument("disable-time-tolerance", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisabletimetoleranceShort, Strings.Options.DisabletimetoleranceLong, "false"),
new CommandLineArgument("tempdir", CommandLineArgument.ArgumentType.Path, Strings.Options.TempdirShort, Strings.Options.TempdirLong, System.IO.Path.GetTempPath()),
new CommandLineArgument("thread-priority", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.ThreadpriorityShort, Strings.Options.ThreadpriorityLong, "normal", null, new string[] {"highest", "high", "abovenormal", "normal", "belownormal", "low", "lowest", "idle" }),
new CommandLineArgument("prefix", CommandLineArgument.ArgumentType.String, Strings.Options.PrefixShort, Strings.Options.PrefixLong, "duplicati"),
new CommandLineArgument("passphrase", CommandLineArgument.ArgumentType.Password, Strings.Options.PassphraseShort, Strings.Options.PassphraseLong),
new CommandLineArgument("no-encryption", CommandLineArgument.ArgumentType.Boolean, Strings.Options.NoencryptionShort, Strings.Options.NoencryptionLong, "false"),
new CommandLineArgument("number-of-retries", CommandLineArgument.ArgumentType.Integer, Strings.Options.NumberofretriesShort, Strings.Options.NumberofretriesLong, "5"),
new CommandLineArgument("retry-delay", CommandLineArgument.ArgumentType.Timespan, Strings.Options.RetrydelayShort, Strings.Options.RetrydelayLong, "10s"),
new CommandLineArgument("synchronous-upload", CommandLineArgument.ArgumentType.Boolean, Strings.Options.SynchronousuploadShort, Strings.Options.SynchronousuploadLong, "false"),
new CommandLineArgument("asynchronous-upload-limit", CommandLineArgument.ArgumentType.Integer, Strings.Options.AsynchronousuploadlimitShort, Strings.Options.AsynchronousuploadlimitLong, "4"),
new CommandLineArgument("asynchronous-upload-folder", CommandLineArgument.ArgumentType.Path, Strings.Options.AsynchronousuploadfolderShort, Strings.Options.AsynchronousuploadfolderLong, System.IO.Path.GetTempPath()),
new CommandLineArgument("disable-streaming-transfers", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisableStreamingShort, Strings.Options.DisableStreamingLong, "false"),
new CommandLineArgument("throttle-upload", CommandLineArgument.ArgumentType.Size, Strings.Options.ThrottleuploadShort, Strings.Options.ThrottleuploadLong, "0kb"),
new CommandLineArgument("throttle-download", CommandLineArgument.ArgumentType.Size, Strings.Options.ThrottledownloadShort, Strings.Options.ThrottledownloadLong, "0kb"),
new CommandLineArgument("skip-files-larger-than", CommandLineArgument.ArgumentType.Size, Strings.Options.SkipfileslargerthanShort, Strings.Options.SkipfileslargerthanLong),
new CommandLineArgument("upload-unchanged-backups", CommandLineArgument.ArgumentType.Boolean, Strings.Options.UploadUnchangedBackupsShort, Strings.Options.UploadUnchangedBackupsLong, "false"),
new CommandLineArgument("snapshot-policy", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.SnapshotpolicyShort, Strings.Options.SnapshotpolicyLong, "off", null, Enum.GetNames(typeof(OptimizationStrategy))),
new CommandLineArgument("vss-exclude-writers", CommandLineArgument.ArgumentType.String, Strings.Options.VssexcludewritersShort, Strings.Options.VssexcludewritersLong),
new CommandLineArgument("vss-use-mapping", CommandLineArgument.ArgumentType.Boolean, Strings.Options.VssusemappingShort, Strings.Options.VssusemappingLong, "false"),
new CommandLineArgument("usn-policy", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.UsnpolicyShort, Strings.Options.UsnpolicyLong, "off", null, Enum.GetNames(typeof(OptimizationStrategy))),
new CommandLineArgument("encryption-module", CommandLineArgument.ArgumentType.String, Strings.Options.EncryptionmoduleShort, Strings.Options.EncryptionmoduleLong, "aes"),
new CommandLineArgument("compression-module", CommandLineArgument.ArgumentType.String, Strings.Options.CompressionmoduleShort, Strings.Options.CompressionmoduleLong, "zip"),
new CommandLineArgument("enable-module", CommandLineArgument.ArgumentType.String, Strings.Options.EnablemoduleShort, Strings.Options.EnablemoduleLong),
new CommandLineArgument("disable-module", CommandLineArgument.ArgumentType.String, Strings.Options.DisablemoduleShort, Strings.Options.DisablemoduleLong),
new CommandLineArgument("debug-output", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DebugoutputShort, Strings.Options.DebugoutputLong, "false"),
new CommandLineArgument("debug-retry-errors", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DebugretryerrorsShort, Strings.Options.DebugretryerrorsLong, "false"),
new CommandLineArgument("log-file", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Path, Strings.Options.LogfileShort, Strings.Options.LogfileShort),
new CommandLineArgument("log-level", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Enumeration, Strings.Options.LoglevelShort, Strings.Options.LoglevelLong, "Warning", null, Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType))),
new CommandLineArgument("list-verify-uploads", CommandLineArgument.ArgumentType.Boolean, Strings.Options.ListverifyuploadsShort, Strings.Options.ListverifyuploadsShort, "false"),
new CommandLineArgument("allow-sleep", CommandLineArgument.ArgumentType.Boolean, Strings.Options.AllowsleepShort, Strings.Options.AllowsleepLong, "false"),
new CommandLineArgument("no-connection-reuse", CommandLineArgument.ArgumentType.Boolean, Strings.Options.NoconnectionreuseShort, Strings.Options.NoconnectionreuseLong, "false"),
new CommandLineArgument("quota-size", CommandLineArgument.ArgumentType.Size, Strings.Options.QuotasizeShort, Strings.Options.QuotasizeLong),
new CommandLineArgument("symlink-policy", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.SymlinkpolicyShort, Strings.Options.SymlinkpolicyLong("store", "ignore", "follow"), Enum.GetName(typeof(SymlinkStrategy), SymlinkStrategy.Store), null, Enum.GetNames(typeof(SymlinkStrategy))),
new CommandLineArgument("hardlink-policy", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.HardlinkpolicyShort, Strings.Options.HardlinkpolicyLong("first", "all", "none"), Enum.GetName(typeof(HardlinkStrategy), HardlinkStrategy.All), null, Enum.GetNames(typeof(HardlinkStrategy))),
new CommandLineArgument("exclude-files-attributes", CommandLineArgument.ArgumentType.String, Strings.Options.ExcludefilesattributesShort, Strings.Options.ExcludefilesattributesLong(Enum.GetNames(typeof(System.IO.FileAttributes)))),
new CommandLineArgument("backup-name", CommandLineArgument.ArgumentType.String, Strings.Options.BackupnameShort, Strings.Options.BackupnameLong, DefaultBackupName),
new CommandLineArgument("compression-extension-file", CommandLineArgument.ArgumentType.Path, Strings.Options.CompressionextensionfileShort, Strings.Options.CompressionextensionfileLong(DEFAULT_COMPRESSED_EXTENSION_FILE), DEFAULT_COMPRESSED_EXTENSION_FILE),
new CommandLineArgument("verbose", CommandLineArgument.ArgumentType.Boolean, Strings.Options.VerboseShort, Strings.Options.VerboseLong, "false"),
new CommandLineArgument("overwrite", CommandLineArgument.ArgumentType.Boolean, Strings.Options.OverwriteShort, Strings.Options.OverwriteLong, "false"),
new CommandLineArgument("dbpath", CommandLineArgument.ArgumentType.Path, Strings.Options.DbpathShort, Strings.Options.DbpathLong),
new CommandLineArgument("blocksize", CommandLineArgument.ArgumentType.Size, Strings.Options.BlocksizeShort, Strings.Options.BlocksizeLong, DEFAULT_BLOCKSIZE),
new CommandLineArgument("file-read-buffer-size", CommandLineArgument.ArgumentType.Size, Strings.Options.FilereadbuffersizeShort, Strings.Options.FilereadbuffersizeLong, "0kb"),
new CommandLineArgument("store-metadata", CommandLineArgument.ArgumentType.Boolean, Strings.Options.StoremetadataShort, Strings.Options.StoremetadataLong, "true", null, null, Strings.Options.StoremetadataDeprecated),
new CommandLineArgument("skip-metadata", CommandLineArgument.ArgumentType.Boolean, Strings.Options.SkipmetadataShort, Strings.Options.SkipmetadataLong, "false"),
new CommandLineArgument("restore-permissions", CommandLineArgument.ArgumentType.Boolean, Strings.Options.RestorepermissionsShort, Strings.Options.RestorepermissionsLong, "false"),
new CommandLineArgument("skip-restore-verification", CommandLineArgument.ArgumentType.Boolean, Strings.Options.SkiprestoreverificationShort, Strings.Options.SkiprestoreverificationLong, "false"),
new CommandLineArgument("blockhash-lookup-memory", CommandLineArgument.ArgumentType.Size, Strings.Options.BlockhashlookupsizeShort, Strings.Options.BlockhashlookupsizeLong, "0mb"),
new CommandLineArgument("filehash-lookup-memory", CommandLineArgument.ArgumentType.Size, Strings.Options.FilehashlookupsizeShort, Strings.Options.FilehashlookupsizeLong, "0mb"),
new CommandLineArgument("metadatahash-lookup-memory", CommandLineArgument.ArgumentType.Size, Strings.Options.MetadatahashlookupsizeShort, Strings.Options.MetadatahashlookupsizeLong, "0mb"),
new CommandLineArgument("old-lookup-memory-defaults", CommandLineArgument.ArgumentType.Size, Strings.Options.OldmemorylookupdefaultsShort, Strings.Options.OldmemorylookupdefaultsLong, "false"),
new CommandLineArgument("disable-filepath-cache", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisablefilepathcacheShort, Strings.Options.DisablefilepathcacheLong, "true"),
new CommandLineArgument("changed-files", CommandLineArgument.ArgumentType.Path, Strings.Options.ChangedfilesShort, Strings.Options.ChangedfilesLong),
new CommandLineArgument("deleted-files", CommandLineArgument.ArgumentType.Path, Strings.Options.DeletedfilesShort, Strings.Options.DeletedfilesLong("changed-files")),
new CommandLineArgument("threshold", CommandLineArgument.ArgumentType.Integer, Strings.Options.ThresholdShort, Strings.Options.ThresholdLong, DEFAULT_THRESHOLD.ToString()),
new CommandLineArgument("index-file-policy", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.IndexfilepolicyShort, Strings.Options.IndexfilepolicyLong, IndexFileStrategy.Full.ToString(), null, Enum.GetNames(typeof(IndexFileStrategy))),
new CommandLineArgument("no-backend-verification", CommandLineArgument.ArgumentType.Boolean, Strings.Options.NobackendverificationShort, Strings.Options.NobackendverificationLong, "false"),
new CommandLineArgument("backup-test-samples", CommandLineArgument.ArgumentType.Integer, Strings.Options.BackendtestsamplesShort, Strings.Options.BackendtestsamplesLong("no-backend-verification"), "1"),
new CommandLineArgument("full-remote-verification", CommandLineArgument.ArgumentType.Boolean, Strings.Options.FullremoteverificationShort, Strings.Options.FullremoteverificationLong("no-backend-verification"), "false"),
new CommandLineArgument("dry-run", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DryrunShort, Strings.Options.DryrunLong, "false", new string[] { "dryrun" }),
new CommandLineArgument("block-hash-algorithm", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.BlockhashalgorithmShort, Strings.Options.BlockhashalgorithmLong, DEFAULT_BLOCK_HASH_ALGORITHM, null, GetSupportedHashes()),
new CommandLineArgument("file-hash-algorithm", CommandLineArgument.ArgumentType.Enumeration, Strings.Options.FilehashalgorithmShort, Strings.Options.FilehashalgorithmLong, DEFAULT_FILE_HASH_ALGORITHM, null, GetSupportedHashes()),
new CommandLineArgument("no-auto-compact", CommandLineArgument.ArgumentType.Boolean, Strings.Options.NoautocompactShort, Strings.Options.NoautocompactLong, "false"),
new CommandLineArgument("small-file-size", CommandLineArgument.ArgumentType.Size, Strings.Options.SmallfilesizeShort, Strings.Options.SmallfilesizeLong),
new CommandLineArgument("small-file-max-count", CommandLineArgument.ArgumentType.Size, Strings.Options.SmallfilemaxcountShort, Strings.Options.SmallfilemaxcountLong, DEFAULT_SMALL_FILE_MAX_COUNT.ToString()),
new CommandLineArgument("patch-with-local-blocks", CommandLineArgument.ArgumentType.Boolean, Strings.Options.PatchwithlocalblocksShort, Strings.Options.PatchwithlocalblocksLong, "false"),
new CommandLineArgument("no-local-db", CommandLineArgument.ArgumentType.Boolean, Strings.Options.NolocaldbShort, Strings.Options.NolocaldbLong, "false"),
new CommandLineArgument("keep-versions", CommandLineArgument.ArgumentType.Integer, Strings.Options.KeepversionsShort, Strings.Options.KeepversionsLong, DEFAULT_KEEP_VERSIONS.ToString()),
new CommandLineArgument("keep-time", CommandLineArgument.ArgumentType.Timespan, Strings.Options.KeeptimeShort, Strings.Options.KeeptimeLong),
new CommandLineArgument("upload-verification-file", CommandLineArgument.ArgumentType.Boolean, Strings.Options.UploadverificationfileShort, Strings.Options.UploadverificationfileLong, "false"),
new CommandLineArgument("allow-passphrase-change", CommandLineArgument.ArgumentType.Boolean, Strings.Options.AllowpassphrasechangeShort, Strings.Options.AllowpassphrasechangeLong, "false"),
new CommandLineArgument("no-local-blocks", CommandLineArgument.ArgumentType.Boolean, Strings.Options.NolocalblocksShort, Strings.Options.NolocalblocksLong, "false"),
new CommandLineArgument("full-block-verification", CommandLineArgument.ArgumentType.Boolean, Strings.Options.FullblockverificationShort, Strings.Options.FullblockverificationLong, "false"),
new CommandLineArgument("log-retention", CommandLineArgument.ArgumentType.Timespan, Strings.Options.LogretentionShort, Strings.Options.LogretentionLong, DEFAULT_LOG_RETENTION),
new CommandLineArgument("repair-only-paths", CommandLineArgument.ArgumentType.Boolean, Strings.Options.RepaironlypathsShort, Strings.Options.RepaironlypathsLong, "false"),
new CommandLineArgument("force-locale", CommandLineArgument.ArgumentType.String, Strings.Options.ForcelocaleShort, Strings.Options.ForcelocaleLong),
new CommandLineArgument("disable-piped-streaming", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DisablepipingShort, Strings.Options.DisablepipingLong, "false"),
});
return lst;
}
}
/// <summary>
/// Gets or sets the current main action of the instance
/// </summary>
public OperationMode MainAction
{
get { return (OperationMode)Enum.Parse(typeof(OperationMode), m_options["main-action"]); }
set { m_options["main-action"] = value.ToString(); }
}
/// <summary>
/// Gets the size of each volume in bytes
/// </summary>
public long VolumeSize
{
get
{
string volsize;
m_options.TryGetValue("dblock-size", out volsize);
if (string.IsNullOrEmpty(volsize))
volsize = DEFAULT_VOLUME_SIZE;
#if DEBUG
return Math.Max(1024 * 10, Library.Utility.Sizeparser.ParseSize(volsize, "mb"));
#else
return Math.Max(1024 * 1024, Library.Utility.Sizeparser.ParseSize(volsize, "mb"));
#endif
}
}
/// <summary>
/// Gets the maximum size of a single file
/// </summary>
public long SkipFilesLargerThan
{
get
{
if (!m_options.ContainsKey("skip-files-larger-than") || string.IsNullOrEmpty(m_options["skip-files-larger-than"]))
return long.MaxValue;
else
return Library.Utility.Sizeparser.ParseSize(m_options["skip-files-larger-than"], "mb");
}
}
/// <summary>
/// A value indicating if orphan files are deleted automatically
/// </summary>
public bool AutoCleanup { get { return GetBool("auto-cleanup"); } }
/// <summary>
/// Gets a list of files to add to the signature volumes
/// </summary>
public string ControlFiles
{
get
{
string v;
m_options.TryGetValue("control-files", out v);
return v;
}
}
/// <summary>
/// A value indicating if file hash checks are skipped
/// </summary>
public bool SkipFileHashChecks { get { return GetBool("skip-file-hash-checks"); } }
/// <summary>
/// A value indicating if the manifest files are not read
/// </summary>
public bool DontReadManifests { get { return GetBool("dont-read-manifests"); } }
/// <summary>
/// Gets the backup that should be restored
/// </summary>
public DateTime Time
{
get
{
if (!m_options.ContainsKey("time") || string.IsNullOrEmpty(m_options["time"]))
return new DateTime(0, DateTimeKind.Utc);
else
return Library.Utility.Timeparser.ParseTimeInterval(m_options["time"], DateTime.Now);
}
}
/// <summary>
/// Gets the versions the restore or list operation is limited to
/// </summary>
public long[] Version
{
get
{
string v;
m_options.TryGetValue("version", out v);
if (string.IsNullOrEmpty(v))
return null;
var versions = v.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
if (v.Length == 0)
return null;
var res = new List<long>();
foreach(var n in versions)
if (n.Contains('-'))
{
//TODO: Throw errors if too many entries?
var parts = n.Split(new char[]{'-'}, StringSplitOptions.RemoveEmptyEntries).Select(x => Convert.ToInt64(x.Trim())).ToArray();
for(var i = Math.Min(parts[0], parts[1]); i <= Math.Max(parts[0], parts[1]); i++)
res.Add(i);
}
else
res.Add(Convert.ToInt64(n));
return res.ToArray();
}
}
/// <summary>
/// A value indicating if all versions are listed
/// </summary>
public bool AllVersions { get { return GetBool("all-versions"); } }
/// <summary>
/// A value indicating if only the largest common prefix is returned
/// </summary>
public bool ListPrefixOnly { get { return GetBool("list-prefix-only"); } }
/// <summary>
/// A value indicating if only folder contents are returned
/// </summary>
public bool ListFolderContents { get { return GetBool("list-folder-contents"); } }
/// <summary>
/// A value indicating that only filesets are returned
/// </summary>
public bool ListSetsOnly { get { return GetBool("list-sets-only"); } }
/// <summary>
/// A value indicating if file time checks are skipped
/// </summary>
public bool DisableFiletimeCheck { get { return GetBool("disable-filetime-check"); } }
/// <summary>
/// A value indicating if USN numbers are used to get list of changed files
/// </summary>
//public bool DisableUSNDiffCheck { get { return GetBool("disable-usn-diff-check"); } }
/// <summary>
/// A value indicating if time tolerance is disabled
/// </summary>
public bool DisableTimeTolerance { get { return GetBool("disable-time-tolerance"); } }
/// <summary>
/// Gets a value indicating whether a temporary folder has been specified
/// </summary>
public bool HasTempDir { get { return m_options.ContainsKey("tempdir") && !string.IsNullOrEmpty(m_options["tempdir"]); } }
/// <summary>
/// Gets the folder where temporary files are stored
/// </summary>
public string TempDir
{
get
{
if (!m_options.ContainsKey("tempdir") || string.IsNullOrEmpty(m_options["tempdir"]))
return System.IO.Path.GetTempPath();
else
return m_options["tempdir"];
}
}
/// <summary>
/// Gets a value indicating whether the user has forced the locale
/// </summary>
public bool HasForcedLocale { get { return m_options.ContainsKey("force-locale"); } }
/// <summary>
/// Gets the forced locale for the current user
/// </summary>
public System.Globalization.CultureInfo ForcedLocale
{
get
{
if (!m_options.ContainsKey("force-locale"))
return System.Threading.Thread.CurrentThread.CurrentCulture;
else
{
var localestring = m_options["force-locale"];
if (string.IsNullOrWhiteSpace(localestring))
return System.Globalization.CultureInfo.InvariantCulture;
else
return new System.Globalization.CultureInfo(localestring);
}
}
}
/// <summary>
/// Gets the process priority
/// </summary>
public string ThreadPriority
{
get
{
if (!m_options.ContainsKey("thread-priority") || string.IsNullOrEmpty(m_options["thread-priority"]))
return null;
else
return m_options["thread-priority"];
}
}
/// <summary>
/// A value indicating if missing folders should be created automatically
/// </summary>
public bool AutocreateFolders { get { return !GetBool("disable-autocreate-folder"); } }
/// <summary>
/// Gets the backup prefix
/// </summary>
public string Prefix
{
get
{
string v;
m_options.TryGetValue("prefix", out v);
if (!string.IsNullOrEmpty(v))
return v;
return "duplicati";
}
}
/// <summary>
/// Gets the number of old backups to keep
/// </summary>
public int KeepVersions
{
get
{
string v;
m_options.TryGetValue("keep-versions", out v);
if (string.IsNullOrEmpty(v))
return DEFAULT_KEEP_VERSIONS;
return Math.Max(0, int.Parse(v));
}
}
/// <summary>
/// Gets the timelimit for removal
/// </summary>
public DateTime KeepTime
{
get
{
string v;
m_options.TryGetValue("keep-time", out v);
if (string.IsNullOrEmpty(v))
return new DateTime(0);
TimeSpan tolerance =
this.DisableTimeTolerance ?
TimeSpan.FromSeconds(0) :
TimeSpan.FromSeconds(Math.Min(Library.Utility.Timeparser.ParseTimeSpan(v).TotalSeconds / 100, 60.0 * 60.0));
return Library.Utility.Timeparser.ParseTimeInterval(v, DateTime.Now, true) - tolerance;
}
}
/// <summary>
/// Gets the filesets selected for deletion
/// </summary>
/// <returns>The filesets to delete</returns>
/// <param name="backups">The list of backups that can be deleted</param>
public DateTime[] GetFilesetsToDelete (DateTime[] backups)
{
if (backups.Length == 0)
return backups;
List<DateTime> res = new List<DateTime>();
var versions = this.Version;
if (versions != null && versions.Length > 0)
foreach (var ix in versions.Distinct())
if (ix >= 0 && ix < backups.Length)
res.Add(backups[ix]);
var keepVersions = this.KeepVersions;
if (keepVersions > 0 && keepVersions < backups.Length)
res.AddRange(backups.Skip(keepVersions));
var keepTime = this.KeepTime;
if (keepTime.Ticks > 0)
res.AddRange(backups.SkipWhile(x => x >= keepTime));
var filtered = res.Distinct().OrderByDescending(x => x).AsEnumerable();
var removeCount = filtered.Count();
if (removeCount >= backups.Length)
filtered = filtered.Skip(removeCount - backups.Length + (AllowFullRemoval ? 0 : 1));
return filtered.ToArray();
}
/// <summary>
/// Gets the encryption passphrase
/// </summary>
public string Passphrase
{
get
{
if (!m_options.ContainsKey("passphrase") || string.IsNullOrEmpty(m_options["passphrase"]))
return null;
else
return m_options["passphrase"];
}
}
/// <summary>
/// Helper method to set the default encryption mode based on the settings of the previous backup
/// </summary>
/// <param name="lastSetting">The encryption module used for the last entry</param>
public void SetEncryptionModuleDefault(string lastSetting)
{
//If the encryption module was specified explicitly, don't change it
if (m_options.ContainsKey("no-encryption") || m_options.ContainsKey("encryption-module"))
return;
if (string.IsNullOrEmpty(lastSetting))
m_options["no-encryption"] = "";
else
m_options["encryption-module"] = lastSetting;
}
/// <summary>
/// A value indicating if backups are not encrypted
/// </summary>
public bool NoEncryption { get { return GetBool("no-encryption"); } }
/// <summary>
/// Gets the module used for encryption
/// </summary>
public string EncryptionModule
{
get
{
//Disabled?
if (NoEncryption)
return null;
//Specified?
if (m_options.ContainsKey("encryption-module"))
return m_options["encryption-module"];
return "aes";
}
}
/// <summary>
/// Helper method to set the default compression mode based on the settings of the previous backup
/// </summary>
/// <param name="lastSetting">The compression module used for the last entry</param>
public void SetCompressionModuleDefault(string lastSetting)
{
//If a compression module is explicitly selected, don't change it
if (m_options.ContainsKey("compression-module"))
return;
m_options["compression-module"] = lastSetting;
}
/// <summary>
/// Gets the module used for compression
/// </summary>
public string CompressionModule
{
get
{
if (m_options.ContainsKey("compression-module"))
return m_options["compression-module"];
else
return "zip";
}
}
/// <summary>
/// Gets the number of time to retry transmission if it fails
/// </summary>
public int NumberOfRetries
{
get
{
if (!m_options.ContainsKey("number-of-retries") || string.IsNullOrEmpty(m_options["number-of-retries"]))
return 5;
else
{
int x = int.Parse(m_options["number-of-retries"]);
if (x < 0)
throw new Exception("Invalid count for number-of-retries");
return x;
}
}
}
/// <summary>
/// A value indicating if backups are transmitted on a separate thread
/// </summary>
public bool SynchronousUpload { get { return Library.Utility.Utility.ParseBoolOption(m_options, "synchronous-upload"); } }
/// <summary>
/// A value indicating if system is allowed to enter sleep power states during backup/restore ops (win32 only)
/// </summary>
public bool AllowSleep { get { return GetBool("allow-sleep"); } }
/// <summary>
/// A value indicating if use of the streaming interface is disallowed
/// </summary>
public bool DisableStreamingTransfers { get { return GetBool("disable-streaming-transfers"); } }
/// <summary>
/// A value indicating if multithreaded pipes may be used for hashing and crypting on up-/downloads
/// </summary>
public bool DisablePipedStreaming { get { return GetBool("disable-piped-streaming"); } }
/// <summary>
/// Gets the timelimit for removal
/// </summary>
public TimeSpan RetryDelay
{
get
{
if (!m_options.ContainsKey("retry-delay") || string.IsNullOrEmpty(m_options["retry-delay"]))
return new TimeSpan(TimeSpan.TicksPerSecond * 10);
else
return Library.Utility.Timeparser.ParseTimeSpan(m_options["retry-delay"]);
}
}
/// <summary>
/// Gets the max upload speed in bytes pr. second
/// </summary>
public long MaxUploadPrSecond
{
get
{
lock(m_lock)
{
string v;
m_options.TryGetValue("throttle-upload", out v);
if (string.IsNullOrEmpty(v))
return 0;
else
return Library.Utility.Sizeparser.ParseSize(v, "kb");
}
}
set
{
lock (m_lock)
if (value <= 0)
m_options["throttle-upload"] = "";
else
m_options["throttle-upload"] = value.ToString() + "b";
}
}
/// <summary>
/// Gets or sets the max download speed in bytes pr. second
/// </summary>
public long MaxDownloadPrSecond
{
get
{
lock (m_lock)
{
string v;
m_options.TryGetValue("throttle-download", out v);
if (string.IsNullOrEmpty(v))
return 0;
else
return Library.Utility.Sizeparser.ParseSize(v, "kb");
}
}
set
{
lock (m_lock)
if (value <= 0)
m_options["throttle-download"] = "";
else
m_options["throttle-download"] = value.ToString() + "b";
}
}
/// <summary>
/// A value indicating if the backup is a full backup
/// </summary>
public bool AllowFullRemoval { get { return GetBool("allow-full-removal"); } }
/// <summary>
/// A value indicating if debug output is enabled
/// </summary>
public bool DebugOutput { get { return GetBool("debug-output"); } }
/// <summary>
/// A value indicating if unchanged backups are uploaded
/// </summary>
public bool UploadUnchangedBackups { get { return GetBool("upload-unchanged-backups"); } }
/// <summary>
/// Gets a list of modules that should be loaded
/// </summary>
public string[] EnableModules
{
get
{
if (m_options.ContainsKey("enable-module"))
return m_options["enable-module"].Trim().ToLower().Split(',');
else
return new string[0];
}
}
/// <summary>
/// Gets a list of modules that should not be loaded
/// </summary>
public string[] DisableModules
{
get
{
if (m_options.ContainsKey("disable-module"))
return m_options["disable-module"].Trim().ToLower().Split(',');
else
return new string[0];
}
}
/// <summary>
/// Gets the snapshot strategy to use
/// </summary>
public OptimizationStrategy SnapShotStrategy
{
get
{
string strategy;
if (!m_options.TryGetValue("snapshot-policy", out strategy))
strategy = "";
if (string.Equals(strategy, "on", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.On;
else if (string.Equals(strategy, "off", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.Off;
else if (string.Equals(strategy, "required", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.Required;
else if (string.Equals(strategy, "auto", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.Auto;
else
return OptimizationStrategy.Off;
}
}
/// <summary>
/// Gets the symlink strategy to use
/// </summary>
public SymlinkStrategy SymlinkPolicy
{
get
{
string policy;
if (!m_options.TryGetValue("symlink-policy", out policy))
policy = "";
SymlinkStrategy r;
if (!Enum.TryParse(policy, true, out r))
r = SymlinkStrategy.Store;
return r;
}
}
/// <summary>
/// Gets the hardlink strategy to use
/// </summary>
public HardlinkStrategy HardlinkPolicy
{
get
{
string policy;
if (!m_options.TryGetValue("hardlink-policy", out policy))
policy = "";
HardlinkStrategy r;
if (!Enum.TryParse(policy, true, out r))
r = HardlinkStrategy.All;
return r;
}
}
/// <summary>
/// Gets the snapshot strategy to use
/// </summary>
public OptimizationStrategy UsnStrategy
{
get
{
string strategy;
if (!m_options.TryGetValue("usn-policy", out strategy))
strategy = "";
if (string.Equals(strategy, "on", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.On;
else if (string.Equals(strategy, "off", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.Off;
else if (string.Equals(strategy, "required", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.Required;
else if (string.Equals(strategy, "auto", StringComparison.InvariantCultureIgnoreCase))
return OptimizationStrategy.Auto;
else
return OptimizationStrategy.Off;
}
}
/// <summary>
/// Gets the number of volumes to create ahead of time when using async transfers,
/// a value of zero indicates no limit
/// </summary>
public long AsynchronousUploadLimit
{
get
{
string value;
if (!m_options.TryGetValue("asynchronous-upload-limit", out value))
value = null;
if (string.IsNullOrEmpty(value))
return 4;
else
return long.Parse(value);
}
}
/// <summary>
/// Gets the temporary folder to use for asyncronous transfers
/// </summary>
public string AsynchronousUploadFolder
{
get
{
string value;
if (!m_options.TryGetValue("asynchronous-upload-folder", out value))
value = null;
if (string.IsNullOrEmpty(value))
return this.TempDir;
else
return value;
}
}
/// <summary>
/// Gets the logfile filename
/// </summary>
public string Logfile
{
get
{
string value;
if (!m_options.TryGetValue("log-file", out value))
value = null;
return value;
}
}
/// <summary>
/// Gets a value indicating if the log level has been set
/// </summary>
public bool HasLoglevel
{
get
{
string value;
if (!m_options.TryGetValue("log-level", out value))
value = null;
foreach (string s in Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType)))
if (s.Equals(value, StringComparison.InvariantCultureIgnoreCase))
return true;
return false;
}
}
/// <summary>
/// Gets the log detail level
/// </summary>
public Duplicati.Library.Logging.LogMessageType Loglevel
{
get
{
string value;
if (!m_options.TryGetValue("log-level", out value))
value = null;
foreach (string s in Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType)))
if (s.Equals(value, StringComparison.InvariantCultureIgnoreCase))
return (Duplicati.Library.Logging.LogMessageType)Enum.Parse(typeof(Duplicati.Library.Logging.LogMessageType), s);
return Duplicati.Library.Logging.LogMessageType.Warning;
}
}
/// <summary>
/// Gets the attribute filter used to exclude files and folders.
/// </summary>
public System.IO.FileAttributes FileAttributeFilter
{
get
{
System.IO.FileAttributes res = (System.IO.FileAttributes)0;
string v;
if (!m_options.TryGetValue("exclude-files-attributes", out v))
return res;
foreach(string s in v.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries))
{
System.IO.FileAttributes f;
if (Enum.TryParse(s.Trim(), true, out f))
res |= f;
}
return res;
}
}
/// <summary>
/// A value indicating if server uploads are verified by listing the folder contents
/// </summary>
public bool ListVerifyUploads { get { return GetBool("list-verify-uploads"); } }
/// <summary>
/// A value indicating if connections cannot be re-used
/// </summary>
public bool NoConnectionReuse { get { return GetBool("no-connection-reuse"); } }
/// <summary>
/// A value indicating if the output should be verbose
/// </summary>
public bool Verbose { get { return GetBool("verbose"); } }
/// <summary>
/// A value indicating restored files overwrite existing ones
/// </summary>
public bool Overwrite { get { return GetBool("overwrite"); } }
/// <summary>
/// Gets the total size in bytes that the backend supports, returns -1 if there is no upper limit
/// </summary>
public long QuotaSize
{
get
{
if (!m_options.ContainsKey("quota-size") || string.IsNullOrEmpty(m_options["quota-size"]))
return -1;
else
return Library.Utility.Sizeparser.ParseSize(m_options["quota-size"], "mb");
}
}
/// <summary>
/// Gets the display name of the backup
/// </summary>
public string BackupName
{
get
{
string tmp;
m_options.TryGetValue("backup-name", out tmp);
if (string.IsNullOrEmpty(tmp))
return DefaultBackupName;
else
return tmp;
}
set
{
m_options["backup-name"] = value;
}
}
/// <summary>
/// Gets the path to the database
/// </summary>
public string Dbpath
{
get
{
string tmp;
m_options.TryGetValue("dbpath", out tmp);
return tmp;
}
set
{
m_options["dbpath"] = value;
}
}
/// <summary>
/// Gets the size of file-blocks
/// </summary>
public int Blocksize
{
get
{
string tmp;
if (!m_options.TryGetValue("blocksize", out tmp))
tmp = DEFAULT_BLOCKSIZE;
long t = Library.Utility.Sizeparser.ParseSize(tmp, "kb");
if (t > int.MaxValue || t < 1024)
throw new ArgumentOutOfRangeException("blocksize", string.Format("The blocksize cannot be less than {0}, nor larger than {1}", 1024, int.MaxValue));
return (int)t;
}
}
/// <summary>
/// Gets the size of the blockhash.
/// </summary>
/// <value>The size of the blockhash.</value>
public int BlockhashSize
{
get
{
return System.Security.Cryptography.HashAlgorithm.Create(BlockHashAlgorithm).HashSize / 8;
}
}
/// <summary>
/// Gets the size the read-ahead buffer
/// </summary>
public long FileReadBufferSize
{
get
{
string tmp;
if (!m_options.TryGetValue("file-read-buffer-size", out tmp))
tmp = DEFAULT_READ_BUFFER_SIZE;
long t = Library.Utility.Sizeparser.ParseSize(tmp, "mb");
return (int)t;
}
}
/// <summary>
/// Gets a flag indicating if metadata for files and folders should be ignored
/// </summary>
public bool StoreMetadata
{
get
{
if (m_options.ContainsKey("skip-metadata"))
return !Library.Utility.Utility.ParseBoolOption(m_options, "skip-metadata");
if (m_options.ContainsKey("store-metadata"))
return Library.Utility.Utility.ParseBoolOption(m_options, "store-metadata");
return true;
}
}
/// <summary>
/// Gets a flag indicating if metadata for files and folders should be ignored
/// </summary>
public bool SkipMetadata
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "skip-metadata"); }
}
/// <summary>
/// Gets a flag indicating if permissions should be restored
/// </summary>
public bool RestorePermissions
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "restore-permissions"); }
}
/// <summary>
/// Gets a flag indicating if file hashes are checked after a restore
/// </summary>
public bool PerformRestoredFileVerification
{
get { return !Library.Utility.Utility.ParseBoolOption(m_options, "skip-restore-verification"); }
}
/// <summary>
/// Gets a flag indicating whether this <see cref="Duplicati.Library.Main.Options"/> old memory defaults.
/// </summary>
public bool OldMemoryDefaults
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "old-lookup-memory-defaults"); }
}
/// <summary>
/// Gets the block hash lookup size
/// </summary>
public long BlockHashLookupMemory
{
get
{
string v;
m_options.TryGetValue("blockhash-lookup-memory", out v);
if (string.IsNullOrEmpty(v))
v = OldMemoryDefaults ? DEFAULT_BLOCK_HASH_LOOKUP_SIZE : "0";
return Library.Utility.Sizeparser.ParseSize(v, "mb");
}
}
/// <summary>
/// Gets the file hash size
/// </summary>
public long FileHashLookupMemory
{
get
{
string v;
m_options.TryGetValue("filehash-lookup-memory", out v);
if (string.IsNullOrEmpty(v))
v = OldMemoryDefaults ? DEFAULT_FILE_HASH_LOOKUP_SIZE : "0";
return Library.Utility.Sizeparser.ParseSize(v, "mb");
}
}
/// <summary>
/// Gets the block hash size
/// </summary>
public long MetadataHashMemory
{
get
{
string v;
m_options.TryGetValue("metadatahash-lookup-memory", out v);
if (string.IsNullOrEmpty(v))
v = OldMemoryDefaults ? DEFAULT_METADATA_HASH_LOOKUP_SIZE : "0";
return Library.Utility.Sizeparser.ParseSize(v, "mb");
}
}
/// <summary>
/// Gets the file hash size
/// </summary>
public bool UseFilepathCache
{
get
{
if (OldMemoryDefaults)
return !Library.Utility.Utility.ParseBoolOption(m_options, "disable-filepath-cache");
else
{
string s;
m_options.TryGetValue("disable-filepath-cache", out s);
return !Library.Utility.Utility.ParseBool(s, true);
}
}
}
/// <summary>
/// Gets the compact threshold
/// </summary>
public long Threshold
{
get
{
string v;
m_options.TryGetValue("threshold", out v);
if (string.IsNullOrEmpty(v))
return DEFAULT_THRESHOLD;
return Convert.ToInt64(v);
}
}
/// <summary>
/// Gets the size of small volumes
/// </summary>
public long SmallFileSize
{
get
{
string v;
m_options.TryGetValue("small-file-size", out v);
if (string.IsNullOrEmpty(v))
return this.VolumeSize / 5;
return Library.Utility.Sizeparser.ParseSize(v, "mb");
}
}
/// <summary>
/// Gets the maximum number of small volumes
/// </summary>
public long SmallFileMaxCount
{
get
{
string v;
m_options.TryGetValue("small-file-max-count", out v);
if (string.IsNullOrEmpty(v))
return DEFAULT_SMALL_FILE_MAX_COUNT;
return Convert.ToInt64(v);
}
}
/// <summary>
/// List of files to check for changes
/// </summary>
public string[] ChangedFilelist
{
get
{
string v;
m_options.TryGetValue("changed-files", out v);
if (string.IsNullOrEmpty(v))
return null;
return v.Split(new char[] { System.IO.Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
}
}
/// <summary>
/// List of files to mark as deleted
/// </summary>
public string[] DeletedFilelist
{
get
{
string v;
m_options.TryGetValue("deleted-files", out v);
if (string.IsNullOrEmpty(v))
return null;
return v.Split(new char[] { System.IO.Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
}
}
/// <summary>
/// Alternate restore path
/// </summary>
public string Restorepath
{
get
{
string v;
m_options.TryGetValue("restore-path", out v);
return v;
}
}
/// <summary>
/// Gets the index file usage method
/// </summary>
public IndexFileStrategy IndexfilePolicy
{
get
{
string strategy;
if (!m_options.TryGetValue("index-file-policy", out strategy))
strategy = "";
IndexFileStrategy res;
if (!Enum.TryParse(strategy, true, out res))
res = IndexFileStrategy.Full;
return res;
}
}
/// <summary>
/// Gets a flag indicating if the check for files on the remote storage should be omitted
/// </summary>
public bool NoBackendverification
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "no-backend-verification"); }
}
/// <summary>
/// Gets the number of samples to test during a backup operation
/// </summary>
public long BackupTestSampleCount
{
get
{
string s;
m_options.TryGetValue("backup-test-samples", out s);
if (string.IsNullOrEmpty(s))
return 1;
return long.Parse(s);
}
}
/// <summary>
/// Gets a flag indicating if compacting should not be done automatically
/// </summary>
public bool NoAutoCompact
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "no-auto-compact"); }
}
/// <summary>
/// Gets a flag indicating if compacting should not be done automatically
/// </summary>
public bool AllowMissingSource
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "allow-missing-source"); }
}
/// <summary>
/// Gets a value indicating if a verification file should be uploaded after changing the remote store
/// </summary>
public bool UploadVerificationFile
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "upload-verification-file"); }
}
/// <summary>
/// Gets a value indicating if a passphrase change is allowed
/// </summary>
public bool AllowPassphraseChange
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "allow-passphrase-change"); }
}
/// <summary>
/// Gets a flag indicating if the current operation should merely output the changes
/// </summary>
public bool Dryrun
{
get
{
if (m_options.ContainsKey("dry-run"))
return Library.Utility.Utility.ParseBoolOption(m_options, "dry-run");
else
return Library.Utility.Utility.ParseBoolOption(m_options, "dryrun");
}
}
/// <summary>
/// Gets a flag indicating if the current operation is intended to delete files older than a certain threshold
/// </summary>
public bool HasDeleteOlderThan
{
get { return m_options.ContainsKey("delete-older-than"); }
}
/// <summary>
/// Gets a flag indicating if the current operation is intended to delete files older than a certain threshold
/// </summary>
public bool HasDeleteAllButN
{
get { return m_options.ContainsKey("delete-all-but-n") || m_options.ContainsKey("delete-all-but-n-full"); }
}
/// <summary>
/// Gets a flag indicating if the remote verification is deep
/// </summary>
public bool FullRemoteVerification
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "full-remote-verification"); }
}
/// <summary>
/// The block hash algorithm to use
/// </summary>
public string BlockHashAlgorithm
{
get
{
string v;
m_options.TryGetValue("block-hash-algorithm", out v);
if (string.IsNullOrEmpty(v))
return DEFAULT_BLOCK_HASH_ALGORITHM;
return v;
}
}
/// <summary>
/// The file hash algorithm to use
/// </summary>
public string FileHashAlgorithm
{
get
{
string v;
m_options.TryGetValue("file-hash-algorithm", out v);
if (string.IsNullOrEmpty(v))
return DEFAULT_FILE_HASH_ALGORITHM;
return v;
}
}
/// <summary>
/// Gets a flag indicating if the current operation is intended to delete files older than a certain threshold
/// </summary>
public bool PatchWithLocalBlocks
{
get { return m_options.ContainsKey("patch-with-local-blocks"); }
}
/// <summary>
/// Gets a value indicating whether local blocks usage should be skipped.
/// </summary>
/// <value><c>true</c> if no local blocks; otherwise, <c>false</c>.</value>
public bool NoLocalBlocks
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "no-local-blocks"); }
}
/// <summary>
/// Gets a flag indicating if the local database should not be used
/// </summary>
/// <value><c>true</c> if no local db is used; otherwise, <c>false</c>.</value>
public bool NoLocalDb
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "no-local-db"); }
}
/// <summary>
/// Gets a flag indicating if block hashes are checked before being applied
/// </summary>
/// <value><c>true</c> if block hashes are checked; otherwise, <c>false</c>.</value>
public bool FullBlockVerification
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "full-block-verification"); }
}
/// <summary>
/// Gets a flag indicating if the repair process will only restore paths
/// </summary>
/// <value><c>true</c> if only paths are restored; otherwise, <c>false</c>.</value>
public bool RepairOnlyPaths
{
get { return Library.Utility.Utility.ParseBoolOption(m_options, "repair-only-paths"); }
}
/// <summary>
/// Gets the threshold for when log data should be cleaned
/// </summary>
public DateTime LogRetention
{
get
{
string pts;
if (!m_options.TryGetValue("log-retention", out pts))
pts = DEFAULT_LOG_RETENTION;
return Library.Utility.Timeparser.ParseTimeInterval(pts, DateTime.Now, true);
}
}
/// <summary>
/// Gets a lookup table with compression hints, the key is the file extension with the leading period
/// </summary>
public IDictionary<string, CompressionHint> CompressionHints
{
get
{
if (m_compressionHints == null)
{
//Don't try again, if the file does not exist
m_compressionHints = new Dictionary<string, CompressionHint>(Library.Utility.Utility.ClientFilenameStringComparer);
string file;
if (!m_options.TryGetValue("compression-extension-file", out file))
file = DEFAULT_COMPRESSED_EXTENSION_FILE;
if (!string.IsNullOrEmpty(file) && System.IO.File.Exists(file))
foreach (var _line in Library.Utility.Utility.ReadFileWithDefaultEncoding(file).Split('\n'))
{
var line = _line.Trim();
var lix = line.IndexOf(' ');
if (lix > 0)
line = line.Substring(0, lix);
if (line.Length >= 2 && line[0] == '.')
m_compressionHints[line] = CompressionHint.Noncompressible;
}
}
return m_compressionHints;
}
}
/// <summary>
/// Gets a compression hint from a filename
/// </summary>
/// <param name="filename">The filename to get the hint for</param>
/// <returns>The compression hint</returns>
public CompressionHint GetCompressionHintFromFilename(string filename)
{
CompressionHint h;
if (!CompressionHints.TryGetValue(System.IO.Path.GetExtension(filename), out h))
return CompressionHint.Default;
return h;
}
/// <summary>
/// Gets a list of modules, the key indicates if they are loaded
/// </summary>
public List<KeyValuePair<bool, Library.Interface.IGenericModule>> LoadedModules { get { return m_loadedModules; } }
/// <summary>
/// Helper method to extract boolean values.
/// If the option is not present, it it's value is false.
/// If the option is present it's value is true, unless the option's value is false, off or 0
/// </summary>
/// <param name="name">The name of the option to read</param>
/// <returns>The interpreted value of the option</returns>
private bool GetBool(string name)
{
return Library.Utility.Utility.ParseBoolOption(m_options, name);
}
}
}
|