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
@@ -40,7 +40,15 @@ internal static class DatabaseCommand
|
||||
var folder = Path.GetFullPath(args[1]);
|
||||
try
|
||||
{
|
||||
await using var db = Database.Open(config.Db!, allowCreate: args[0] == "import" && !File.Exists(config.Data.InstallationFile));
|
||||
if (args[0] == "import")
|
||||
{
|
||||
// Read before the database is opened: a wrong folder must not leave a new empty SQLite file behind.
|
||||
await Archive.ReadIndexAsync(folder).ConfigureAwait(false);
|
||||
config.Data.Ensure();
|
||||
}
|
||||
|
||||
// Moving to SQLite, the file does not exist yet: the user asked for it by name, unlike a start (trap 20).
|
||||
await using var db = Database.Open(config.Db!, allowCreate: args[0] == "import");
|
||||
if (args[0] == "export")
|
||||
{
|
||||
var index = await Archive.ExportAsync(db, folder, clock).ConfigureAwait(false);
|
||||
@@ -48,14 +56,13 @@ internal static class DatabaseCommand
|
||||
return 0;
|
||||
}
|
||||
|
||||
config.Data.Ensure();
|
||||
var imported = await Archive.ImportAsync(db, folder, clock).ConfigureAwait(false);
|
||||
await Installation.RenewAsync(db, config.Data, clock, adoptDatabaseIdentity: !File.Exists(config.Data.InstallationFile)).ConfigureAwait(false);
|
||||
await Installation.RenewAsync(db, config.Data, clock, "Archivio importato").ConfigureAwait(false);
|
||||
await output.WriteLineAsync($"Importate {imported.Tables.Sum(t => t.Count)} righe di {imported.Tables.Count} tabelle: conteggi e totali coincidono. " +
|
||||
"Al prossimo avvio il bot riparte protetto.").ConfigureAwait(false);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidOperationException or SchemaException or System.Text.Json.JsonException or System.Data.Common.DbException)
|
||||
catch (Exception ex) when (Forms.IsArchiveProblem(ex))
|
||||
{
|
||||
await output.WriteLineAsync("Non riuscito: " + Redactor.Redact(ex.Message)).ConfigureAwait(false);
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user