{"id":995,"date":"2026-11-28T10:06:11","date_gmt":"2026-11-28T18:06:11","guid":{"rendered":"https:\/\/blog.canutethegreat.com\/?p=995"},"modified":"2026-11-28T10:06:13","modified_gmt":"2026-11-28T18:06:13","slug":"horcrux-backed-up-postgres-container-restored-tables-gone","status":"publish","type":"post","link":"https:\/\/blog.canutethegreat.com\/index.php\/2026\/11\/28\/horcrux-backed-up-postgres-container-restored-tables-gone\/","title":{"rendered":"Horcrux: I backed up a Postgres container, deleted it, restored it, and the tables were gone"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Full disclosure: I make Horcrux. It&#8217;s my Gentoo-based hypervisor, it&#8217;s pre-1.0, and this is my notebook for the week.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Everybody has a backup story that ends with &#8220;and then I found out it didn&#8217;t include the data&#8221;. I didn&#8217;t want that story to be about my own software, so last Saturday morning I tested exactly that. A Postgres container, a backup from the Backups page, everything deleted, a restore. The restore finished with a running database in it and no tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The daily server image from that morning (horcrux-bin 0.1.0_p202611210632), installed by answer file onto a ZFS root in a KVM guest on one of my lab laptops. 4 vCPUs, 6 GB of RAM, OpenRC. I logged into the web UI as the administrator account the installer makes and clicked everything below. The only things I did outside the browser are marked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The workload is a stack from the Stacks page: <code>postgres:16-alpine<\/code> with a named volume called pgdata, and a second container that inserts a row into a table every 5 seconds so there is something to lose. It was 26 rows when I broke things. I used the Docker runtime, not Podman, and the compose file went in as plain text.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/01-compose.jpg\" alt=\"Stacks page with a two service compose file: a postgres db with a named volume and a ticker service\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">The stack. The password in it is a throwaway for this VM.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The backup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Backups page, pick the container, mode snapshot, zstd, a note that says &#8220;db before I break it&#8221;, Back up now. It was done inside the 12 seconds I recorded and wrote a 102.8 MiB archive. Then Verify, which said &#8220;verified OK (2 file(s) checked)&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls preload=\"none\" poster=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/clip-backup-poster.jpg\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/clip-backup.mp4\"><\/video><figcaption class=\"wp-element-caption\">Backing up the database container. 13 seconds, real time.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/02-backup-verified.png\" alt=\"Backups page showing one archive marked OK after verification\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">Verified OK.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then I looked inside the archive, which is a thing I should have done before the video. It holds three files: a manifest, <code>inspect.json<\/code>, and <code>rootfs.tar<\/code>, about 297 MB uncompressed. That is the container&#8217;s file system as <code>docker export<\/code> writes it. In the tar, <code>\/var\/lib\/postgresql\/data\/<\/code> is an empty directory. On the live container that directory was 9.3 MB. Verify checks the checksums of what is in the archive, so it passed. The data was never in it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Breaking it<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I removed the stack from the Stacks page. The confirm text says it &#8220;stops and deletes every container in it&#8221;, and that&#8217;s accurate. The pgdata volume survived, which is Docker&#8217;s normal behaviour. Then I went to the Volumes page and removed the leftovers, the way you tidy up when you think a project is gone.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls preload=\"none\" poster=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/clip-break-poster.jpg\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/clip-break.mp4\"><\/video><figcaption class=\"wp-element-caption\">Removing the stack and then the volume. 16 seconds, real time.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/05-volumes-leftover.png\" alt=\"Volumes page listing pgdata and an anonymous volume, with the Actions column off screen to the right\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">The Volumes page at 1440 pixels wide. The Remove buttons are past the right edge, so I clicked them with a script. A person would scroll sideways.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Restoring<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Backups page, Restore on the archive, original id, start after restore. It failed:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/07-backup-restored.png\" alt=\"Red banner: Restore failed, HTTP 500, network notes_default not found\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">The first restore attempt.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The stack&#8217;s network, notes_default, went away with the stack, and the container&#8217;s config in the backup still points at it. What the failure left behind was a container in the Created state and a brand new empty pgdata volume. I made the network again on the Container Networks page, pressed Start on the Containers page, and it ran. The image is a new one, <code>horcrux-restore\/notes_db_9405c03c:94a20893<\/code>, imported from the tar.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls preload=\"none\" poster=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/clip-restore-poster.jpg\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/clip-restore.mp4\"><\/video><figcaption class=\"wp-element-caption\">The failed restore, the network, and starting the container. 39 seconds, real time.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/09-containers-restored-created.png\" alt=\"Containers page with the restored notes_db container, stopped, image horcrux-restore\/notes_db\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">Restored and stopped, before I pressed Start.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then I asked the database. The notes database exists, because the restored config still has <code>POSTGRES_DB=notes<\/code> and the Postgres image creates it on first start. It has no tables. The 26 rows are gone, and so is the table they were in. Nothing on any page warned me before or after.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/t2-terminal-after-restore.png\" alt=\"Terminal output: restored notes_db container up, database list including notes, no relations found, relation readings does not exist\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">From a root shell on the node (the one other thing I did outside the browser): the list of databases, then &#8220;Did not find any relations&#8221;.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Getting the data back by hand<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\/var\/lib\/docker is its own ZFS dataset on a Horcrux install, so a ZFS snapshot of it contains every Docker volume. I tried that on the restored database: made a table with 1000 rows, took <code>rpool\/var\/lib\/docker@hand-before-drop<\/code> (0 bytes used when it was taken), dropped the table, stopped the container, emptied the volume directory, copied pgdata back out of the snapshot&#8217;s <code>.zfs\/snapshot<\/code> directory, and started it. Postgres logged &#8220;redo done&#8221; and &#8220;ready to accept connections&#8221;, and <code>select count(*)<\/code> said 1000.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/t3-terminal-zfs-snapshot.png\" alt=\"Terminal session: zfs snapshot, drop table, copy from the snapshot directory, redo done, count 1000\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">The commands and the output, from the node.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This isn&#8217;t a Horcrux feature. The Snapshots page only knows about VMs. It also worked once, on an idle database of one table, and a snapshot taken under write load only gives you crash recovery. For a database you care about, run <code>pg_dump<\/code> on a schedule. The file system layout just makes the snapshot trick possible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What doesn&#8217;t work (yet)<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Container backups don&#8217;t include named volumes. This is the big one. I already had it in my QA notes from the Thursday before, with a fix on a branch that adds the volume data to the archive. I checked main again this morning, a week later, and that branch still isn&#8217;t merged, so a fresh daily image won&#8217;t have it either.<\/li><li>Restore only found out the network was gone at the start step. A failed restore leaves a half-made container and an empty volume behind. It should fail before it creates anything, or it should create the network.<\/li><li>The Volumes and Networks lists don&#8217;t refresh after you remove or create something with Docker selected. I watched the Networks list for 30 seconds after creating one and it never appeared. A reload showed it. Same on the Volumes page after removing pgdata: it was gone from disk and still on screen.<\/li><li>On the Volumes page at 1440 pixels the Actions column is off the right edge. On a 390 pixel phone the backup archive table is 887 pixels wide, so the Restore and Verify buttons sit behind a sideways scroll.<\/li><li>Times disagree. The Backups page shows 10:16:27 -08:00, the Containers page shows the creation time as 18:19:38 UTC, and the node&#8217;s own logs are in UTC.<\/li><li>Every container row carries the same warning that CRIU isn&#8217;t installed, so state can&#8217;t be saved. The warning is accurate. It is also on every row.<\/li><li>The UI listens on port 8006 and not 443, and the certificate is self-signed, so the browser stops you at a warning first. I told the browser to ignore it.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/13-mobile-backups-table.png\" alt=\"Phone-width Backups page with the archive table cut off after the Size column\" loading=\"lazy\"\/><figcaption class=\"wp-element-caption\">Backup archives on a 390 pixel wide screen. Time and Size fit, the buttons don&#8217;t.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Design decisions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The backup code calls itself a vzdump equivalent, and it follows Proxmox&#8217;s behaviour on purpose: a catalog of archives with SHA-256 checksums, Verify that re-reads them, retention per guest, restore into the same or a new id. Its header comment says a no-pause snapshot, a copy-before-write block job, isn&#8217;t implemented, so in snapshot mode a running container is frozen for the copy and then resumed. The restore form says the archive is verified first and that a corrupt one never touches the existing guest, and that part I believe, because the UI states it and the verify step exists.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Containers go in with <code>docker export<\/code>, which is a file system and nothing else. The code has a comment saying so next to the function that puts the image config back by hand. I haven&#8217;t found anything written down about why volumes were left out, and I&#8217;m not going to invent a reason. My QA notes file it as a bug, not as a decision.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ZFS is under all of this for the reason I gave in the last post: recovery and bit rot protection. The separate dataset for Docker&#8217;s data comes from the same layout that keeps the root file system rollbackable on its own. That layout is why the snapshot trick above works at all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where it stands<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Backups work for containers that store their state inside the container. They don&#8217;t work for containers that use a volume, and that includes the usual way to run Postgres. The fix exists and isn&#8217;t merged yet. Until it is, I wouldn&#8217;t trust a container backup from this build to hold a database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next: get that branch merged, then run this same test again on the build that has it, with a database big enough to take more than a second to copy. I haven&#8217;t re-run any of this on a newer image than the one from last Saturday, so the other items above are as of that build.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Horcrux lives at <a href=\"https:\/\/horcrux.errant.solutions\/\">horcrux.errant.solutions<\/a>.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Full disclosure: I make Horcrux. It&#8217;s my Gentoo-based hypervisor, it&#8217;s pre-1.0, and this is my notebook for the week. Everybody has a backup story that ends with &#8220;and then I found out it didn&#8217;t include the data&#8221;. I didn&#8217;t want that story to be about my own software, so last Saturday morning I tested exactly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1010,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,26],"tags":[98,81,358,432,167,101],"class_list":["post-995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-software-engineering","tag-backups","tag-docker","tag-horcrux","tag-self-hosted","tag-virtualization","tag-zfs"],"_links":{"self":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/comments?post=995"}],"version-history":[{"count":1,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/995\/revisions"}],"predecessor-version":[{"id":1011,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/995\/revisions\/1011"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/media\/1010"}],"wp:attachment":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/media?parent=995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/categories?post=995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/tags?post=995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}