295481cc70
Settings › Database on the server side: provider, version, size, free space and per-table rows/sizes for SQLite, Postgres and SQL Server; maintenance on demand or on a schedule (SQLite VACUUM + optimize, Postgres VACUUM (ANALYZE), SQL Server index reorganize + statistics); and optional periodic backups, off by default: SQLite online copies (backup API, quick_check, gzip) to DATABASE_BACKUP_PATH and/or the S3 store under executer/backups/, SQL Server COPY_ONLY backups into a folder on its own host. Postgres backups are refused with the reason. One task at a time across replicas (claimed with a compare-and-swap in the settings table, with a heartbeat), retention per destination, settings saved with If-Match, downloads behind step-up, and every start, finish, download and delete audited. README documents manual restore per provider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.8 KiB
C#
43 lines
1.8 KiB
C#
using System.Collections.Concurrent;
|
|
using Backend.Maintenance;
|
|
|
|
namespace Backend.Tests;
|
|
|
|
/// <summary>An S3 store in memory for database backups; "not configured" until <see cref="Unavailable"/> is cleared.</summary>
|
|
public sealed class FakeBackupObjectStore : IBackupObjectStore
|
|
{
|
|
public ConcurrentDictionary<string, (byte[] Content, DateTimeOffset Modified)> Objects { get; } = new(StringComparer.Ordinal);
|
|
|
|
public string? Unavailable { get; set; } = "S3 is not configured.";
|
|
|
|
/// <summary>When set, uploads fail with this message.</summary>
|
|
public string? FailUploads { get; set; }
|
|
|
|
public Task<string?> UnavailableAsync(CancellationToken cancellationToken) => Task.FromResult(Unavailable);
|
|
|
|
public Task<IReadOnlyList<BackupObject>> ListAsync(string prefix, CancellationToken cancellationToken)
|
|
=> Task.FromResult<IReadOnlyList<BackupObject>>(Objects
|
|
.Where(o => o.Key.StartsWith(prefix, StringComparison.Ordinal))
|
|
.Select(o => new BackupObject(o.Key, o.Value.Content.Length, o.Value.Modified))
|
|
.ToList());
|
|
|
|
public async Task PutAsync(string key, string filePath, CancellationToken cancellationToken)
|
|
{
|
|
if (FailUploads is { } failure)
|
|
{
|
|
throw new InvalidOperationException(failure);
|
|
}
|
|
|
|
Objects[key] = (await File.ReadAllBytesAsync(filePath, cancellationToken), DateTimeOffset.UtcNow);
|
|
}
|
|
|
|
public Task<(Stream Content, long Length)?> OpenAsync(string key, CancellationToken cancellationToken)
|
|
=> Task.FromResult<(Stream, long)?>(Objects.TryGetValue(key, out var found) ? (new MemoryStream(found.Content), found.Content.Length) : null);
|
|
|
|
public Task DeleteAsync(string key, CancellationToken cancellationToken)
|
|
{
|
|
Objects.TryRemove(key, out _);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|