Docs / Reference

server-move.sh

Moves an Otto server from your Mac in one command, or checks a new machine, exports the server, imports the export on the new machine, and checks the result. Used by Move your Otto server to a new machine.

Synopsis

server-move.sh
server-move.sh move <new-ip> [--from <ssh-alias>] [--server-name <name>] [--yes] [--dry-run] [--restart] [--no-dns-wait] [--grace <min>] [--hard <min>] [--full] [--password-file <path>]
server-move.sh export [--drain [--grace <min>] [--hard <min>]] [--dry-run] [--force] [--full] [--out <dir>]
server-move.sh preflight [--need-bytes <n>] [--names "<name> …"]
server-move.sh import [--dry-run] [--force]
server-move.sh verify [--no-dns]
server-move.sh undo-export [--force]
server-move.sh names
server-move.sh stop-web | moved-to <new-ip>
server-move.sh undrain

move runs on your Mac, from an Otto checkout (bash deploy/session-host/server-move.sh move …); the Mac's bash 3.2 is fine, and nothing needs installing. With no arguments, or move without an address, it runs as the wizard. Every other command runs as root, on the server itself; preflight needs no Otto there, only the script. The script is at /opt/otto/deploy/session-host/server-move.sh on a server, and a copy of it is in every export folder.

Commands

move

On your Mac. Runs the other commands on both servers over SSH, from preflight to undrain. <new-ip> is the new server's IPv4 or IPv6 address.

It needs:

The server name is a DNS name for the server itself, such as vps.example.com, that the Macs' aliases use as HostName. Then every Mac follows the move through DNS.

It prints the plan as a checklist: each step, numbered, with a line on how long it takes, ✔ when done, ▸ where this run starts. On a first run, it reads the TTLs of the old server's names (from names) and of the server name from a public resolver (1.1.1.1), and warns about each above 600 s: lower them to 300 s a day before the move. The dry run does this too. Unless --yes, it then asks before it changes anything. As each step starts it prints ▸ n/11 and what it does; as it ends, ✔ n/11 and how long it took. Where it needs you, it says ▲ Your turn: and what to do. In order, each step once:

  1. access: checks that root@<new-ip> takes the Mac's key. When it does not, it takes root's password once, from OTTO_MOVE_PASSWORD, else the first line of --password-file, else a hidden prompt, and adds the Mac's public key (the first of ~/.ssh/id_ed25519.pub, id_ecdsa.pub, id_rsa.pub, or OTTO_MOVE_PUBKEY) to /root/.ssh/authorized_keys there, once. A wrong password, or a server that refuses root password logins, stops the move here, before anything changes. This step runs on every run, a resumed one too. Every later SSH to the new server uses the key only, so it never asks for a password mid-step.
  2. preflight: copies the script to /root/server-move-preflight.sh on the new server and runs preflight there, with --need-bytes set to the size export --dry-run gives on the old server, and --names set to the old server's names and the server name. That dry run keeps the sizes it measured, so the export does not measure them again. A FAIL stops the move here, before anything changes.
  3. export: on the old server, export --drain, with --grace, --hard and --full passed on. An export that was already made is kept. The export fences the old server.
  4. copy: copies the export folder to /root/otto-move on the new server, server to server with rsync when the servers reach each other, else streamed through the Mac. Either way it goes into a folder that is renamed once whole, then checked against SHA256SUMS.
  5. import: import on the new server, as root. Then, in the Mac's ~/.ssh/known_hosts, it replaces the entry for <new-ip> with the key the new server now shows, but only when this Mac already trusted that key for the old server. Otherwise it warns and leaves the file alone.
  6. ssh-config: sets the alias's HostName in ~/.ssh/config to the server name, or else to <new-ip>. Does nothing when the alias already uses it. It first makes a backup, config.bak-<UTC time>, and prints the diff. Refuses when there is no HostName line under Host <alias>: set it by hand, then run the move again. A host in Otto's Settings → Session hosts set up by the alias follows it; one set up by address must be changed there.
  7. dns: prints the domain names the old server served (DOMAINS in the manifest) and the server name, marked as the server's own name: point each at <new-ip> with an A record, and remove the old server's AAAA records. Then asks 1.1.1.1 every 30 seconds until every name gives <new-ip>. A wildcard is checked by a name under it. Ctrl-C here is safe: run the move again to carry on.
  8. verify: verify on the new server, through the alias but by <new-ip>. Then, from the Mac: warns when the server name does not resolve to <new-ip> yet at 1.1.1.1. When this Mac's own resolver (dscacheutil) still gives the old address, so ssh <alias> would land on the fenced old server, it offers to flush the Mac's DNS cache (sudo asks for the Mac's password once); declined, it prints the commands. Last, it warns when the old server answers and is not fenced.
  9. old-web: stop-web on the old server, so a client that still has its address gets no answer rather than an old copy of the site. A server that no longer answers is fine.
  10. undrain: the point of no return. When the old server was drained, it explains and asks Resume your sessions on <new-ip> now? [y/N]; no ends the move there, changing nothing, with what to run to resume or to go back. Yes runs moved-to <new-ip> on the old server, then undrain on the new one, which reports how many sessions resumed.
  11. cleanup: the export is on both servers, with the keys in it. It asks Delete both copies now? [y/N]: yes deletes /root/otto-move on the new server and ~otto/otto-move on the old one; no (the default, and what --yes answers) keeps them and prints the commands that delete them.

It ends with Moved. The old server keeps everything, stopped and fenced. It also prints the command that registers the CI runner again.

Each step that succeeds leaves a marker in ~/.otto/server-move/<alias>/. Running the move again with the same address skips those steps and carries on from the one that failed. It keeps using the old address and server name it first found, even once the alias or the name points at the new server. A move with another address refuses while one is under way; --restart starts over.

The wizard

server-move.sh with no arguments, or move without an address, is the same move with its questions asked instead of given as flags. It needs a terminal; without one it exits 2. Each question shows its default in brackets, and Enter takes it:

  1. When a move is under way (a plan.env on this Mac, not yet finished): Carry on where it stopped? [Y/n]. Yes opens it at the step it stopped at. No asks whether to start that move over.
  2. The ssh alias your Mac reaches the old server with [otto-vps], asked again until ~/.ssh/config has it.
  3. The new server's IP address, asked again until it is one.
  4. When the alias has an address: Give the server a DNS name? [Y/n], then The server's name [vps.<domain>].
  5. Then the move's own questions: going ahead, root's password (only when the new server does not take the Mac's key), the Mac's DNS cache, the point of no return, and the export's copies.

Every flag of move works with the wizard too. Colours are used only on a terminal, never with NO_COLOR set or TERM=dumb.

The direct copy

The copy step first copies server to server:

  1. It reads the old server's ed25519 host key through the Mac's alias, which the Mac trusts.
  2. On the new server, it installs rsync when missing, makes a key, /root/.ssh/otto-move-copy, and a known-hosts file holding only that host key.
  3. On the old server, it adds the key to ~otto/.ssh/authorized_keys as restrict,from="<new-ip>": from the new server's address only, with no shell, forwarding or terminal.
  4. The new server runs rsync -rtp --partial from otto@<old address> (the alias's port) into /root/otto-move.part, checking the old server's host key strictly, then checks SHA256SUMS and renames the folder to /root/otto-move.
  5. It removes the key from both servers, whatever happened.

When the servers cannot reach each other (a firewall, no rsync on the old server, the key refused), it says so and streams the export through the Mac instead. When rsync stops part-way, the move stops: run it again, and rsync carries on from what /root/otto-move.part holds.

preflight

On the new server, as root, before move day. Needs no export folder and changes nothing. It prints one line per check, PASS, WARN or FAIL, and exits 1 when any check fails.

CheckPASSWARNFAIL
OSUbuntu 24.04, Debian 12, Debian 13another Ubuntu or Debiananything else
userrootnot root
memory7 GB or more3 GB or moreless
free disk, with --need-bytes3 × size + 15 GB2 × size + 10 GBless
free disk, without60 GB30 GBless
ports 80 and 443freesomething listens
HTTPS to github.com, download.docker.com and the distribution's apt mirroreach reachedone not reached
clockNTP-synchronizednot synchronized
each name in --namesresolvesdoes not resolve
no Otto here yetnone of the belowan Otto volume holds data, an Otto container exists, or /opt/otto is a directory that is not an Otto checkout
earlier import/var/lib/otto-move holds an import's progress

Without move, copy the script there first: scp deploy/session-host/server-move.sh root@<new-ip>:, then bash server-move.sh preflight.

names

Prints the domain names the server serves, one per line: the imported manifest's DOMAINS on a server that was imported, else the names its web/Caddyfile serves. move uses it for the TTL warning and for preflight.

export

On the old server. In order:

  1. Lists what it copies, with sizes, the free disk at the output folder, and the domain names the server serves, read from its own web/Caddyfile. Unless --full, it also lists what it leaves out, by category, and the size with --full. Refuses when the copy does not fit. A dry run keeps the sizes it measured in /var/lib/otto-move/sizes.tsv; an export within 6 hours of it uses them instead of measuring every directory again, which can take minutes on a large server.
  2. With --drain, drains the server (otto-host drain --by "server-move export" --wait) and waits until it is drained or stuck: every session is paused, with its conversation kept, and nothing starts or resumes until it is undrained. Before it drains, it checks the free disk and the export folder, so nothing that would refuse the export anyway stops the sessions first. A drain that is stuck (a session still in a step that must not be cut past the hard timeout) ends the export here (exit 3) with nothing stopped and the host still drained: run export --drain again once that step is done, or undo-export to lift the drain.
  3. Refuses (exit 3) while a session is mid-turn, or when the daemon does not answer.
  4. Takes the deploy lock and pauses autodeploy (/srv/otto-deploy/paused, unless it is paused already).
  5. Stops, when running: otto-runner, otto-host-ops, otto-host-exec, otto-gateway, otto-vault-api, otto-auth, ottobot-api, vault-sync, then otto-host. Caddy (otto-mobile-web) keeps running and keeps serving the static site.
  6. Writes the export folder, the server's SSH host keys included.
  7. Fences the server.

Nothing is deleted. Otto stays stopped on the old server afterwards, a reboot included; undo-export starts it again. If export fails or is interrupted after step 4, it runs undo-export itself.

The fence keeps Otto off the old server once it is exported, so nothing runs on two servers at once:

Only undo-export lifts it: it puts the recorded restart policies back, enables the timer again and removes the file.

The drain lives in the otto-state volume (/otto/drain.json), so it moves with the export: on the new server the hold is still on, and import ends by printing the command that lifts it — run otto-host undrain --resume there once the Macs point at the new server. On the old server, undo-export (or a failed export undoing itself) lifts a drain that export --drain started, with --resume, once otto-host is back up.

import

On the new server, run from inside the copied export folder (bash otto-move/server-move.sh import). In order:

  1. Checks every file against SHA256SUMS. Refuses a damaged or incomplete export before changing anything.
  2. When Docker, Compose, Buildx, git, rsync or curl is missing, installs them with apt-get: git, rsync, python3, curl, and Docker from the distribution where it carries Compose v2 and Buildx (Ubuntu 24.04: docker.io docker-compose-v2 docker-buildx; Debian 13: docker.io docker-compose docker-buildx), else from Docker's own apt repository, added with its signing key (docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin) — Debian 12, whose docker-compose is Compose v1 and which has no Buildx, and any other OS whose apt knows no Compose v2 and Buildx.
  3. Creates the user otto (when missing), in the docker group, with passwordless sudo.
  4. Restores ~otto/.ssh. Keys already in authorized_keys are kept.
  5. When the export has ssh-hostkeys.tar.gz, gives the server the old server's SSH host keys. It first copies this server's own keys to /etc/ssh/host-keys-before-move. It installs the old ones owned by root, private keys mode 600, public keys 644, checks the configuration with sshd -t, and reloads sshd. It does not restart it, so the session running the import stays. A fresh ssh-keyscan of 127.0.0.1 must then show the old key. If any of this fails, it puts this server's own keys back and warns: each Mac then sees a changed host key once.
  6. Creates /opt/otto and the /srv directories a deploy writes, restores the /srv files with their owners and modes.
  7. Creates each volume and restores it, then checks its entry count against its archive.
  8. For a slim export, marks each work tree listed in slim-installs.tsv to get its dependencies back: see Dependencies after a slim export.
  9. Clones the repository into /opt/otto with the restored deploy key.
  10. Adds swap with swap.sh, before the deploy's image builds: /swapfile at half the RAM, 2 to 8 GB, unless swap is on already, and swappiness 10 (see Add swap to your Otto server). If it fails, import warns and carries on.
  11. Runs vps-deploy.sh all, then vps-deploy.sh autodeploy if the old server had the autodeploy timer.
  12. Runs verify --no-dns, also requiring as many sessions as the old server had (none after export --drain), and lists the domain names to point at the server: the old server's, from the manifest. It warns when the configuration deployed on the new server serves other names.

Each step that succeeds is recorded in /var/lib/otto-move/<export id>/. Running import again skips those steps and carries on from the one that failed.

Import refuses to restore into a volume that holds data, or over a /srv or ~otto/.ssh file that exists, unless --force.

verify

On the new server. Checks:

Prints verified when every check passes.

undo-export

On the old server. Lifts the fence, starts the services export (and stop-web) stopped and lifts the pause export set. Refuses on a server that was not exported.

After the point of no return, when moved-to has recorded that the sessions resumed on the new server, it refuses: the old server would come back as it was at the export, without anything the sessions did on the new server since. --force does it anyway, and warns.

stop-web

On the old server, after an export; move runs it once DNS points at the new server and verify passed. Stops Caddy (otto-mobile-web), adds it to what export stopped and to the fence, so it stays off after a reboot and undo-export starts it again. Refuses on a server that was not exported.

moved-to <new-ip>

On the old server, after an export; move runs it just before the sessions resume on the new server. Writes /var/lib/otto-move/moved-to, so undo-export refuses without --force.

undrain

On the new server, after import. Lifts the drain that came with the state volume and resumes what it paused (otto-host undrain --resume), then waits for the sessions to resume, checking otto-host drain status every 15 seconds: 25 seconds per session, at least 3 and at most 10 minutes. It prints N of M session(s) resumed and names any that have not. Those keep resuming by themselves as the host has room. Each resumed session is told it was paused for maintenance, and that background jobs it started (a background shell, a dev server, a Monitor) ended with the pause and must be rerun.

Options

OptionCommandsEffect
--from <ssh-alias>moveThe ~/.ssh/config alias of the old server. Default otto-vps.
--server-name <name>moveThe server name, when the alias's HostName is an IP address: the alias is set to it instead of <new-ip>, the dns step lists it, and verify checks it resolves to <new-ip>.
--yesmoveAnswers yes to going ahead, flushing the Mac's DNS cache and the point of no return, and does not ask for a server name. The export's copies are kept: --yes never deletes them.
--restartmoveRemoves the move's markers and starts over. An export already made on the old server is still kept.
--password-file <path>moveFor the access step: root's password on the new server, the file's first line. OTTO_MOVE_PASSWORD takes precedence. There is no option that takes the password itself, which would end up in the shell's history.
--no-dns-waitmovePrints the DNS names but does not wait for them.
--dry-runmovePrints the plan (each step, done or to do), the old and new addresses, the export flags and the progress folder, and whether the new server takes the Mac's key, and changes nothing.
--dry-runexport, importShows what would happen and changes nothing. Export lists sizes, what a slim export leaves out by category, free disk and running sessions. Import checks the checksums and warns about volumes that hold data.
--drainexportDrains the server first and waits until it is drained or stuck, then exports. See otto-host drain. With --dry-run, nothing is drained.
--grace <min>export, moveWith --drain: the drain's grace period, in minutes. Default 5.
--hard <min>export, moveWith --drain: the drain's hard timeout, in minutes. Default 30.
--fullexport, moveCopies every volume whole: nothing is left out and no slim-installs.tsv is written.
--forceexportExports while a session is mid-turn (its turn is cut off) or when the daemon does not answer; exports a server that was exported already.
--forceundo-exportUndoes the export after the point of no return, losing what was done on the new server since.
--forceimportRestores over existing data: empties a volume that holds data before restoring it, overwrites existing files.
--out <dir>exportWrites the export to <dir> instead of ~otto/otto-move. It must be empty or not exist.
--no-dnsverifySkips the DNS check.
--need-bytes <n>preflightThe export's size in bytes (EXPORT_BYTES in export --dry-run), for the disk check.
--names "<name> …"preflightNames that should resolve, space-separated. A wildcard is checked by a name under it.

From the environment: OTTO_MOVE_PASSWORD (root's password for the access step), OTTO_MOVE_PUBKEY (the public key it adds), NO_COLOR (no colours).

Exit status

CodeMeaning
0Done; for verify, every check passed.
1Refused or failed. The message says why and what to do. For preflight, a check failed.
2Wrong usage; the wizard without a terminal.
3export: a session is mid-turn, or the daemon cannot say.
4verify: a check failed.
5verify: the server is fine, but DNS does not reach it yet for the names listed.

The export folder

Default ~otto/otto-move, owned by otto, mode 700. It holds secrets: keep it private, and delete it once the new server is in use.

FileContents
volume-session-host_otto-state.tar.gzThe daemon's state and its session journal. A slim export leaves out the regenerable directories of the clones in it, such as a swarm's workers'.
volume-session-host_otto-home.tar.gzThe sessions' home: the Claude login, transcripts, settings. A slim export leaves out its package-manager and browser caches.
volume-session-host_otto-repos.tar.gz/repos: every clone and worktree, uncommitted work included. A slim export leaves out their regenerable directories.
volume-session-host_otto-vault-pending.tar.gzVault edits from the phone that no Mac has committed yet. Absent when the volume does not exist.
volume-caddy_data.tar.gzCaddy's TLS certificates and ACME account.
srv.tar.gzWhichever exist of /srv/otto-auth, /srv/otto-vault, /srv/otto-host/push-allow, /srv/otto-host/autonomy, /srv/ottobot-api/data, /srv/otto-mobile/caddy.env, /srv/otto-deploy/notify-url.
ssh.tar.gzWhichever exist of ~otto/.ssh/ otto_repo_deploy, otto_repo_deploy.pub, config, known_hosts, authorized_keys.
ssh-hostkeys.tar.gzThe server's SSH host keys, /etc/ssh/ssh_host_*, so the new server keeps its identity.
manifest.envMOVE_ID, SOURCE_HOST, COMMIT, ORIGIN, AUTODEPLOY, LIVE_SESSIONS, EXPORTED_VOLUMES, SLIM (1, or 0 with --full), DOMAINS (the names the old server's web/Caddyfile serves).
slim-installs.tsvSlim export only, when it left something out of a work tree. One line per such work tree, tab-separated: its directory as the containers see it (/repos/…), its installer (yarn, pnpm, npm, npm-nolock, bun, or - when no dependencies were left out), the bytes left out, then each path left out, relative to the work tree.
server-move.shThe script, for import.
SHA256SUMSThe SHA-256 checksum of every other file.

What a slim export leaves out

Unless --full, the export leaves out what an install or a build makes again. In each git work tree of the otto-repos and otto-state volumes (a directory with a .git, outside node_modules), it leaves out an entry only when all of these hold:

CategoryDirectoriesFiles
dependenciesnode_modules, .pnpm-store, .yarn/cache, .yarn/unplugged.yarn/install-state.gz
build outputdist, build, out, target, .next, .nuxt, .svelte-kit, .output, storybook-static, coverage, .nyc_output, playwright-report, test-results*.tsbuildinfo
tool caches.turbo, .vite, .vite-cache, .cache, .parcel-cache, .angular, __pycache__, .pytest_cache, .mypy_cache, .ruff_cache, .gradle.eslintcache

From the otto-home volume it leaves out the package-manager and browser caches, whichever exist: .cache/ms-playwright, .cache/puppeteer, .cache/otto-chromium, .cache/chromium-headless, .config/chromium-headless, .cache/node-gyp, .cache/electron, .cache/electron-builder, .cache/node/corepack, .cache/yarn, .cache/pnpm, .cache/pip, .yarn/berry/cache, .npm/_cacache, .npm/_npx, .electron-gyp, .local/share/pnpm/store.

Everything else is copied: every tracked file, uncommitted change and untracked file, ignored files of any other name (such as .env), and every git directory whole, with its branches, unpushed commits, stashes and worktrees. A work tree whose git directory cannot be found or read is copied whole, and the dry run names it.

Dependencies after a slim export

For each line of slim-installs.tsv, import writes the marker Otto also writes when it frees a paused session's worktree: ~otto/.cache/otto/freed/<sha>.json on the home volume, where <sha> is the first 32 hex digits of the SHA-256 of the work tree's directory. A marker that is there already is kept, unless it reinstalls nothing and the new one does.

The next time a session starts in that directory, including its resume after the move, it runs the work tree's installer on its terminal before Claude starts: yarn install, pnpm install, npm ci, npm install --no-package-lock or bun install. The marker is removed once the install succeeds. If it fails, Claude starts anyway, and the next start tries again. Build output and caches are not rebuilt; the next build makes them.

Files on the servers

PathServerWhat
/var/lib/otto-move/stoppedoldWhat export stopped and paused; read and removed by undo-export.
/var/lib/otto-move/exportedoldWhen the export finished; removed by undo-export.
/var/lib/otto-move/fencedoldThe fence: each container's old restart policy, and whether the autodeploy timer was on. vps-deploy.sh refuses while it exists. Read and removed by undo-export.
/var/lib/otto-move/sizes.tsvoldThe sizes the last export --dry-run measured, path and bytes; the export reuses them for 6 hours.
/var/lib/otto-move/moved-tooldThe new address and when the sessions resumed there (moved-to). While it exists, undo-export refuses without --force.
~otto/.ssh/authorized_keysoldDuring the direct copy only: one line ending otto-move-copy, removed afterwards.
/root/.ssh/otto-move-copy, .pub, .knownnewDuring the direct copy only: its key and the old server's host key, removed afterwards.
/root/otto-move.part/newA copy not yet whole; a direct copy carries on from it.
/etc/ssh/host-keys-before-move/newThe new server's own SSH host keys, from before import gave it the old server's.
/root/server-move-preflight.shnewThe script, as move copied it for its preflight step.
/var/lib/otto-move/<export id>/newOne marker per finished import step.
/var/lib/otto-move/manifest.envnewThe imported export's manifest.
/root/otto-move/newThe export, as move copied it. Holds secrets: delete it once the new server is in use.

Files on the Mac

Written by move.

PathWhat
~/.otto/server-move/<alias>/plan.envThe move under way: the alias's old HostName (PLAN_OLD), the old server's address (PLAN_ADDR), the new address (PLAN_NEW) and the server name (PLAN_NAME).
~/.otto/server-move/<alias>/<step>One marker per finished step, holding when it finished: preflight, export, copy, import, ssh-config, dns, verify, old-web, undrain, cleanup; and done once the move has finished, so the wizard no longer offers to carry it on.
~/.ssh/known_hostsThe entry for <new-ip> is replaced by the old server's key, when this Mac already trusted that key.
~/.ssh/config.bak-<UTC time>The SSH config as it was before the move changed the alias's HostName.