Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Duplicati/Server/Database/Connection.cs')
-rw-r--r--Duplicati/Server/Database/Connection.cs131
1 files changed, 117 insertions, 14 deletions
diff --git a/Duplicati/Server/Database/Connection.cs b/Duplicati/Server/Database/Connection.cs
index 0a1f5a5b5..4e4de0c8a 100644
--- a/Duplicati/Server/Database/Connection.cs
+++ b/Duplicati/Server/Database/Connection.cs
@@ -354,16 +354,104 @@ namespace Duplicati.Server.Database
}
}
- internal void AddOrUpdateBackup(IBackup item)
- {
- AddOrUpdateBackup(item, false, null);
- }
-
internal void AddOrUpdateBackupAndSchedule(IBackup item, ISchedule schedule)
{
AddOrUpdateBackup(item, true, schedule);
}
+ internal string ValidateBackup(IBackup item, ISchedule schedule)
+ {
+ if (string.IsNullOrWhiteSpace(item.Name))
+ return "Missing a name";
+
+ if (string.IsNullOrWhiteSpace(item.TargetURL))
+ return "Missing a target";
+
+ if (item.Sources == null || item.Sources.Any(x => string.IsNullOrWhiteSpace(x)) || item.Sources.Length == 0)
+ return "Invalid source list";
+
+ var disabled_encryption = false;
+ var passphrase = string.Empty;
+ if (item.Settings != null)
+ {
+ foreach (var s in item.Settings)
+ if (string.Equals(s.Name, "--no-encryption", StringComparison.OrdinalIgnoreCase))
+ disabled_encryption = string.IsNullOrWhiteSpace(s.Value) ? true : Library.Utility.Utility.ParseBool(s.Value, false);
+ else if (string.Equals(s.Name, "passphrase", StringComparison.OrdinalIgnoreCase))
+ passphrase = s.Value;
+ else if (string.Equals(s.Name, "keep-versions", StringComparison.OrdinalIgnoreCase))
+ {
+ int i;
+ if (!int.TryParse(s.Value, out i) || i <= 0)
+ return "Retention value must be a positive integer";
+ }
+ else if (string.Equals(s.Name, "keep-time", StringComparison.OrdinalIgnoreCase))
+ {
+ try
+ {
+ var ts = Library.Utility.Timeparser.ParseTimeSpan(s.Value);
+ if (ts <= TimeSpan.FromMinutes(5))
+ return "Retention value must be more than 5 minutes";
+ }
+ catch
+ {
+ return "Retention value must be a valid timespan";
+ }
+ }
+ else if (string.Equals(s.Name, "dblock-size", StringComparison.OrdinalIgnoreCase))
+ {
+ try
+ {
+ var ds = Library.Utility.Sizeparser.ParseSize(s.Value);
+ if (ds < 1024 * 1024)
+ return "DBlock size must be at least 1MB";
+ }
+ catch
+ {
+ return "DBlock value must be a valid size string";
+ }
+ }
+ else if (string.Equals(s.Name, "--blocksize", StringComparison.OrdinalIgnoreCase))
+ {
+ try
+ {
+ var ds = Library.Utility.Sizeparser.ParseSize(s.Value);
+ if (ds < 1024 || ds > int.MaxValue)
+ return "The blocksize must be at least 1KB";
+ }
+ catch
+ {
+ return "The blocksize value must be a valid size string";
+ }
+ }
+ else if (string.Equals(s.Name, "--prefix", StringComparison.OrdinalIgnoreCase))
+ {
+ if (!string.IsNullOrWhiteSpace(s.Value) && s.Value.Contains("-"))
+ return "The prefix cannot contain hyphens (-)";
+ }
+ }
+
+ if (!disabled_encryption && string.IsNullOrWhiteSpace(passphrase))
+ return "Missing passphrase";
+
+ if (schedule != null)
+ {
+ try
+ {
+ var ts = Library.Utility.Timeparser.ParseTimeSpan(schedule.Repeat);
+ if (ts <= TimeSpan.FromMinutes(5))
+ return "Schedule repetition time must be more than 5 minutes";
+ }
+ catch
+ {
+ return "Schedule repetition value must be a valid timespan";
+ }
+
+ }
+
+ return null;
+ }
+
internal void UpdateBackupDBPath(IBackup item, string path)
{
lock(m_lock)
@@ -392,7 +480,7 @@ namespace Duplicati.Server.Database
bool update = item.ID != null;
if (!update && item.DBPath == null)
{
- var folder = Program.DATAFOLDER;
+ var folder = Program.DataFolder;
if (!System.IO.Directory.Exists(folder))
System.IO.Directory.CreateDirectory(folder);
@@ -747,7 +835,8 @@ namespace Duplicati.Server.Database
),
@"SELECT ""Key"", ""Value"" FROM ""UIStorage"" WHERE ""Scheme"" = ?",
scheme)
- .ToDictionary(x => x.Key, x => x.Value);
+ .GroupBy(x => x.Key)
+ .ToDictionary(x => x.Key, x => x.Last().Value);
}
public void SetUISettings(string scheme, IDictionary<string, string> values, System.Data.IDbTransaction transaction = null)
@@ -770,6 +859,27 @@ namespace Duplicati.Server.Database
}
}
+ public void UpdateUISettings(string scheme, IDictionary<string, string> values, System.Data.IDbTransaction transaction = null)
+ {
+ lock (m_lock)
+ using (var tr = transaction == null ? m_connection.BeginTransaction() : null)
+ {
+ OverwriteAndUpdateDb(
+ tr,
+ @"DELETE FROM ""UIStorage"" WHERE ""Scheme"" = ? AND ""Key"" IN (?)", new object[] { scheme, values.Keys },
+ values.Where(x => x.Value != null),
+ @"INSERT INTO ""UIStorage"" (""Scheme"", ""Key"", ""Value"") VALUES (?, ?, ?)",
+ (f) =>
+ {
+ return new object[] { scheme, f.Key ?? "", f.Value ?? "" };
+ }
+ );
+
+ if (tr != null)
+ tr.Commit();
+ }
+ }
+
public TempFile[] GetTempFiles()
{
lock(m_lock)
@@ -823,13 +933,6 @@ namespace Duplicati.Server.Database
tr.Commit();
}
-
- using(var cmd = m_connection.CreateCommand())
- {
- cmd.CommandText = "VACUUM";
- cmd.ExecuteNonQuery();
- }
-
}
private static long NormalizeDateTimeToEpochSeconds(DateTime input)