Part G. Move the data from the Worker to the new database
The Durable Object’s write limit is the problem we are leaving, and it also decides when we can take the data out. The limit resets at 00:00 UTC every day (08:00 in Malaysia). Do not export while the limit is still exceeded.
G.1 What is moved and what is not
Section titled “G.1 What is moved and what is not”| Moved | Not moved, and why |
|---|---|
| Bots and their cards, loaders, instance numbers, releases and history, settings, presets, audit trail, round logs, crash history, rates, flags, backups list | Loader tokens and sign-in data (users, sessions, locks, codes): the existing backup leaves them out on purpose. The owner is created again from the env file; other users and every loader’s token are created again once (see G.4). |
G.2 Prepare (before 00:00 UTC)
Section titled “G.2 Prepare (before 00:00 UTC)”- Stop all bots and loaders on the betting sites, so the daily write allowance is not used up again before the export.
- Make sure the new hub is running and healthy (F.7) and the dashboard opens at app.bideward.com. The database should be empty except for the owner.
- Write down, from the old dashboard if it answers, the number of bots, loaders and releases. You will compare them in G.5.
- Check in Google Drive that the Apps Script backup folder holds recent backups. This is the fallback if the live export fails.
- Secrets inventory. For every name in the section 6 table, write down where its readable copy is: your password manager, a file you saved earlier, or nowhere. Cloudflare cannot show a Worker secret again once it is set, so a value that exists only there must be generated again. Re-generating DASHBOARD_KEY means pasting every loader again, so find the saved copy first. Do this before you fill in F.3.
G.3 Export (after 00:00 UTC)
Section titled “G.3 Export (after 00:00 UTC)”-
At 00:05 UTC or later, open the old dashboard (the workers.dev address) and sign in. If it still says the limit is exceeded, wait; the reset can lag a few minutes. If it still fails after 01:00 UTC, use the newest Drive backup instead (step 3).
-
Run the existing Backup now action (the same one that writes to Drive). Wait for success. Do not start any bot.
-
Open the Drive backup folder and download the newest backup file to your own computer. Do not open it in a shared place and do not send it in a chat; it contains private data.
-
Copy it to the server through Tailscale from your own computer’s terminal (your Tailscale name for the server replaces SERVER):
Terminal window scp backup.json admin@SERVER:/tmp/bideward-import.json -
On the server, keep an archive copy in the root-only folder and put a working copy where the hub’s user can read it:
Terminal window sudo install -d -m 700 -o root -g root /var/backups/bideward/importsudo install -d -m 750 -o bideward-hub -g bideward-hub /var/lib/bideward-hub/importsudo install -m 600 -o root -g root /tmp/bideward-import.json /var/backups/bideward/import/bideward-import.jsonsudo install -m 640 -o root -g bideward-hub /tmp/bideward-import.json /var/lib/bideward-hub/import/bideward-import.jsonsudo shred -u /tmp/bideward-import.jsonsudo sha256sum /var/backups/bideward/import/bideward-import.json
Write the checksum down. It proves later that the file you imported is the file you exported.
G.4 Import
Section titled “G.4 Import”-
Stop the hub: sudo systemctl stop bideward-hub. The import tool uses the same restore code as the dashboard’s Restore (cloudflare/core/backup.mjs), so the rules are identical.
-
Dry run: it reads the file and prints how many rows of each key family it would write, and changes nothing. It runs as the hub’s own limited user, with the same settings file, through systemd so no secret appears on a command line:
Terminal window sudo systemd-run --wait --pipe -p User=bideward-hub -p Group=bideward-hub -p EnvironmentFile=/etc/bideward/hub.env -p WorkingDirectory=/opt/bideward/hub -p ReadWritePaths=/var/lib/bideward-hub /usr/local/bin/node tools/import_backup.mjs --dry-run /var/lib/bideward-hub/import/bideward-import.json
Compare the counts with what you wrote down in G.2.
- Real import: the same command without –dry-run. The tool writes in one transaction per key family and prints the total.
- Remove the working copy (the archive copy stays in the root-only folder): sudo shred -u /var/lib/bideward-hub/import/bideward-import.json. Then start the hub: sudo systemctl start bideward-hub.
- Sign in as the owner. Create any other dashboard users again (Settings → Users). Each loader will show as waiting for approval the first time it connects to the new address; approve it from the dashboard with the control password. This is expected, because loader tokens are not part of the backup.
G.5 Check the import
Section titled “G.5 Check the import”-
Counts per key family in the database against the counts in the file (the tool prints both):
Terminal window psql -U bideward_ro -d bideward -c "select split_part(k, ':', 1) as family, count(*) from hub.kv group by 1 order by 1;" -
The tool’s verify step recomputes a checksum of every value from the file and from the database and prints any key that differs. It must print zero differences.
-
Open the dashboard: the number of bots, loaders and releases equals your G.2 note; open three bot cards and compare their last values with the old dashboard if it still answers; open the Loaders & releases window.
-
Do not delete anything in Cloudflare. The old data stays where it is until Part L.
Honest limit: anything the bots sent after the export and before the cutover is not in the new database. With 1 to 3 bots that is minutes of statistics, and the bots keep their own state in the loader, so no bet or money record is lost.
← Previous: Part F. Install the hub, the research service and the tunnel on the server · Guide index · Next: Part H. The cutover: pointing the loaders at the new address →