Rebuild the state from the brokers after a restore and refuse an older copy
A restore, an import or an adopted database restarts protected: the engine stays stopped, reads from the broker what the archive does not know (orders, stops, executions, also from the OKX history up to 89 days), cancels orders left working, protects what it finds and waits for the user. Strategies with real money stay exit only until confirmed again. The database of before the restore, put back by mistake, is refused by its fingerprint. A failed migration leaves the engine off with one backup and a way to try again; an archive is checked whole before the database is touched; a changed secret key no longer crashes anything, and "anubis access reset" gives the access back to whoever holds the computer. The image runs the db and access commands without the guard. refs #69 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3da9b00f44
commit
4897594b87
40 files changed
+1871
-90
No files matched your search
@@ -9,11 +9,13 @@ public sealed record BackupInfo(string Folder, string Name, DateTimeOffset Taken
|
||||
|
||||
/// <summary>
|
||||
/// Backups (SPEC 5.4): the engine-independent archive, plus a consistent copy of the SQLite file made with the
|
||||
/// backup API. Nightly at 03:30 Italian time, before every migration, and on request. The last 14 are kept.
|
||||
/// backup API. Nightly at 03:30 Italian time, before every migration, and on request. The last 14 nightly ones are
|
||||
/// kept, and separately the last 14 of each other kind, so a series of one kind never pushes out the others.
|
||||
/// </summary>
|
||||
public sealed class Backups(DataDirectory data, IClock clock)
|
||||
{
|
||||
public const int Keep = 14;
|
||||
public const string BeforeMigration = "prima-della-migrazione";
|
||||
public const string ArchiveFolder = "archivio";
|
||||
public const string SqliteCopy = "anubis.sqlite3";
|
||||
|
||||
@@ -37,6 +39,7 @@ public sealed class Backups(DataDirectory data, IClock clock)
|
||||
if (db.Engine == DbEngine.Sqlite)
|
||||
{
|
||||
await db.BackupSqliteFileAsync(Path.Combine(temp, SqliteCopy), cancellationToken).ConfigureAwait(false);
|
||||
await Installation.SealCopyAsync(Path.Combine(temp, SqliteCopy), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Directory.Move(temp, folder);
|
||||
@@ -69,10 +72,23 @@ public sealed class Backups(DataDirectory data, IClock clock)
|
||||
|
||||
private void Prune()
|
||||
{
|
||||
foreach (var old in List().Skip(Keep))
|
||||
foreach (var old in List().GroupBy(b => Kind(b.Reason)).SelectMany(g => g.Skip(Keep)))
|
||||
{
|
||||
Directory.Delete(old.Folder, recursive: true);
|
||||
}
|
||||
|
||||
// What a backup cut off by a power failure left behind; one under way right now is younger than a day.
|
||||
foreach (var partial in Directory.EnumerateDirectories(data.Backups, "*.partial").Where(d => clock.UtcNow - new DateTimeOffset(Directory.GetLastWriteTimeUtc(d)) > TimeSpan.FromDays(1)))
|
||||
{
|
||||
Directory.Delete(partial, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
// "notturno-2" is the second of the same second: the number is not part of the kind.
|
||||
private static string Kind(string reason)
|
||||
{
|
||||
var dash = reason.LastIndexOf('-');
|
||||
return dash > 0 && int.TryParse(reason[(dash + 1)..], NumberStyles.None, CultureInfo.InvariantCulture, out _) ? reason[..dash] : reason;
|
||||
}
|
||||
|
||||
private static BackupInfo? Describe(string folder)
|
||||
|
||||
Reference in new issue
Block a user