OneDrive Backup

OneDrive Backup
This commit is contained in:
2023-07-28 22:36:06 +07:00
parent e1c6e91a0a
commit d70d81ebdf
244 changed files with 75229 additions and 0 deletions
+125
View File
@@ -0,0 +1,125 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
namespace hassio_onedrive_backup.Contracts
{
public class AddonOptions
{
[JsonProperty("local_backup_num_to_keep")]
public int MaxLocalBackups { get; set; }
[JsonProperty("onedrive_backup_num_to_keep")]
public int MaxOnedriveBackups { get; set; }
[JsonProperty("backup_interval_days")]
public float BackupIntervalDays { get; set; }
[JsonProperty("backup_passwd")]
public string? BackupPassword { get; set; }
[JsonProperty("backup_name")]
public string? BackupName { get; set; }
[JsonProperty("monitor_all_local_backups")]
public bool MonitorAllLocalBackups{ get; set; }
[JsonProperty("notify_on_error")]
public bool NotifyOnError { get; set; }
[JsonProperty("hass_api_timeout_minutes")]
public int HassAPITimeoutMinutes { get; set; }
[JsonProperty("exclude_media_folder")]
public bool ExcludeMediaFolder { get; set; }
[JsonProperty("exclude_ssl_folder")]
public bool ExcludeSSLFolder { get; set; }
[JsonProperty("exclude_share_folder")]
public bool ExcludeShareFolder { get; set; }
[JsonProperty("exclude_local_addons_folder")]
public bool ExcludeLocalAddonsFolder { get; set; }
[JsonProperty("backup_allowed_hours")]
public string? BackupAllowedHours { get; set; }
[JsonProperty("backup_instance_name")]
public string? InstanceName { get; set; }
[JsonProperty("sync_paths")]
public List<string>? SyncPaths { get; set; }
[JsonProperty("file_sync_remove_deleted")]
public bool FileSyncRemoveDeleted { get; set; } = false;
[JsonProperty("excluded_addons")]
public List<string> ExcludedAddons { get; set; } = new List<string>();
[JsonProperty("log_level")]
public string LogLevelStr { get; set; }
[JsonProperty("ignore_upgrade_backups")]
public bool IgnoreUpgradeBackups { get; set; }
//[JsonProperty("upload_speed_cap")]
//public int? UploadSpeedCapKBPerSecond { get; set; }
[JsonIgnore]
public ConsoleLogger.LogLevel LogLevel => LogLevelStr switch
{
"verbose" => ConsoleLogger.LogLevel.Verbose,
"info" => ConsoleLogger.LogLevel.Info,
"warning" => ConsoleLogger.LogLevel.Warning,
"error" => ConsoleLogger.LogLevel.Error,
_ => ConsoleLogger.LogLevel.Info
};
[JsonIgnore]
public string BackupPasswordSafe => string.IsNullOrEmpty(BackupPassword) ? "backup" : BackupPassword;
[JsonIgnore]
public float BackupIntervalHours => BackupIntervalDays * 24;
[JsonIgnore]
public string BackupNameSafe => string.IsNullOrEmpty(BackupName) ? "hass_backup" : BackupName;
[JsonIgnore]
public bool IsPartialBackup => ExcludeLocalAddonsFolder || ExcludeMediaFolder || ExcludeShareFolder || ExcludeSSLFolder || ExcludedAddons.Any();
[JsonIgnore]
public bool FileSyncEnabled => SyncPaths != null && SyncPaths.Count > 0;
//[JsonIgnore]
//public bool UploadSpeedCap => UploadSpeedCapKBPerSecond != null;
public List<string> IncludedFolderList
{
get
{
List<string> folders = new List<string>();
if (!ExcludeLocalAddonsFolder)
{
folders.Add("addons/local");
}
if (!ExcludeMediaFolder)
{
folders.Add("media");
}
if (!ExcludeShareFolder)
{
folders.Add("share");
}
if (!ExcludeSSLFolder)
{
folders.Add("ssl");
}
return folders;
}
}
}
}
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
namespace onedrive_backup.Contracts
{
public class HassAddonInfoResponse
{
[JsonProperty("data")]
public Data DataProperty { get; set; }
public class Data
{
[JsonProperty("ingress_entry")]
public string IngressEntry { get; set; }
[JsonProperty("ingress_url")]
public string IngressUrl { get; set; }
}
}
}
@@ -0,0 +1,30 @@
using Newtonsoft.Json;
namespace hassio_onedrive_backup.Contracts
{
public class HassAddonsResponse
{
[JsonProperty("result")]
public string Result { get; set; }
[JsonProperty("data")]
public Data DataProperty { get; set; }
public class Data
{
[JsonProperty("addons")]
public Addon[] Addons { get; set; }
}
public class Addon
{
[JsonProperty("slug")]
public string Slug { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
}
}
@@ -0,0 +1,59 @@
using Newtonsoft.Json;
namespace hassio_onedrive_backup.Contracts
{
public class HassBackupsResponse
{
[JsonProperty("result")]
public string Result { get; set; }
[JsonProperty("data")]
public Data DataProperty { get; set; }
public class Data
{
[JsonProperty("backups")]
public Backup[] Backups { get; set; }
}
public class Backup
{
[JsonProperty("slug")]
public string Slug { get; set; }
[JsonProperty("date")]
public DateTime Date { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("size")]
public float Size { get; set; }
[JsonProperty("protected")]
public bool Protected { get; set; }
[JsonProperty("compressed")]
public bool Compressed { get; set; }
[JsonProperty("content")]
public Content Content { get; set; }
}
public class Content
{
[JsonProperty("homeassistant")]
public bool Homeassistant { get; set; }
[JsonProperty("addons")]
public string[] Addons { get; set; }
[JsonProperty("folders")]
public string[] Folders { get; set; }
}
}
}
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
namespace hassio_onedrive_backup.Contracts
{
public class HassSupervisorInfoResponse
{
[JsonProperty("result")]
public string Result { get; set; }
[JsonProperty("data")]
public Data DataProperty { get; set; }
public class Data
{
[JsonProperty("timezone")]
public string Timezone{ get; set; }
}
}
}
@@ -0,0 +1,9 @@
namespace onedrive_backup.Contracts
{
public class OneDriveFreeSpaceData
{
public double? FreeSpace { get; set; }
public double? TotalSpace { get; set; }
}
}
@@ -0,0 +1,41 @@
namespace hassio_onedrive_backup.Contracts
{
public class OnedriveBackup
{
public OnedriveBackup()
{
}
public OnedriveBackup(string fileName, OnedriveItemDescription itemDescription)
{
FileName = fileName;
Slug = itemDescription.Slug;
BackupDate = itemDescription.BackupDate;
InstanceName = itemDescription.InstanceName;
Type = itemDescription.BackupType;
IsProtected = itemDescription.IsProtected;
Size = itemDescription.Size;
Addons = itemDescription.Addons;
Folders = itemDescription.Folders;
}
public string Slug { get; set; }
public string FileName { get; set; }
public DateTime BackupDate { get; set; }
public string? InstanceName { get; set; }
public string Type { get; set; }
public bool IsProtected { get; set; }
public float Size { get; set; }
public IEnumerable<string> Addons { get; set; }
public IEnumerable<string> Folders { get; set; }
}
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hassio_onedrive_backup.Contracts
{
public class OnedriveItemDescription
{
public string Slug { get; set; }
public DateTime BackupDate { get; set; }
public string? InstanceName { get; set; }
public bool IsProtected { get; set; }
public float Size { get; set; }
public string BackupType { get; set; }
public IEnumerable<string> Addons { get; set; }
public IEnumerable<string> Folders { get; set; }
}
}
+18
View File
@@ -0,0 +1,18 @@
namespace hassio_onedrive_backup.Contracts
{
internal class SyncFileData
{
public SyncFileData(string path, string hash, long size)
{
Path = path ?? throw new ArgumentNullException(nameof(path));
Hash = hash ?? throw new ArgumentNullException(nameof(hash));
Size = size;
}
public string Path { get; }
public string Hash { get; }
public long Size { get; }
}
}