2024-03-15 14:18:56 +01:00
// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
2024-02-28 15:45:30 +01:00
2013-02-12 21:43:14 +00:00
using System ;
2013-05-11 12:03:15 +02:00
using System.Linq ;
2013-02-12 21:43:14 +00:00
using System.Collections.Generic ;
2018-09-09 14:42:40 +02:00
using System.Security.Cryptography ;
2013-02-12 21:43:14 +00:00
using Duplicati.Library.Interface ;
2017-09-21 23:44:24 -06:00
using Duplicati.Library.Utility ;
2019-09-01 12:40:37 +02:00
using System.Globalization ;
2013-02-12 21:43:14 +00:00
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
{
2013-05-06 09:58:19 +02:00
private const string DEFAULT_BLOCK_HASH_ALGORITHM = "SHA256" ;
private const string DEFAULT_FILE_HASH_ALGORITHM = "SHA256" ;
/// <summary>
2023-04-22 16:50:48 +10:00
/// The default block size, chose to minimize hash numbers but allow smaller upload sizes.
2013-05-06 09:58:19 +02:00
/// </summary>
2023-04-22 16:50:48 +10:00
private const string DEFAULT_BLOCKSIZE = "1mb" ;
2020-01-26 10:27:39 -08:00
2013-05-21 21:16:01 +02:00
/// <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 ;
2013-05-25 16:40:15 +02:00
/// <summary>
/// Default size of volumes
/// </summary>
2013-05-30 22:27:16 +02:00
private const string DEFAULT_VOLUME_SIZE = "50mb" ;
2013-05-25 17:57:52 +02:00
/// <summary>
/// Default value for keep-versions
/// </summary>
private const int DEFAULT_KEEP_VERSIONS = 0 ;
2013-05-06 09:58:19 +02:00
2015-02-15 23:26:52 +01:00
/// <summary>
/// The default threshold for purging log data
/// </summary>
private const string DEFAULT_LOG_RETENTION = "30D" ;
2016-04-04 22:43:07 +02:00
/// <summary>
/// The default number of compressor instances
/// </summary>
2016-04-05 23:29:14 +02:00
private readonly int DEFAULT_COMPRESSORS = Math . Max ( 1 , Environment . ProcessorCount / 2 );
2016-04-04 22:43:07 +02:00
/// <summary>
/// The default number of hasher instances
/// </summary>
2016-04-05 23:29:14 +02:00
private readonly int DEFAULT_BLOCK_HASHERS = Math . Max ( 1 , Environment . ProcessorCount / 2 );
2018-04-11 23:02:47 +02:00
2018-02-07 11:23:52 -07:00
/// <summary>
/// The default threshold for warning about coming close to quota
/// </summary>
private const int DEFAULT_QUOTA_WARNING_THRESHOLD = 10 ;
2016-04-04 22:43:07 +02:00
2013-02-12 21:43:14 +00:00
/// <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
}
2014-04-02 11:02:06 +02:00
2023-12-10 00:24:07 +01:00
/// <summary>
/// The possible settings for the remote test strategy
/// </summary>
public enum RemoteTestStrategy
{
/// <summary>
/// test the remote volumes
/// </summary>
True ,
/// <summary>
/// do not test the remote volumes
/// </summary>
False ,
/// <summary>
/// test only the list and index volumes
/// </summary>
ListAndIndexes
}
2014-04-02 11:02:06 +02:00
/// <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
}
2013-07-01 10:33:07 +02:00
/// <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
}
2013-02-12 21:43:14 +00:00
2024-03-15 14:18:56 +01:00
private static readonly string DEFAULT_COMPRESSED_EXTENSION_FILE = System . IO . Path . Combine ( Duplicati . Library . AutoUpdater . UpdaterManager . INSTALLATIONDIR , "default_compressed_extensions.txt" );
2013-02-27 20:57:58 +00:00
2013-02-12 21:43:14 +00:00
/// <summary>
/// Lock that protects the options collection
/// </summary>
2018-03-17 19:59:23 -07:00
protected readonly object m_lock = new object ();
2013-02-12 21:43:14 +00:00
2019-10-19 10:56:21 -07:00
protected readonly Dictionary < string , string > m_options ;
2013-02-12 21:43:14 +00:00
2019-10-19 10:56:21 -07:00
protected readonly List < KeyValuePair < bool , Library . Interface . IGenericModule >> m_loadedModules = new List < KeyValuePair < bool , IGenericModule >>();
2013-02-12 21:43:14 +00:00
2013-02-27 20:57:58 +00:00
/// <summary>
/// Lookup table for compression hints
/// </summary>
private Dictionary < string , CompressionHint > m_compressionHints ;
2013-02-12 21:43:14 +00:00
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
{
2013-05-05 16:40:37 +02:00
get { return new string [] { "auth-password" , "auth-username" }; }
2013-02-12 21:43:14 +00:00
}
/// <summary>
/// A default backup name
/// </summary>
public static string DefaultBackupName
{
get
{
2013-05-08 21:29:59 +02:00
return System . IO . Path . GetFileNameWithoutExtension ( Library . Utility . Utility . getEntryAssembly (). Location );
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
/// Gets all supported commands
/// </summary>
public IList < ICommandLineArgument > SupportedCommands
{
get
{
var lst = new List < ICommandLineArgument >( new ICommandLineArgument [] {
2013-05-28 23:41:07 +02:00
new CommandLineArgument ( "dblock-size" , CommandLineArgument . ArgumentType . Size , Strings . Options . DblocksizeShort , Strings . Options . DblocksizeLong , DEFAULT_VOLUME_SIZE ),
2014-03-13 10:20:57 +01:00
new CommandLineArgument ( "auto-cleanup" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . AutocleanupShort , Strings . Options . AutocleanupLong , "false" ),
2018-06-12 09:31:39 +02:00
new CommandLineArgument ( "unittest-mode" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . UnittestmodeShort , Strings . Options . UnittestmodeLong , "false" ),
2013-02-12 21:43:14 +00:00
2013-05-22 21:28:54 +02:00
new CommandLineArgument ( "control-files" , CommandLineArgument . ArgumentType . Path , Strings . Options . ControlfilesShort , Strings . Options . ControlfilesLong ),
2014-03-13 10:20:57 +01:00
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" ),
2013-05-13 22:32:05 +02:00
new CommandLineArgument ( "restore-path" , CommandLineArgument . ArgumentType . String , Strings . Options . RestorepathShort , Strings . Options . RestorepathLong ),
2013-05-11 12:03:15 +02:00
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" ),
2014-03-15 01:03:15 +01:00
new CommandLineArgument ( "list-prefix-only" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ListprefixonlyShort , Strings . Options . ListprefixonlyLong , "false" ),
2014-03-21 15:01:49 +01:00
new CommandLineArgument ( "list-folder-contents" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ListfoldercontentsShort , Strings . Options . ListfoldercontentsLong , "false" ),
2015-01-20 21:07:24 +01:00
new CommandLineArgument ( "list-sets-only" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ListsetsonlyShort , Strings . Options . ListsetsonlyLong , "false" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "disable-autocreate-folder" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisableautocreatefolderShort , Strings . Options . DisableautocreatefolderLong , "false" ),
2013-06-29 12:17:52 +02:00
new CommandLineArgument ( "allow-missing-source" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . AllowmissingsourceShort , Strings . Options . AllowmissingsourceLong , "false" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "disable-filetime-check" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisablefiletimecheckShort , Strings . Options . DisablefiletimecheckLong , "false" ),
2017-01-05 10:03:32 +01:00
new CommandLineArgument ( "check-filetime-only" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . CheckfiletimeonlyShort , Strings . Options . CheckfiletimeonlyLong , "false" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "disable-time-tolerance" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisabletimetoleranceShort , Strings . Options . DisabletimetoleranceLong , "false" ),
2015-01-20 21:07:24 +01:00
new CommandLineArgument ( "tempdir" , CommandLineArgument . ArgumentType . Path , Strings . Options . TempdirShort , Strings . Options . TempdirLong , System . IO . Path . GetTempPath ()),
2013-02-12 21:43:14 +00:00
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" }),
2013-05-13 22:32:05 +02:00
new CommandLineArgument ( "prefix" , CommandLineArgument . ArgumentType . String , Strings . Options . PrefixShort , Strings . Options . PrefixLong , "duplicati" ),
2013-02-12 21:43:14 +00:00
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" ),
2022-01-15 18:11:59 +01:00
new CommandLineArgument ( "retry-with-exponential-backoff" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . RetrywithexponentialbackoffShort , Strings . Options . RetrywithexponentialbackoffLong , "false" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "synchronous-upload" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . SynchronousuploadShort , Strings . Options . SynchronousuploadLong , "false" ),
2013-08-30 20:43:33 +02:00
new CommandLineArgument ( "asynchronous-upload-limit" , CommandLineArgument . ArgumentType . Integer , Strings . Options . AsynchronousuploadlimitShort , Strings . Options . AsynchronousuploadlimitLong , "4" ),
2019-09-01 12:40:37 +02:00
new CommandLineArgument ( "asynchronous-concurrent-upload-limit" , CommandLineArgument . ArgumentType . Integer , Strings . Options . AsynchronousconcurrentuploadlimitShort , Strings . Options . AsynchronousconcurrentuploadlimitLong , "4" ),
2014-03-13 10:20:57 +01:00
new CommandLineArgument ( "asynchronous-upload-folder" , CommandLineArgument . ArgumentType . Path , Strings . Options . AsynchronousuploadfolderShort , Strings . Options . AsynchronousuploadfolderLong , System . IO . Path . GetTempPath ()),
2019-11-01 19:27:49 -06:00
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "disable-streaming-transfers" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisableStreamingShort , Strings . Options . DisableStreamingLong , "false" ),
2016-11-27 12:00:51 +01:00
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" ),
2013-02-12 21:43:14 +00:00
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" ),
2013-05-08 19:57:13 +02:00
new CommandLineArgument ( "snapshot-policy" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . SnapshotpolicyShort , Strings . Options . SnapshotpolicyLong , "off" , null , Enum . GetNames ( typeof ( OptimizationStrategy ))),
2018-06-29 17:08:57 +02:00
new CommandLineArgument ( "vss-exclude-writers" , CommandLineArgument . ArgumentType . String , Strings . Options . VssexcludewritersShort , Strings . Options . VssexcludewritersLong , "{e8132975-6f93-4464-a53e-1050253ae220}" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "vss-use-mapping" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . VssusemappingShort , Strings . Options . VssusemappingLong , "false" ),
2013-05-08 19:57:13 +02:00
new CommandLineArgument ( "usn-policy" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . UsnpolicyShort , Strings . Options . UsnpolicyLong , "off" , null , Enum . GetNames ( typeof ( OptimizationStrategy ))),
2013-02-12 21:43:14 +00:00
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" ),
2018-08-07 09:40:43 +02:00
new CommandLineArgument ( "log-file" , CommandLineArgument . ArgumentType . Path , Strings . Options . LogfileShort , Strings . Options . LogfileLong ),
new CommandLineArgument ( "log-file-log-level" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . LogfileloglevelShort , Strings . Options . LogfileloglevelShort , "Warning" , null , Enum . GetNames ( typeof ( Duplicati . Library . Logging . LogMessageType ))),
new CommandLineArgument ( "log-file-log-filter" , CommandLineArgument . ArgumentType . String , Strings . Options . LogfilelogfiltersShort , Strings . Options . LogfilelogfiltersLong ( System . IO . Path . PathSeparator . ToString ()), null ),
2018-03-12 14:07:11 +01:00
2018-08-07 09:40:43 +02:00
new CommandLineArgument ( "console-log-level" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . ConsoleloglevelShort , Strings . Options . ConsoleloglevelShort , "Warning" , null , Enum . GetNames ( typeof ( Duplicati . Library . Logging . LogMessageType ))),
new CommandLineArgument ( "console-log-filter" , CommandLineArgument . ArgumentType . String , Strings . Options . ConsolelogfiltersShort , Strings . Options . ConsolelogfiltersLong ( System . IO . Path . PathSeparator . ToString ()), null ),
2018-03-12 14:07:11 +01:00
2018-08-07 09:40:43 +02:00
new CommandLineArgument ( "log-level" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . LoglevelShort , Strings . Options . LoglevelLong , "Warning" , null , Enum . GetNames ( typeof ( Duplicati . Library . Logging . LogMessageType )), Strings . Options . LogLevelDeprecated ( "log-file-log-level" , "console-log-level" )),
new CommandLineArgument ( "profile-all-database-queries" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ProfilealldatabasequeriesShort , Strings . Options . ProfilealldatabasequeriesLong , "false" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "list-verify-uploads" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ListverifyuploadsShort , Strings . Options . ListverifyuploadsShort , "false" ),
2016-10-04 11:53:51 +02:00
new CommandLineArgument ( "allow-sleep" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . AllowsleepShort , Strings . Options . AllowsleepLong , "false" ),
2018-03-16 23:25:06 +01:00
new CommandLineArgument ( "use-background-io-priority" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . UsebackgroundiopriorityShort , Strings . Options . UsebackgroundiopriorityLong , "false" ),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "no-connection-reuse" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . NoconnectionreuseShort , Strings . Options . NoconnectionreuseLong , "false" ),
2018-02-07 11:23:52 -07:00
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "quota-size" , CommandLineArgument . ArgumentType . Size , Strings . Options . QuotasizeShort , Strings . Options . QuotasizeLong ),
2018-02-07 11:23:52 -07:00
new CommandLineArgument ( "quota-warning-threshold" , CommandLineArgument . ArgumentType . Integer , Strings . Options . QuotaWarningThresholdShort , Strings . Options . QuotaWarningThresholdLong , DEFAULT_QUOTA_WARNING_THRESHOLD . ToString ()),
2013-02-12 21:43:14 +00:00
2015-01-20 21:07:24 +01:00
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 )))),
2013-02-12 21:43:14 +00:00
new CommandLineArgument ( "backup-name" , CommandLineArgument . ArgumentType . String , Strings . Options . BackupnameShort , Strings . Options . BackupnameLong , DefaultBackupName ),
2015-01-20 21:07:24 +01:00
new CommandLineArgument ( "compression-extension-file" , CommandLineArgument . ArgumentType . Path , Strings . Options . CompressionextensionfileShort , Strings . Options . CompressionextensionfileLong ( DEFAULT_COMPRESSED_EXTENSION_FILE ), DEFAULT_COMPRESSED_EXTENSION_FILE ),
2013-03-27 16:06:45 +01:00
2024-03-07 22:11:49 +01:00
new CommandLineArgument ( "backup-id" , CommandLineArgument . ArgumentType . String , Strings . Options . BackupidShort , Strings . Options . BackupidLong , "" ),
new CommandLineArgument ( "machine-id" , CommandLineArgument . ArgumentType . String , Strings . Options . MachineidShort , Strings . Options . MachineidLong , Library . AutoUpdater . UpdaterManager . InstallID ),
2018-03-12 14:07:11 +01:00
new CommandLineArgument ( "verbose" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . VerboseShort , Strings . Options . VerboseLong , "false" , null , null , Strings . Options . VerboseDeprecated ),
2017-04-04 23:51:40 +02:00
new CommandLineArgument ( "full-result" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . FullresultShort , Strings . Options . FullresultLong , "false" ),
2013-02-12 21:43:14 +00:00
2013-05-20 13:48:44 +02:00
new CommandLineArgument ( "overwrite" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . OverwriteShort , Strings . Options . OverwriteLong , "false" ),
2013-05-08 19:57:13 +02:00
new CommandLineArgument ( "dbpath" , CommandLineArgument . ArgumentType . Path , Strings . Options . DbpathShort , Strings . Options . DbpathLong ),
2013-05-21 21:16:01 +02:00
new CommandLineArgument ( "blocksize" , CommandLineArgument . ArgumentType . Size , Strings . Options . BlocksizeShort , Strings . Options . BlocksizeLong , DEFAULT_BLOCKSIZE ),
2019-09-19 13:51:00 -07:00
new CommandLineArgument ( "file-read-buffer-size" , CommandLineArgument . ArgumentType . Size , Strings . Options . FilereadbuffersizeShort , Strings . Options . FilereadbuffersizeLong , "0kb" , null , null , @"The ""file-read-buffer-size"" option is no longer used and has been deprecated." ),
2015-01-20 21:07:24 +01:00
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" ),
2019-09-19 14:10:32 -07:00
new CommandLineArgument ( "disable-filepath-cache" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisablefilepathcacheShort , Strings . Options . DisablefilepathcacheLong , "true" , null , null , @"The ""disable-filepath-cache"" option is no longer used and has been deprecated." ),
2017-09-19 12:51:40 +02:00
new CommandLineArgument ( "use-block-cache" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . UseblockcacheShort , Strings . Options . UseblockcacheLong , "false" ),
2017-09-18 23:23:45 -06:00
new CommandLineArgument ( "changed-files" , CommandLineArgument . ArgumentType . Path , Strings . Options . ChangedfilesShort , Strings . Options . ChangedfilesLong ),
2015-01-20 21:07:24 +01:00
new CommandLineArgument ( "deleted-files" , CommandLineArgument . ArgumentType . Path , Strings . Options . DeletedfilesShort , Strings . Options . DeletedfilesLong ( "changed-files" )),
2016-12-24 11:42:26 +01:00
new CommandLineArgument ( "disable-synthetic-filelist" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisablesyntheticfilelistShort , Strings . Options . DisablesyntehticfilelistLong , "false" ),
2013-05-06 09:58:19 +02:00
2016-11-06 22:28:56 +01:00
new CommandLineArgument ( "threshold" , CommandLineArgument . ArgumentType . Integer , Strings . Options . ThresholdShort , Strings . Options . ThresholdLong , DEFAULT_THRESHOLD . ToString ()),
2013-08-31 13:36:12 +02:00
new CommandLineArgument ( "index-file-policy" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . IndexfilepolicyShort , Strings . Options . IndexfilepolicyLong , IndexFileStrategy . Full . ToString (), null , Enum . GetNames ( typeof ( IndexFileStrategy ))),
2013-05-20 14:05:49 +02:00
new CommandLineArgument ( "no-backend-verification" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . NobackendverificationShort , Strings . Options . NobackendverificationLong , "false" ),
2015-01-20 21:07:24 +01:00
new CommandLineArgument ( "backup-test-samples" , CommandLineArgument . ArgumentType . Integer , Strings . Options . BackendtestsamplesShort , Strings . Options . BackendtestsamplesLong ( "no-backend-verification" ), "1" ),
2019-09-01 12:40:37 +02:00
new CommandLineArgument ( "backup-test-percentage" , CommandLineArgument . ArgumentType . Integer , Strings . Options . BackendtestpercentageShort , Strings . Options . BackendtestpercentageLong , "0" ),
2023-12-10 00:24:07 +01:00
new CommandLineArgument ( "full-remote-verification" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . FullremoteverificationShort , Strings . Options . FullremoteverificationLong ( "no-backend-verification" ), Enum . GetName ( typeof ( RemoteTestStrategy ), RemoteTestStrategy . False ), null , Enum . GetNames ( typeof ( RemoteTestStrategy ))),
2013-05-11 22:56:21 +02:00
new CommandLineArgument ( "dry-run" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DryrunShort , Strings . Options . DryrunLong , "false" , new string [] { "dryrun" }),
2013-05-06 09:58:19 +02:00
2021-04-04 11:17:13 -07:00
new CommandLineArgument ( "block-hash-algorithm" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . BlockhashalgorithmShort , Strings . Options . BlockhashalgorithmLong , DEFAULT_BLOCK_HASH_ALGORITHM , null , HashFactory . GetSupportedHashes ()),
new CommandLineArgument ( "file-hash-algorithm" , CommandLineArgument . ArgumentType . Enumeration , Strings . Options . FilehashalgorithmShort , Strings . Options . FilehashalgorithmLong , DEFAULT_FILE_HASH_ALGORITHM , null , HashFactory . GetSupportedHashes ()),
2013-05-06 09:58:19 +02:00
2013-05-08 19:57:13 +02:00
new CommandLineArgument ( "no-auto-compact" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . NoautocompactShort , Strings . Options . NoautocompactLong , "false" ),
2013-05-21 21:16:01 +02:00
new CommandLineArgument ( "small-file-size" , CommandLineArgument . ArgumentType . Size , Strings . Options . SmallfilesizeShort , Strings . Options . SmallfilesizeLong ),
2017-09-06 16:38:05 +02:00
new CommandLineArgument ( "small-file-max-count" , CommandLineArgument . ArgumentType . Integer , Strings . Options . SmallfilemaxcountShort , Strings . Options . SmallfilemaxcountLong , DEFAULT_SMALL_FILE_MAX_COUNT . ToString ()),
2013-05-06 09:58:19 +02:00
2014-03-13 10:20:57 +01:00
new CommandLineArgument ( "patch-with-local-blocks" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . PatchwithlocalblocksShort , Strings . Options . PatchwithlocalblocksLong , "false" ),
2013-05-11 22:56:21 +02:00
new CommandLineArgument ( "no-local-db" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . NolocaldbShort , Strings . Options . NolocaldbLong , "false" ),
2017-01-06 23:01:54 +01:00
new CommandLineArgument ( "dont-compress-restore-paths" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DontcompressrestorepathsShort , Strings . Options . DontcompressrestorepathsLong , "false" ),
2013-05-25 17:57:52 +02:00
new CommandLineArgument ( "keep-versions" , CommandLineArgument . ArgumentType . Integer , Strings . Options . KeepversionsShort , Strings . Options . KeepversionsLong , DEFAULT_KEEP_VERSIONS . ToString ()),
2013-07-02 10:00:46 +02:00
new CommandLineArgument ( "keep-time" , CommandLineArgument . ArgumentType . Timespan , Strings . Options . KeeptimeShort , Strings . Options . KeeptimeLong ),
2017-09-30 20:28:40 +02:00
new CommandLineArgument ( "retention-policy" , CommandLineArgument . ArgumentType . String , Strings . Options . RetentionPolicyShort , Strings . Options . RetentionPolicyLong ),
2013-07-01 14:40:45 +02:00
new CommandLineArgument ( "upload-verification-file" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . UploadverificationfileShort , Strings . Options . UploadverificationfileLong , "false" ),
2013-10-29 11:43:44 +01:00
new CommandLineArgument ( "allow-passphrase-change" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . AllowpassphrasechangeShort , Strings . Options . AllowpassphrasechangeLong , "false" ),
2015-01-27 22:12:52 +01:00
new CommandLineArgument ( "no-local-blocks" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . NolocalblocksShort , Strings . Options . NolocalblocksLong , "false" ),
2015-01-27 22:21:43 +01:00
new CommandLineArgument ( "full-block-verification" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . FullblockverificationShort , Strings . Options . FullblockverificationLong , "false" ),
2017-01-09 10:32:38 +01:00
new CommandLineArgument ( "allow-full-removal" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . AllowfullremovalShort , Strings . Options . AllowfullremovalLong , "false" ),
2015-02-15 23:26:52 +01:00
new CommandLineArgument ( "log-retention" , CommandLineArgument . ArgumentType . Timespan , Strings . Options . LogretentionShort , Strings . Options . LogretentionLong , DEFAULT_LOG_RETENTION ),
2015-04-08 20:19:46 +02:00
new CommandLineArgument ( "repair-only-paths" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . RepaironlypathsShort , Strings . Options . RepaironlypathsLong , "false" ),
2023-11-05 18:19:08 +01:00
new CommandLineArgument ( "repair-force-block-use" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . RepaironlypathsShort , Strings . Options . RepaironlypathsLong , "false" ),
2015-09-11 11:21:57 +02:00
new CommandLineArgument ( "force-locale" , CommandLineArgument . ArgumentType . String , Strings . Options . ForcelocaleShort , Strings . Options . ForcelocaleLong ),
2018-11-12 10:09:13 -02:00
new CommandLineArgument ( "force-actual-date" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ForceActualDateShort , Strings . Options . ForceActualDateLong , "false" ),
2016-02-28 21:36:52 +01:00
2016-03-19 22:27:46 +01:00
new CommandLineArgument ( "disable-piped-streaming" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisablepipingShort , Strings . Options . DisablepipingLong , "false" ),
2016-04-04 22:43:07 +02:00
new CommandLineArgument ( "concurrency-max-threads" , CommandLineArgument . ArgumentType . Integer , Strings . Options . ConcurrencymaxthreadsShort , Strings . Options . ConcurrencymaxthreadsLong , "0" ),
new CommandLineArgument ( "concurrency-block-hashers" , CommandLineArgument . ArgumentType . Integer , Strings . Options . ConcurrencyblockhashersShort , Strings . Options . ConcurrencyblockhashersLong , DEFAULT_BLOCK_HASHERS . ToString ()),
new CommandLineArgument ( "concurrency-compressors" , CommandLineArgument . ArgumentType . Integer , Strings . Options . ConcurrencycompressorsShort , Strings . Options . ConcurrencycompressorsLong , DEFAULT_COMPRESSORS . ToString ()),
2017-09-18 11:56:35 +02:00
2017-08-04 12:09:01 +01:00
new CommandLineArgument ( "auto-vacuum" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . AutoVacuumShort , Strings . Options . AutoVacuumLong , "false" ),
2018-02-11 20:57:38 +01:00
new CommandLineArgument ( "disable-file-scanner" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisablefilescannerShort , Strings . Options . DisablefilescannerLong , "false" ),
2018-08-14 15:21:54 +02:00
new CommandLineArgument ( "disable-filelist-consistency-checks" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisablefilelistconsistencychecksShort , Strings . Options . DisablefilelistconsistencychecksLong , "false" ),
2018-03-04 12:29:56 -08:00
new CommandLineArgument ( "disable-on-battery" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . DisableOnBatteryShort , Strings . Options . DisableOnBatteryLong , "false" ),
2018-04-24 13:11:03 +02:00
new CommandLineArgument ( "exclude-empty-folders" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . ExcludeemptyfoldersShort , Strings . Options . ExcludeemptyfoldersLong , "false" ),
2018-04-24 11:25:37 +02:00
new CommandLineArgument ( "ignore-filenames" , CommandLineArgument . ArgumentType . Path , Strings . Options . IgnorefilenamesShort , Strings . Options . IgnorefilenamesLong ),
2018-06-07 13:26:28 +02:00
new CommandLineArgument ( "restore-symlink-metadata" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . RestoresymlinkmetadataShort , Strings . Options . RestoresymlinkmetadataLong , "false" ),
2018-08-07 11:14:28 +02:00
new CommandLineArgument ( "rebuild-missing-dblock-files" , CommandLineArgument . ArgumentType . Boolean , Strings . Options . RebuildmissingdblockfilesShort , Strings . Options . RebuildmissingdblockfilesLong , "false" ),
2019-09-01 12:40:37 +02:00
new CommandLineArgument ( "auto-compact-interval" , CommandLineArgument . ArgumentType . Timespan , Strings . Options . AutoCompactIntervalShort , Strings . Options . AutoCompactIntervalLong , "0m" ),
new CommandLineArgument ( "auto-vacuum-interval" , CommandLineArgument . ArgumentType . Timespan , Strings . Options . AutoVacuumIntervalShort , Strings . Options . AutoVacuumIntervalLong , "0m" ),
2013-05-06 09:58:19 +02:00
});
2013-02-12 21:43:14 +00:00
return lst ;
}
}
/// <summary>
/// Gets or sets the current main action of the instance
/// </summary>
2013-05-08 21:29:59 +02:00
public OperationMode MainAction
2013-02-12 21:43:14 +00:00
{
2013-05-08 21:29:59 +02:00
get { return ( OperationMode ) Enum . Parse ( typeof ( OperationMode ), m_options [ "main-action" ]); }
2013-02-12 21:43:14 +00:00
set { m_options [ "main-action" ] = value . ToString (); }
}
/// <summary>
/// Gets the size of each volume in bytes
/// </summary>
public long VolumeSize
{
get
{
2013-05-25 16:40:15 +02:00
string volsize ;
2013-05-28 23:41:07 +02:00
m_options . TryGetValue ( "dblock-size" , out volsize );
2013-05-25 16:40:15 +02:00
if ( string . IsNullOrEmpty ( volsize ))
volsize = DEFAULT_VOLUME_SIZE ;
2013-02-12 21:43:14 +00:00
#if DEBUG
2013-05-08 21:29:59 +02:00
return Math . Max ( 1024 * 10 , Library . Utility . Sizeparser . ParseSize ( volsize , "mb" ));
2013-02-12 21:43:14 +00:00
#else
2013-09-10 22:41:05 +02:00
return Math . Max ( 1024 * 1024 , Library . Utility . Sizeparser . ParseSize ( volsize , "mb" ));
2013-02-12 21:43:14 +00:00
#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
2013-05-08 21:29:59 +02:00
return Library . Utility . Sizeparser . ParseSize ( m_options [ "skip-files-larger-than" ], "mb" );
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
/// A value indicating if orphan files are deleted automatically
/// </summary>
public bool AutoCleanup { get { return GetBool ( "auto-cleanup" ); } }
2018-06-12 09:31:39 +02:00
/// <summary>
/// A value indicating if we are running in unittest mode
/// </summary>
public bool UnittestMode { get { return GetBool ( "unittest-mode" ); } }
2013-02-12 21:43:14 +00:00
/// <summary>
/// Gets a list of files to add to the signature volumes
/// </summary>
2013-05-22 21:28:54 +02:00
public string ControlFiles
2013-02-12 21:43:14 +00:00
{
get
{
2016-09-15 11:39:27 +02:00
string v ;
m_options . TryGetValue ( "control-files" , out v );
return v ;
2013-02-12 21:43:14 +00:00
}
}
/// <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" ); } }
2013-05-11 12:03:15 +02:00
/// <summary>
2013-02-12 21:43:14 +00:00
/// Gets the backup that should be restored
/// </summary>
2013-05-11 12:03:15 +02:00
public DateTime Time
2013-02-12 21:43:14 +00:00
{
get
{
2013-05-11 12:03:15 +02:00
if (! m_options . ContainsKey ( "time" ) || string . IsNullOrEmpty ( m_options [ "time" ]))
2013-06-26 21:52:59 +02:00
return new DateTime ( 0 , DateTimeKind . Utc );
2013-02-12 21:43:14 +00:00
else
2013-05-11 12:03:15 +02:00
return Library . Utility . Timeparser . ParseTimeInterval ( m_options [ "time" ], DateTime . Now );
2013-02-12 21:43:14 +00:00
}
}
2013-05-11 12:03:15 +02:00
/// <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" ); } }
2013-02-12 21:43:14 +00:00
2014-03-15 01:03:15 +01:00
/// <summary>
/// A value indicating if only the largest common prefix is returned
/// </summary>
public bool ListPrefixOnly { get { return GetBool ( "list-prefix-only" ); } }
2014-03-21 15:01:49 +01:00
/// <summary>
/// A value indicating if only folder contents are returned
/// </summary>
public bool ListFolderContents { get { return GetBool ( "list-folder-contents" ); } }
2014-08-19 20:24:54 +02:00
/// <summary>
/// A value indicating that only filesets are returned
/// </summary>
public bool ListSetsOnly { get { return GetBool ( "list-sets-only" ); } }
2013-02-12 21:43:14 +00:00
/// <summary>
/// A value indicating if file time checks are skipped
/// </summary>
public bool DisableFiletimeCheck { get { return GetBool ( "disable-filetime-check" ); } }
2017-01-05 10:03:32 +01:00
/// <summary>
/// A value indicating if file time checks are skipped
/// </summary>
public bool CheckFiletimeOnly { get { return GetBool ( "check-filetime-only" ); } }
2013-02-12 21:43:14 +00:00
/// <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" ); } }
2013-03-08 12:25:35 +01:00
/// <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" ]); } }
2013-02-12 21:43:14 +00:00
/// <summary>
/// Gets the folder where temporary files are stored
/// </summary>
public string TempDir
{
get
{
if (! m_options . ContainsKey ( "tempdir" ) || string . IsNullOrEmpty ( m_options [ "tempdir" ]))
2018-05-26 22:55:29 +02:00
{
2018-05-22 21:49:48 +02:00
return Duplicati . Library . Utility . TempFolder . SystemTempPath ;
2018-05-26 22:55:29 +02:00
}
2018-05-20 16:07:12 +02:00
return m_options [ "tempdir" ];
2013-02-12 21:43:14 +00:00
}
2019-09-01 12:40:37 +02:00
}
2015-09-11 11:21:57 +02:00
/// <summary>
2016-03-10 21:51:55 +01:00
/// Gets a value indicating whether the user has forced the locale
2015-09-11 11:21:57 +02:00
/// </summary>
public bool HasForcedLocale { get { return m_options . ContainsKey ( "force-locale" ); } }
/// <summary>
2016-03-10 21:51:55 +01:00
/// Gets the forced locale for the current user
2015-09-11 11:21:57 +02:00
/// </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 );
}
}
}
2013-02-12 21:43:14 +00:00
/// <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>
2013-05-13 22:32:05 +02:00
public string Prefix
2013-02-12 21:43:14 +00:00
{
get
{
2016-09-15 11:39:27 +02:00
string v ;
m_options . TryGetValue ( "prefix" , out v );
if (! string . IsNullOrEmpty ( v ))
return v ;
return "duplicati" ;
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
/// Gets the number of old backups to keep
/// </summary>
2013-05-11 22:56:21 +02:00
public int KeepVersions
2013-02-12 21:43:14 +00:00
{
get
{
2013-05-11 22:56:21 +02:00
string v ;
m_options . TryGetValue ( "keep-versions" , out v );
if ( string . IsNullOrEmpty ( v ))
2013-05-25 17:57:52 +02:00
return DEFAULT_KEEP_VERSIONS ;
2013-05-11 22:56:21 +02:00
2013-05-25 17:57:52 +02:00
return Math . Max ( 0 , int . Parse ( v ));
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
/// Gets the timelimit for removal
/// </summary>
2013-05-11 22:56:21 +02:00
public DateTime KeepTime
2013-02-12 21:43:14 +00:00
{
get
{
2013-05-11 22:56:21 +02:00
string v ;
m_options . TryGetValue ( "keep-time" , out v );
if ( string . IsNullOrEmpty ( v ))
2013-07-02 10:00:46 +02:00
return new DateTime ( 0 );
2013-02-12 21:43:14 +00:00
TimeSpan tolerance =
this . DisableTimeTolerance ?
TimeSpan . FromSeconds ( 0 ) :
2013-05-11 22:56:21 +02:00
TimeSpan . FromSeconds ( Math . Min ( Library . Utility . Timeparser . ParseTimeSpan ( v ). TotalSeconds / 100 , 60.0 * 60.0 ));
2013-02-12 21:43:14 +00:00
2013-05-11 22:56:21 +02:00
return Library . Utility . Timeparser . ParseTimeInterval ( v , DateTime . Now , true ) - tolerance ;
2013-02-12 21:43:14 +00:00
}
}
2017-09-05 21:13:40 +02:00
2013-05-11 22:56:21 +02:00
/// <summary>
2017-09-30 13:14:28 +02:00
/// Gets the time frames and intervals for the retention policy
2017-09-05 21:13:40 +02:00
/// </summary>
2018-02-18 16:47:04 +01:00
public List < RetentionPolicyValue > RetentionPolicy
2013-05-11 22:56:21 +02:00
{
2017-09-05 21:13:40 +02:00
get {
2018-02-18 16:47:04 +01:00
var retentionPolicyConfig = new List < RetentionPolicyValue >();
2017-01-11 13:51:30 +01:00
2017-09-05 21:13:40 +02:00
string v ;
2017-09-30 13:14:28 +02:00
m_options . TryGetValue ( "retention-policy" , out v );
2017-09-05 21:13:40 +02:00
if ( string . IsNullOrEmpty ( v )) {
2017-09-30 13:14:28 +02:00
return retentionPolicyConfig ;
2017-09-05 21:13:40 +02:00
}
2017-01-11 13:51:30 +01:00
2017-09-09 14:08:43 +02:00
var periodIntervalStrings = v . Split ( new char [] { ',' }, StringSplitOptions . RemoveEmptyEntries );
2017-09-05 21:13:40 +02:00
2017-09-09 14:08:43 +02:00
foreach ( var periodIntervalString in periodIntervalStrings )
2017-09-05 21:13:40 +02:00
{
2018-02-18 16:47:04 +01:00
retentionPolicyConfig . Add ( RetentionPolicyValue . CreateFromString ( periodIntervalString ));
2017-09-05 21:13:40 +02:00
}
2017-09-30 13:14:28 +02:00
return retentionPolicyConfig ;
2017-09-05 21:13:40 +02:00
}
2013-05-11 22:56:21 +02:00
}
2013-02-12 21:43:14 +00:00
/// <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>
/// 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" ];
2013-05-08 19:57:13 +02:00
return "aes" ;
2013-02-12 21:43:14 +00:00
}
}
/// <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 )
2018-03-12 14:07:11 +01:00
throw new UserInformationException ( "Invalid count for number-of-retries" , "NumberOfRetriesInvalid" );
2013-02-12 21:43:14 +00:00
return x ;
}
}
}
/// <summary>
/// A value indicating if backups are transmitted on a separate thread
/// </summary>
2013-05-08 21:29:59 +02:00
public bool SynchronousUpload { get { return Library . Utility . Utility . ParseBoolOption ( m_options , "synchronous-upload" ); } }
2013-02-12 21:43:14 +00:00
/// <summary>
2018-03-16 23:25:06 +01:00
/// A value indicating if system is allowed to enter sleep power states during backup/restore
2013-02-12 21:43:14 +00:00
/// </summary>
public bool AllowSleep { get { return GetBool ( "allow-sleep" ); } }
2018-03-16 23:25:06 +01:00
/// <summary>
/// A value indicating if system should use the low-priority IO during backup/restore
/// </summary>
public bool UseBackgroundIOPriority { get { return GetBool ( "use-background-io-priority" ); } }
2013-02-12 21:43:14 +00:00
/// <summary>
/// A value indicating if use of the streaming interface is disallowed
/// </summary>
public bool DisableStreamingTransfers { get { return GetBool ( "disable-streaming-transfers" ); } }
2016-02-28 21:36:52 +01:00
/// <summary>
2016-03-17 19:53:51 +01:00
/// A value indicating if multithreaded pipes may be used for hashing and crypting on up-/downloads
2016-02-28 21:36:52 +01:00
/// </summary>
2016-03-19 22:27:46 +01:00
public bool DisablePipedStreaming { get { return GetBool ( "disable-piped-streaming" ); } }
2016-02-28 21:36:52 +01:00
2013-02-12 21:43:14 +00:00
/// <summary>
2022-01-15 18:11:59 +01:00
/// Gets the delay period to retry uploads
2013-02-12 21:43:14 +00:00
/// </summary>
public TimeSpan RetryDelay
{
get
{
if (! m_options . ContainsKey ( "retry-delay" ) || string . IsNullOrEmpty ( m_options [ "retry-delay" ]))
return new TimeSpan ( TimeSpan . TicksPerSecond * 10 );
else
2013-05-08 21:29:59 +02:00
return Library . Utility . Timeparser . ParseTimeSpan ( m_options [ "retry-delay" ]);
2013-02-12 21:43:14 +00:00
}
}
2022-01-15 18:11:59 +01:00
/// <summary>
/// Gets whether exponential backoff is enabled
/// </summary>
public Boolean RetryWithExponentialBackoff
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "retry-with-exponential-backoff" ); }
}
2013-02-12 21:43:14 +00:00
/// <summary>
/// Gets the max upload speed in bytes pr. second
/// </summary>
public long MaxUploadPrSecond
{
get
{
lock ( m_lock )
2013-05-28 23:51:43 +02:00
{
string v ;
2013-05-30 22:30:30 +02:00
m_options . TryGetValue ( "throttle-upload" , out v );
2013-05-28 23:51:43 +02:00
if ( string . IsNullOrEmpty ( v ))
2013-02-12 21:43:14 +00:00
return 0 ;
else
2013-05-28 23:51:43 +02:00
return Library . Utility . Sizeparser . ParseSize ( v , "kb" );
}
2013-02-12 21:43:14 +00:00
}
set
{
lock ( m_lock )
if ( value <= 0 )
2013-05-30 22:30:30 +02:00
m_options [ "throttle-upload" ] = "" ;
2013-02-12 21:43:14 +00:00
else
2013-05-30 22:30:30 +02:00
m_options [ "throttle-upload" ] = value . ToString () + "b" ;
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
/// Gets or sets the max download speed in bytes pr. second
/// </summary>
public long MaxDownloadPrSecond
{
get
{
lock ( m_lock )
2013-05-28 23:51:43 +02:00
{
string v ;
2013-05-30 22:30:30 +02:00
m_options . TryGetValue ( "throttle-download" , out v );
2013-05-28 23:51:43 +02:00
if ( string . IsNullOrEmpty ( v ))
2013-02-12 21:43:14 +00:00
return 0 ;
else
2013-05-28 23:51:43 +02:00
return Library . Utility . Sizeparser . ParseSize ( v , "kb" );
}
2013-02-12 21:43:14 +00:00
}
set
{
lock ( m_lock )
if ( value <= 0 )
2013-05-30 22:30:30 +02:00
m_options [ "throttle-download" ] = "" ;
2013-02-12 21:43:14 +00:00
else
2013-05-30 22:30:30 +02:00
m_options [ "throttle-download" ] = value . ToString () + "b" ;
2013-02-12 21:43:14 +00:00
}
}
/// <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" ))
2019-09-01 12:40:37 +02:00
return m_options [ "enable-module" ]. Trim (). ToLower ( CultureInfo . InvariantCulture ). Split ( ',' );
2013-02-12 21:43:14 +00:00
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" ))
2019-09-01 12:40:37 +02:00
return m_options [ "disable-module" ]. Trim (). ToLower ( CultureInfo . InvariantCulture ). Split ( ',' );
2013-02-12 21:43:14 +00:00
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 = "" ;
2020-02-03 21:19:23 -08:00
OptimizationStrategy r ;
if (! Enum . TryParse ( strategy , true , out r ))
r = OptimizationStrategy . Off ;
return r ;
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
2014-04-02 11:02:06 +02:00
/// Gets the symlink strategy to use
2013-02-12 21:43:14 +00:00
/// </summary>
public SymlinkStrategy SymlinkPolicy
{
get
{
2014-04-02 11:02:06 +02:00
string policy ;
if (! m_options . TryGetValue ( "symlink-policy" , out policy ))
policy = "" ;
2013-02-12 21:43:14 +00:00
SymlinkStrategy r ;
2014-04-02 11:02:06 +02:00
if (! Enum . TryParse ( policy , true , out r ))
2013-02-12 21:43:14 +00:00
r = SymlinkStrategy . Store ;
return r ;
}
}
2014-04-02 11:02:06 +02:00
/// <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 ;
}
}
2013-02-12 21:43:14 +00:00
/// <summary>
2018-04-19 22:59:28 +02:00
/// Gets the update sequence number (USN) strategy to use
2013-02-12 21:43:14 +00:00
/// </summary>
public OptimizationStrategy UsnStrategy
{
get
{
string strategy ;
if (! m_options . TryGetValue ( "usn-policy" , out strategy ))
strategy = "" ;
2020-02-03 21:19:23 -08:00
OptimizationStrategy r ;
if (! Enum . TryParse ( strategy , true , out r ))
r = OptimizationStrategy . Off ;
return r ;
2013-02-12 21:43:14 +00:00
}
}
2019-09-01 12:40:37 +02:00
/// <summary>
/// Gets the number of concurrent volume uploads allowed. Zero for unlimited.
/// </summary>
public int AsynchronousConcurrentUploadLimit
{
get
{
if (! m_options . TryGetValue ( "asynchronous-concurrent-upload-limit" , out var value ))
value = null ;
if ( string . IsNullOrEmpty ( value ))
return 4 ;
else
return int . Parse ( value );
}
}
2013-02-12 21:43:14 +00:00
/// <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 ))
2013-08-30 20:43:33 +02:00
return 4 ;
2013-02-12 21:43:14 +00:00
else
return long . Parse ( value );
}
}
/// <summary>
2019-11-30 11:35:43 -08:00
/// Gets the temporary folder to use for asynchronous transfers
2013-02-12 21:43:14 +00:00
/// </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 ;
}
}
2019-11-01 19:27:49 -06:00
2013-02-12 21:43:14 +00:00
/// <summary>
/// Gets the logfile filename
/// </summary>
public string Logfile
{
get
{
string value ;
if (! m_options . TryGetValue ( "log-file" , out value ))
value = null ;
return value ;
}
}
2014-08-12 11:02:03 +02:00
/// <summary>
2018-03-12 14:07:11 +01:00
/// Gets the log-file detail level
2014-08-12 11:02:03 +02:00
/// </summary>
2018-03-12 14:07:11 +01:00
public Duplicati . Library . Logging . LogMessageType LogFileLoglevel
2014-08-12 11:02:03 +02:00
{
get
{
string value ;
2018-03-12 14:07:11 +01:00
if (! m_options . TryGetValue ( "log-file-log-level" , out value ))
2014-08-12 11:02:03 +02:00
value = null ;
2018-03-12 14:07:11 +01:00
if ( string . IsNullOrWhiteSpace ( value ))
if (! m_options . TryGetValue ( "log-level" , out value ))
value = null ;
2014-08-12 11:02:03 +02:00
foreach ( string s in Enum . GetNames ( typeof ( Duplicati . Library . Logging . LogMessageType )))
2017-09-18 23:23:45 -06:00
if ( s . Equals ( value , StringComparison . OrdinalIgnoreCase ))
2018-03-12 14:07:11 +01:00
return ( Duplicati . Library . Logging . LogMessageType ) Enum . Parse ( typeof ( Duplicati . Library . Logging . LogMessageType ), s );
2014-08-12 11:02:03 +02:00
2023-12-11 14:42:45 +01:00
if ( Dryrun )
return Duplicati . Library . Logging . LogMessageType . DryRun ;
else
return Duplicati . Library . Logging . LogMessageType . Warning ;
2014-08-12 11:02:03 +02:00
}
}
2018-03-12 14:07:11 +01:00
/// <summary>
/// Gets the filter used for log-file messages.
2013-02-12 21:43:14 +00:00
/// </summary>
2018-03-12 14:07:11 +01:00
/// <value>The log file filter.</value>
public IFilter LogFileLogFilter
{
get
{
m_options . TryGetValue ( "log-file-log-filter" , out var value );
2018-04-02 11:20:46 +02:00
return Library . Utility . FilterExpression . ParseLogFilter ( value );
2018-03-12 14:07:11 +01:00
}
}
/// <summary>
/// Gets the filter used for console messages.
/// </summary>
/// <value>The log file filter.</value>
public IFilter ConsoleLogFilter
{
get
{
m_options . TryGetValue ( "console-log-filter" , out var value );
2018-04-02 11:20:46 +02:00
return Library . Utility . FilterExpression . ParseLogFilter ( value );
2014-08-12 11:02:03 +02:00
}
}
2013-02-12 21:43:14 +00:00
/// <summary>
2018-03-12 14:07:11 +01:00
/// Gets the console log detail level
2013-02-12 21:43:14 +00:00
/// </summary>
2018-03-12 14:07:11 +01:00
public Duplicati . Library . Logging . LogMessageType ConsoleLoglevel
2013-02-12 21:43:14 +00:00
{
get
{
string value ;
2018-03-12 14:07:11 +01:00
if (! m_options . TryGetValue ( "console-log-level" , out value ))
2013-02-12 21:43:14 +00:00
value = null ;
2018-03-12 14:07:11 +01:00
if ( string . IsNullOrWhiteSpace ( value ))
if (! m_options . TryGetValue ( "log-level" , out value ))
value = null ;
2013-02-12 21:43:14 +00:00
foreach ( string s in Enum . GetNames ( typeof ( Duplicati . Library . Logging . LogMessageType )))
2017-09-18 23:23:45 -06:00
if ( s . Equals ( value , StringComparison . OrdinalIgnoreCase ))
2013-02-12 21:43:14 +00:00
return ( Duplicati . Library . Logging . LogMessageType ) Enum . Parse ( typeof ( Duplicati . Library . Logging . LogMessageType ), s );
2023-12-11 14:42:45 +01:00
if ( Dryrun )
return Duplicati . Library . Logging . LogMessageType . DryRun ;
else
return Duplicati . Library . Logging . LogMessageType . Warning ;
2013-02-12 21:43:14 +00:00
}
}
2018-08-07 09:40:43 +02:00
/// <summary>
/// A value indicating if all database queries should be logged
/// </summary>
public bool ProfileAllDatabaseQueries { get { return GetBool ( "profile-all-database-queries" ); } }
2013-02-12 21:43:14 +00:00
/// <summary>
/// Gets the attribute filter used to exclude files and folders.
/// </summary>
public System . IO . FileAttributes FileAttributeFilter
{
get
{
2019-09-01 12:40:37 +02:00
System . IO . FileAttributes res = default ( System . IO . FileAttributes );
2013-02-12 21:43:14 +00:00
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" ); } }
2017-04-04 23:51:40 +02:00
/// <summary>
/// A value indicating if the returned value should not be truncated
/// </summary>
public bool FullResult { get { return GetBool ( "full-result" ); } }
2013-05-20 13:48:44 +02:00
/// <summary>
/// A value indicating restored files overwrite existing ones
/// </summary>
public bool Overwrite { get { return GetBool ( "overwrite" ); } }
2013-02-12 21:43:14 +00:00
/// <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
2013-05-08 21:29:59 +02:00
return Library . Utility . Sizeparser . ParseSize ( m_options [ "quota-size" ], "mb" );
2013-02-12 21:43:14 +00:00
}
}
/// <summary>
2018-02-07 11:23:52 -07:00
/// Gets the threshold at which a quota warning should be generated.
/// </summary>
/// <remarks>
/// This is treated as a percentage, where a warning is given when the amount of free space is less than this percentage of the backup size.
/// </remarks>
public int QuotaWarningThreshold
{
get
{
string tmp ;
m_options . TryGetValue ( "quota-warning-threshold" , out tmp );
if ( string . IsNullOrEmpty ( tmp ))
{
return DEFAULT_QUOTA_WARNING_THRESHOLD ;
}
else
{
return int . Parse ( tmp );
}
}
}
2013-02-12 21:43:14 +00:00
/// <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 ;
}
}
2024-03-07 22:11:49 +01:00
/// <summary>
/// Gets the ID of the backup
/// </summary>
public string BackupId
{
get
{
m_options . TryGetValue ( "backup-id" , out var tmp );
return tmp ;
}
}
/// <summary>
/// Gets the ID of the machine
/// </summary>
public string MachineId
{
get
{
if ( m_options . TryGetValue ( "machine-id" , out var tmp ))
return tmp ;
return Library . AutoUpdater . UpdaterManager . InstallID ;
}
}
2013-05-06 09:58:19 +02:00
/// <summary>
/// Gets the path to the database
/// </summary>
2013-05-08 19:57:13 +02:00
public string Dbpath
2013-05-06 09:58:19 +02:00
{
get
{
string tmp ;
2013-05-08 19:57:13 +02:00
m_options . TryGetValue ( "dbpath" , out tmp );
2013-05-06 09:58:19 +02:00
return tmp ;
}
set
{
2013-05-08 19:57:13 +02:00
m_options [ "dbpath" ] = value ;
2013-05-06 09:58:19 +02:00
}
}
2018-06-30 17:28:23 +02:00
/// <summary>
/// Gets a value indicating whether a blocksize has been specified
/// </summary>
public bool HasBlocksize { get { return m_options . ContainsKey ( "blocksize" ) && ! string . IsNullOrEmpty ( m_options [ "blocksize" ]); } }
2013-05-06 09:58:19 +02:00
/// <summary>
/// Gets the size of file-blocks
/// </summary>
2013-05-08 19:57:13 +02:00
public int Blocksize
2013-05-06 09:58:19 +02:00
{
get
{
string tmp ;
2013-05-08 19:57:13 +02:00
if (! m_options . TryGetValue ( "blocksize" , out tmp ))
2013-05-21 21:16:01 +02:00
tmp = DEFAULT_BLOCKSIZE ;
2013-05-06 09:58:19 +02:00
2017-10-08 09:03:21 -07:00
long blocksize = Library . Utility . Sizeparser . ParseSize ( tmp , "kb" );
if ( blocksize > int . MaxValue || blocksize < 1024 )
2017-10-08 09:04:02 -07:00
throw new ArgumentOutOfRangeException ( nameof ( blocksize ), string . Format ( "The blocksize cannot be less than {0}, nor larger than {1}" , 1024 , int . MaxValue ));
2013-05-06 09:58:19 +02:00
2017-10-08 09:03:21 -07:00
return ( int ) blocksize ;
2013-05-06 09:58:19 +02:00
}
}
2018-05-09 17:19:45 +02:00
/// <summary>
/// Cache for the block hash size value, to avoid creating new hash instances just to get the size
/// </summary>
private KeyValuePair < string , int > m_cachedBlockHashSize ;
2013-05-06 09:58:19 +02:00
2015-02-03 23:47:33 +01:00
/// <summary>
2018-05-09 17:19:45 +02:00
/// Gets the size of the blockhash in bytes.
2015-02-03 23:47:33 +01:00
/// </summary>
/// <value>The size of the blockhash.</value>
public int BlockhashSize
{
get
{
2018-05-09 17:19:45 +02:00
if ( m_cachedBlockHashSize . Key != BlockHashAlgorithm )
2021-04-04 11:17:13 -07:00
m_cachedBlockHashSize = new KeyValuePair < string , int >( BlockHashAlgorithm , HashFactory . HashSizeBytes ( BlockHashAlgorithm ));
2018-05-09 17:19:45 +02:00
return m_cachedBlockHashSize . Value ;
2015-02-03 23:47:33 +01:00
}
}
2014-11-19 14:15:11 +01:00
/// <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" ); }
}
2014-11-30 21:32:31 +01:00
2018-04-24 13:11:03 +02:00
/// <summary>
/// Gets a flag indicating if empty folders should be ignored
/// </summary>
public bool ExcludeEmptyFolders
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "exclude-empty-folders" ); }
}
2018-06-07 13:26:28 +02:00
/// <summary>
2019-10-06 09:55:33 -07:00
/// Gets a flag indicating if during restores metadata should be applied to the symlink target.
/// Setting this to true can result in errors if the target no longer exists.
2018-06-07 13:26:28 +02:00
/// </summary>
public bool RestoreSymlinkMetadata
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "restore-symlink-metadata" ); }
}
2018-04-24 13:11:03 +02:00
2014-11-30 21:32:31 +01:00
/// <summary>
/// Gets a flag indicating if permissions should be restored
/// </summary>
public bool RestorePermissions
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "restore-permissions" ); }
}
2014-12-30 16:10:45 +01:00
/// <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" ); }
}
2014-10-31 15:14:30 +01:00
/// <summary>
2016-12-24 11:42:26 +01:00
/// Gets a flag indicating if synthetic filelist generation is disabled
2014-10-31 15:14:30 +01:00
/// </summary>
2016-12-24 11:42:26 +01:00
public bool DisableSyntheticFilelist
2014-10-31 15:14:30 +01:00
{
2016-12-24 11:42:26 +01:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "disable-synthetic-filelist" ); }
2013-05-06 09:58:19 +02:00
}
2017-09-16 18:44:25 +02:00
/// <summary>
/// Flag indicating if the in-memory block cache is used
/// </summary>
public bool UseBlockCache
{
get
{
2017-09-19 12:51:40 +02:00
return Library . Utility . Utility . ParseBoolOption ( m_options , "use-block-cache" );
2017-09-18 23:23:45 -06:00
}
2017-09-16 18:44:25 +02:00
}
2013-05-06 09:58:19 +02:00
/// <summary>
2013-05-21 21:16:01 +02:00
/// Gets the compact threshold
2013-05-06 09:58:19 +02:00
/// </summary>
2013-05-21 21:16:01 +02:00
public long Threshold
2013-05-06 09:58:19 +02:00
{
get
{
string v ;
2013-05-21 21:16:01 +02:00
m_options . TryGetValue ( "threshold" , out v );
2013-05-06 09:58:19 +02:00
if ( string . IsNullOrEmpty ( v ))
2013-05-21 21:16:01 +02:00
return DEFAULT_THRESHOLD ;
2013-05-06 09:58:19 +02:00
2013-05-21 21:16:01 +02:00
return Convert . ToInt64 ( v );
2013-05-06 09:58:19 +02:00
}
}
/// <summary>
2013-05-21 21:16:01 +02:00
/// Gets the size of small volumes
2013-05-06 09:58:19 +02:00
/// </summary>
2013-05-21 21:16:01 +02:00
public long SmallFileSize
2013-05-06 09:58:19 +02:00
{
get
{
string v ;
2013-05-21 21:16:01 +02:00
m_options . TryGetValue ( "small-file-size" , out v );
2013-05-06 09:58:19 +02:00
if ( string . IsNullOrEmpty ( v ))
2013-05-25 18:00:46 +02:00
return this . VolumeSize / 5 ;
2013-05-06 09:58:19 +02:00
2013-05-08 21:29:59 +02:00
return Library . Utility . Sizeparser . ParseSize ( v , "mb" );
2013-05-06 09:58:19 +02:00
}
}
2013-05-21 21:16:01 +02:00
/// <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 );
}
}
2013-05-06 09:58:19 +02:00
/// <summary>
/// List of files to check for changes
/// </summary>
2013-05-08 19:57:13 +02:00
public string [] ChangedFilelist
2013-05-06 09:58:19 +02:00
{
get
{
string v ;
2013-05-11 22:56:21 +02:00
m_options . TryGetValue ( "changed-files" , out v );
2013-05-06 09:58:19 +02:00
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>
2013-05-08 19:57:13 +02:00
public string [] DeletedFilelist
2013-05-06 09:58:19 +02:00
{
get
{
string v ;
2013-05-11 22:56:21 +02:00
m_options . TryGetValue ( "deleted-files" , out v );
2013-05-06 09:58:19 +02:00
if ( string . IsNullOrEmpty ( v ))
return null ;
return v . Split ( new char [] { System . IO . Path . PathSeparator }, StringSplitOptions . RemoveEmptyEntries );
}
}
2013-05-13 22:32:05 +02:00
2018-04-24 11:25:37 +02:00
/// <summary>
/// List of filenames that are used to exclude a folder
/// </summary>
public string [] IgnoreFilenames
{
get
{
string v ;
m_options . TryGetValue ( "ignore-filenames" , out v );
if ( string . IsNullOrEmpty ( v ))
return null ;
return v . Split ( new char [] { System . IO . Path . PathSeparator }, StringSplitOptions . RemoveEmptyEntries );
}
}
2013-05-13 22:32:05 +02:00
/// <summary>
/// Alternate restore path
/// </summary>
public string Restorepath
{
get
{
string v ;
m_options . TryGetValue ( "restore-path" , out v );
return v ;
}
}
2013-05-06 09:58:19 +02:00
/// <summary>
2013-07-01 10:33:07 +02:00
/// Gets the index file usage method
2013-05-06 09:58:19 +02:00
/// </summary>
2013-07-01 10:33:07 +02:00
public IndexFileStrategy IndexfilePolicy
2013-05-06 09:58:19 +02:00
{
2013-07-01 10:33:07 +02:00
get
{
string strategy ;
if (! m_options . TryGetValue ( "index-file-policy" , out strategy ))
strategy = "" ;
IndexFileStrategy res ;
if (! Enum . TryParse ( strategy , true , out res ))
2013-08-31 13:36:12 +02:00
res = IndexFileStrategy . Full ;
2013-07-01 10:33:07 +02:00
return res ;
}
2013-05-06 09:58:19 +02:00
}
/// <summary>
/// Gets a flag indicating if the check for files on the remote storage should be omitted
/// </summary>
2013-05-08 19:57:13 +02:00
public bool NoBackendverification
2013-05-06 09:58:19 +02:00
{
2013-05-20 14:05:49 +02:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "no-backend-verification" ); }
2013-05-06 09:58:19 +02:00
}
2013-08-24 20:59:09 +02:00
2019-09-01 12:40:37 +02:00
/// <summary>
/// Gets the percentage of samples to test during a backup operation
/// </summary>
public long BackupTestPercentage
{
get
{
m_options . TryGetValue ( "backup-test-percentage" , out string s );
if ( string . IsNullOrEmpty ( s ))
{
return 0 ;
}
long percentage ;
try
{
percentage = long . Parse ( s );
}
catch ( Exception ex )
{
throw new ArgumentException ( "The value provided for the backup-test-percentage option must lie between 0 and 100." , ex );
}
if (( percentage < 0 ) || ( percentage > 100 ))
{
throw new ArgumentOutOfRangeException ( nameof ( percentage ), "The value provided for the backup-test-percentage option must lie between 0 and 100." );
}
return percentage ;
}
}
2013-08-24 20:59:09 +02:00
/// <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 );
}
}
2013-05-06 09:58:19 +02:00
/// <summary>
/// Gets a flag indicating if compacting should not be done automatically
/// </summary>
2013-05-08 19:57:13 +02:00
public bool NoAutoCompact
2013-05-06 09:58:19 +02:00
{
2013-05-08 21:29:59 +02:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "no-auto-compact" ); }
2013-05-06 09:58:19 +02:00
}
2019-09-01 12:40:37 +02:00
/// <summary>
/// Gets the minimum time that must elapse after last compaction before running next automatic compaction
/// </summary>
public TimeSpan AutoCompactInterval
{
get
{
if (! m_options . ContainsKey ( "auto-compact-interval" ) || string . IsNullOrEmpty ( m_options [ "auto-compact-interval" ]))
return TimeSpan . Zero ;
else
return Library . Utility . Timeparser . ParseTimeSpan ( m_options [ "auto-compact-interval" ]);
}
}
2013-05-13 22:32:05 +02:00
/// <summary>
/// Gets a flag indicating if compacting should not be done automatically
/// </summary>
2013-06-29 12:17:52 +02:00
public bool AllowMissingSource
2013-05-13 22:32:05 +02:00
{
2013-06-29 12:17:52 +02:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "allow-missing-source" ); }
2013-05-13 22:32:05 +02:00
}
2013-07-01 14:40:45 +02:00
/// <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" ); }
}
2013-10-29 11:43:44 +01:00
/// <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" ); }
}
2013-05-13 22:32:05 +02:00
2013-05-06 09:58:19 +02:00
/// <summary>
/// Gets a flag indicating if the current operation should merely output the changes
/// </summary>
2013-05-08 19:57:13 +02:00
public bool Dryrun
2013-05-06 09:58:19 +02:00
{
2013-05-11 22:56:21 +02:00
get
{
2016-09-15 11:39:27 +02:00
if ( m_options . ContainsKey ( "dry-run" ))
return Library . Utility . Utility . ParseBoolOption ( m_options , "dry-run" );
else
return Library . Utility . Utility . ParseBoolOption ( m_options , "dryrun" );
2013-05-11 22:56:21 +02:00
}
2013-05-06 09:58:19 +02:00
}
2014-03-10 14:16:27 +01:00
/// <summary>
2023-12-10 00:24:07 +01:00
/// Gets a value indicating if the remote verification is deep
2014-03-10 14:16:27 +01:00
/// </summary>
2023-12-10 00:24:07 +01:00
public RemoteTestStrategy FullRemoteVerification
2014-03-10 14:16:27 +01:00
{
2023-12-10 00:24:07 +01:00
get
{
string policy ;
if (! m_options . TryGetValue ( "full-remote-verification" , out policy ))
policy = "False" ;
RemoteTestStrategy r ;
if (! Enum . TryParse ( policy , true , out r ))
r = RemoteTestStrategy . True ;
return r ;
}
2014-03-10 14:16:27 +01:00
}
2013-05-06 09:58:19 +02:00
/// <summary>
/// The block hash algorithm to use
/// </summary>
2013-05-08 19:57:13 +02:00
public string BlockHashAlgorithm
2013-05-06 09:58:19 +02:00
{
get
{
string v ;
2013-05-08 19:57:13 +02:00
m_options . TryGetValue ( "block-hash-algorithm" , out v );
2013-05-06 09:58:19 +02:00
if ( string . IsNullOrEmpty ( v ))
return DEFAULT_BLOCK_HASH_ALGORITHM ;
return v ;
}
}
/// <summary>
/// The file hash algorithm to use
/// </summary>
2013-05-08 19:57:13 +02:00
public string FileHashAlgorithm
2013-05-06 09:58:19 +02:00
{
get
{
string v ;
2013-05-08 19:57:13 +02:00
m_options . TryGetValue ( "file-hash-algorithm" , out v );
2013-05-06 09:58:19 +02:00
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>
2013-05-08 19:57:13 +02:00
public bool PatchWithLocalBlocks
2013-05-06 09:58:19 +02:00
{
2021-09-03 13:34:26 -07:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "patch-with-local-blocks" ); }
2013-05-06 09:58:19 +02:00
}
2015-01-27 22:12:52 +01:00
/// <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>
2013-05-06 09:58:19 +02:00
public bool NoLocalBlocks
{
2013-05-08 21:29:59 +02:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "no-local-blocks" ); }
2013-05-06 09:58:19 +02:00
}
2013-09-10 22:41:05 +02:00
/// <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>
2013-05-06 09:58:19 +02:00
public bool NoLocalDb
{
2013-05-08 21:29:59 +02:00
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "no-local-db" ); }
2013-05-06 09:58:19 +02:00
}
2015-01-27 22:21:43 +01:00
2017-01-06 23:01:54 +01:00
/// <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 DontCompressRestorePaths
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "dont-compress-restore-paths" ); }
}
2015-01-27 22:21:43 +01:00
/// <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" ); }
}
2015-04-08 20:19:46 +02:00
/// <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" ); }
}
2015-02-15 23:26:52 +01:00
2023-11-05 18:19:08 +01:00
/// <summary>
/// Gets a flag indicating if the repair process will always use blocks
/// </summary>
/// <value><c>true</c> if repair process always use blocks; otherwise, <c>false</c>.</value>
public bool RepairForceBlockUse
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "repair-force-block-use" ); }
}
2017-08-04 12:09:01 +01:00
/// <summary>
/// Gets a flag indicating whether the VACUUM operation should ever be run automatically.
/// </summary>
public bool AutoVacuum
{
get { return GetBool ( "auto-vacuum" ); }
}
2019-09-01 12:40:37 +02:00
/// <summary>
/// Gets the minimum time that must elapse after last vacuum before running next automatic vacuum
/// </summary>
public TimeSpan AutoVacuumInterval
{
get
{
if (! m_options . ContainsKey ( "auto-vacuum-interval" ) || string . IsNullOrEmpty ( m_options [ "auto-vacuum-interval" ]))
return TimeSpan . Zero ;
else
return Library . Utility . Timeparser . ParseTimeSpan ( m_options [ "auto-vacuum-interval" ]);
}
}
2018-02-11 20:57:38 +01:00
/// <summary>
/// Gets a flag indicating if the local filescanner should be disabled
/// </summary>
/// <value><c>true</c> if the filescanner should be disabled; otherwise, <c>false</c>.</value>
public bool DisableFileScanner
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "disable-file-scanner" ); }
}
2018-08-14 15:21:54 +02:00
/// <summary>
/// Gets a flag indicating if the filelist consistency checks should be disabled
/// </summary>
/// <value><c>true</c> if the filelist consistency checks should be disabled; otherwise, <c>false</c>.</value>
public bool DisableFilelistConsistencyChecks
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "disable-filelist-consistency-checks" ); }
}
2018-03-04 12:29:56 -08:00
/// <summary>
/// Gets a flag indicating whether the backup should be disabled when on battery power.
/// </summary>
/// <value><c>true</c> if the backup should be disabled when on battery power; otherwise, <c>false</c>.</value>
public bool DisableOnBattery
{
get { return Library . Utility . Utility . ParseBoolOption ( m_options , "disable-on-battery" ); }
}
2018-08-07 11:14:28 +02:00
/// <summary>
/// Gets a value indicating if missing dblock files are attempted created
/// </summary>
public bool RebuildMissingDblockFiles
{
get { return GetBool ( "rebuild-missing-dblock-files" ); }
}
2015-02-15 23:26:52 +01:00
/// <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 );
}
}
2016-04-04 22:43:07 +02:00
/// <summary>
/// Gets the number of concurrent threads
/// </summary>
public int ConcurrencyMaxThreads
{
get
{
string value ;
if (! m_options . TryGetValue ( "concurrency-max-threads" , out value ))
value = null ;
if ( string . IsNullOrEmpty ( value ))
return 0 ;
else
return int . Parse ( value );
}
}
/// <summary>
/// Gets the number of concurrent block hashers
/// </summary>
public int ConcurrencyBlockHashers
{
get
{
string value ;
if (! m_options . TryGetValue ( "concurrency-block-hashers" , out value ))
value = null ;
if ( string . IsNullOrEmpty ( value ))
return DEFAULT_BLOCK_HASHERS ;
else
return Math . Max ( 1 , int . Parse ( value ));
}
}
/// <summary>
/// Gets the number of concurrent block hashers
/// </summary>
public int ConcurrencyCompressors
{
get
{
string value ;
if (! m_options . TryGetValue ( "concurrency-compressors" , out value ))
value = null ;
if ( string . IsNullOrEmpty ( value ))
return DEFAULT_COMPRESSORS ;
else
return Math . Max ( 1 , int . Parse ( value ));
}
}
2013-02-27 20:57:58 +00:00
/// <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 )
{
2021-05-09 15:16:31 -05:00
var hints = new Dictionary < string , CompressionHint >( StringComparer . OrdinalIgnoreCase ); // Ignore file system case sensitivity, since file extensions case rarely indicates type
2013-02-27 20:57:58 +00:00
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 ))
2013-05-08 21:29:59 +02:00
foreach ( var _line in Library . Utility . Utility . ReadFileWithDefaultEncoding ( file ). Split ( '\n' ))
2013-02-27 20:57:58 +00:00
{
var line = _line . Trim ();
var lix = line . IndexOf ( ' ' );
if ( lix > 0 )
line = line . Substring ( 0 , lix );
if ( line . Length >= 2 && line [ 0 ] == '.' )
2016-04-05 23:29:14 +02:00
hints [ line ] = CompressionHint . Noncompressible ;
2013-02-27 20:57:58 +00:00
}
2016-04-05 23:29:14 +02:00
//Don't try again, if the file does not exist
m_compressionHints = hints ;
2013-02-27 20:57:58 +00:00
}
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 ;
}
2013-02-12 21:43:14 +00:00
/// <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 )
{
2013-05-08 21:29:59 +02:00
return Library . Utility . Utility . ParseBoolOption ( m_options , name );
2013-02-12 21:43:14 +00:00
}
2018-02-18 16:47:04 +01:00
/// <summary>
2019-11-30 11:35:43 -08:00
/// Class for handling a single RetentionPolicy timeframe-interval-pair
2018-02-18 16:47:04 +01:00
/// </summary>
public class RetentionPolicyValue
{
public readonly TimeSpan Timeframe ;
public readonly TimeSpan Interval ;
public RetentionPolicyValue ( TimeSpan timeframe , TimeSpan interval )
{
if ( timeframe < TimeSpan . Zero )
{
throw new ArgumentOutOfRangeException ( nameof ( timeframe ), string . Format ( "The timeframe cannot be negative: '{0}'" , timeframe ));
}
if ( interval < TimeSpan . Zero )
{
throw new ArgumentOutOfRangeException ( nameof ( interval ), string . Format ( "The interval cannot be negative: '{0}'" , interval ));
}
this . Timeframe = timeframe ;
this . Interval = interval ;
}
/// <summary>
/// Returns whether this is an unlimited timeframe or not
/// </summary>
/// <returns></returns>
public Boolean IsUnlimtedTimeframe ()
{
2019-11-30 11:35:43 -08:00
// Timeframes equal or bigger than the maximum TimeSpan effectively represent an unlimited timeframe
2018-02-18 16:47:04 +01:00
return Timeframe >= TimeSpan . MaxValue ;
}
/// <summary>
/// Returns whether all versions in this timeframe should be kept or not
/// </summary>
/// <returns></returns>
public Boolean IsKeepAllVersions ()
{
/// Intervals between two versions that are equal or smaller than zero effectivly result in
/// all versions in that timeframe being kept.
return Interval <= TimeSpan . Zero ;
}
public override string ToString ()
{
return ( IsUnlimtedTimeframe () ? "Unlimited" : Timeframe . ToString ()) + " / " + ( IsKeepAllVersions () ? "Keep all" : Interval . ToString ());
}
/// <summary>
2019-11-30 11:35:43 -08:00
/// Parses a string representation of a timeframe-interval-pair and returns a RetentionPolicyValue object
2018-02-18 16:47:04 +01:00
/// </summary>
/// <returns></returns>
public static RetentionPolicyValue CreateFromString ( string rententionPolicyValueString )
{
var periodInterval = rententionPolicyValueString . Split ( ':' );
TimeSpan timeframe ;
2019-11-30 11:35:43 -08:00
// Timeframe "U" (= Unlimited) means: For unlimited time keep one version every X interval.
2018-02-18 16:47:04 +01:00
// So the timeframe has to span the maximum time possible.
if ( String . Equals ( periodInterval [ 0 ], "U" , StringComparison . OrdinalIgnoreCase ))
{
timeframe = TimeSpan . MaxValue ;
}
else
{
timeframe = Library . Utility . Timeparser . ParseTimeSpan ( periodInterval [ 0 ]);
}
TimeSpan interval ;
// Interval "U" (= Unlimited) means: For period X keep all versions.
// So the interval between two versions has to be zero.
if ( String . Equals ( periodInterval [ 1 ], "U" , StringComparison . OrdinalIgnoreCase ))
{
interval = TimeSpan . Zero ;
}
else
{
interval = Library . Utility . Timeparser . ParseTimeSpan ( periodInterval [ 1 ]);
}
return new RetentionPolicyValue ( timeframe , interval );
}
}
2013-02-12 21:43:14 +00:00
}
}