# Backup / download all files from a PWA client

**URL:** <https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516>\
**Category:** Troubleshooting\
**Created:** [November 5, 2026, 9:49am UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516 "2026-11-05T09:49:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivangretsky](https://community.silverbullet.md/user_avatar/community.silverbullet.md/ivangretsky/32/3321_2.png) [@ivangretsky](https://community.silverbullet.md/u/ivangretsky)\
**Post date:** [November 5, 2026, 9:49am UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/1 "2026-11-05T09:49:33Z")

</div>

Hello everyone!

My hosting provider was hacked and all the VPS's were deleted. The one I had SilverBullet in a docker in was one of them. But I still got my data in a PWA and a mobile clients. I ask someone in the know to teach me how to backup the space from such a client. So I can move all the files to a new installation.

The ideal thing would be something like _Download all files_ command. But I couldn't find one 😓

---

<div class="post-metadata">

**Author:** ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)\
**Post date:** [November 5, 2026, 9:53am UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/2 "2026-11-05T09:53:38Z")

</div>

@Mr.Red created this: [silverbullet-libraries/ExportSpaceAsZIP.md at main · Mr-xRed/silverbullet-libraries · GitHub](https://github.com/Mr-xRed/silverbullet-libraries/blob/main/ExportSpaceAsZIP.md) but I'm not sure you would actually be able to install that successfully in your condition?

---

<div class="post-metadata">

**Author:** ![LostInLua](https://community.silverbullet.md/letter_avatar_proxy/v4/letter/l/91b2a8/32.png) [@LostInLua](https://community.silverbullet.md/u/LostInLua)\
**Post date:** [November 5, 2026, 10:21am UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/3 "2026-11-05T10:21:57Z")

</div>

I got llm to churn out something like this but I did not check throughly if all files are exported

````auto
```space-lua
-- ==============================================================
-- 100% Offline Space Exporter (.ZIP with Exact Folder Structure)
-- ==============================================================
command.define {
  name = "Space: Export to Zip",
  run = function()
    editor.flashNotification("Collecting local notes from phone...", "info")
    
    local allPages = space.listPages()
    local files = {}

    -- 1. Read all files currently cached in IndexedDB
    for _, p in ipairs(allPages) do
      local text = space.readPage(p.name)
      table.insert(files, {
        name = p.name .. ".md",
        content = text
      })
    end

    editor.flashNotification("Packaging " .. #files .. " files into .zip...", "info")

    -- 2. Pure client-side ZIP generator (runs in phone browser memory)
    local zipExporter = js.window.Function([[
      const files = arguments[0];
      
      // Standard CRC32 table
      const crcTable = [];
      for (let n = 0; n < 256; n++) {
        let c = n;
        for (let k = 0; k < 8; k++) c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
        crcTable[n] = c;
      }
      function crc32(buf) {
        let crc = -1;
        for (let i = 0; i < buf.length; i++) crc = (crc >>> 8) ^ crcTable[(crc ^ buf[i]) & 0xFF];
        return (crc ^ -1) >>> 0;
      }

      const enc = new TextEncoder();
      const entries = [];
      let offset = 0;

      for (const f of files) {
        const nameBytes = enc.encode(f.name);
        const dataBytes = enc.encode(f.content);
        const crc = crc32(dataBytes);
        const size = dataBytes.length;

        // Local header (PK\x03\x04)
        const h = new Uint8Array(30 + nameBytes.length);
        const v = new DataView(h.buffer);
        v.setUint32(0, 0x04034b50, true);
        v.setUint16(4, 20, true);
        v.setUint16(6, 0x0800, true); // UTF-8 filename flag
        v.setUint16(8, 0, true); // Store (no compression)
        v.setUint32(14, crc, true);
        v.setUint32(18, size, true);
        v.setUint32(22, size, true);
        v.setUint16(26, nameBytes.length, true);
        h.set(nameBytes, 30);

        entries.push({ nameBytes, crc, size, offset, header: h, data: dataBytes });
        offset += h.length + size;
      }

      // Central directory headers (PK\x01\x02)
      let cdSize = 0;
      const cdHeaders = [];
      for (const e of entries) {
        const ch = new Uint8Array(46 + e.nameBytes.length);
        const v = new DataView(ch.buffer);
        v.setUint32(0, 0x02014b50, true);
        v.setUint16(4, 20, true);
        v.setUint16(6, 20, true);
        v.setUint16(8, 0x0800, true);
        v.setUint16(10, 0, true);
        v.setUint32(16, e.crc, true);
        v.setUint32(20, e.size, true);
        v.setUint32(24, e.size, true);
        v.setUint16(28, e.nameBytes.length, true);
        v.setUint32(42, e.offset, true);
        ch.set(e.nameBytes, 46);
        cdHeaders.push(ch);
        cdSize += ch.length;
      }

      // End of central directory record (PK\x05\x06)
      const eocd = new Uint8Array(22);
      const ev = new DataView(eocd.buffer);
      ev.setUint32(0, 0x06054b50, true);
      ev.setUint16(8, entries.length, true);
      ev.setUint16(10, entries.length, true);
      ev.setUint32(12, cdSize, true);
      ev.setUint32(16, offset, true);

      // Assemble blob
      const parts = [];
      for (const e of entries) { parts.push(e.header); parts.push(e.data); }
      for (const ch of cdHeaders) parts.push(ch);
      parts.push(eocd);

      const blob = new Blob(parts, { type: "application/zip" });
      const url = URL.createObjectURL(blob);
      const a = document.createElement("a");
      a.href = url;
      a.download = "SilverBullet-Backup-" + new Date().toISOString().slice(0, 10) + ".zip";
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
      setTimeout(() => URL.revokeObjectURL(url), 10000);
    ]])

    zipExporter(files)
    editor.flashNotification("Download started! Check your phone files.", "info")
  end
}
```

````

---

<div class="post-metadata">

**Author:** ![dtomvan](https://community.silverbullet.md/user_avatar/community.silverbullet.md/dtomvan/32/4013_2.png) [@dtomvan](https://community.silverbullet.md/u/dtomvan)\
**Post date:** [November 5, 2026, 11:31am UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/4 "2026-11-05T11:31:22Z")

</div>

I know that doesn't help right now, but I advise you to always backup your space's history to GitHub/Gitlab/Codeberg with the builtin git integration.

---

<div class="post-metadata">

**Author:** ![ivangretsky](https://community.silverbullet.md/user_avatar/community.silverbullet.md/ivangretsky/32/3321_2.png) [@ivangretsky](https://community.silverbullet.md/u/ivangretsky)\
**Post date:** [November 5, 2026, 12:47pm UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/5 "2026-11-05T12:47:51Z")

</div>

Thanks for the help and your tokens! This worked! And it even solved the windows filename bug replacing quotes with underscores.

It did not download images. Not sure they were uploaded to the client in the first place.

---

<div class="post-metadata">

**Author:** ![ivangretsky](https://community.silverbullet.md/user_avatar/community.silverbullet.md/ivangretsky/32/3321_2.png) [@ivangretsky](https://community.silverbullet.md/u/ivangretsky)\
**Post date:** [November 5, 2026, 12:48pm UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/6 "2026-11-05T12:48:52Z")

</div>

Thanks for this tip. I was kind of scared to install something not to lose my last chance so didn't try it (yet).

---

<div class="post-metadata">

**Author:** ![dtomvan](https://community.silverbullet.md/user_avatar/community.silverbullet.md/dtomvan/32/4013_2.png) [@dtomvan](https://community.silverbullet.md/u/dtomvan)\
**Post date:** [November 5, 2026, 11:45pm UTC](https://community.silverbullet.md/t/backup-download-all-files-from-a-pwa-client/4516/7 "2026-11-05T23:45:11Z")

</div>

This is actually pretty neat! You can expand it by changing `listPages` to `listFiles`, so it will attempt to download everything:

````auto
```space-lua
-- ==============================================================
-- 100% Offline Space Exporter (.ZIP with Exact Folder Structure)
-- ==============================================================
command.define {
  name = "Space: Export to Zip",
  run = function()
    editor.flashNotification("Collecting local notes from phone...", "info")
    
    local allFiles = space.listFiles()
    local files = {}

    -- 1. Read all files currently cached in IndexedDB
    for f in each(allFiles) do
      if not string.startsWith(f.name, "Library/Std") then
        table.insert(files, {
          name = f.name,
          content = space.readFile(f.name),
        })
      end
    end

    editor.flashNotification("Packaging " .. #files .. " files into .zip...", "info")

    -- 2. Pure client-side ZIP generator (runs in phone browser memory)
    local zipExporter = js.window.Function([[
      const files = arguments[0];
      
      // Standard CRC32 table
      const crcTable = [];
      for (let n = 0; n < 256; n++) {
        let c = n;
        for (let k = 0; k < 8; k++) c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
        crcTable[n] = c;
      }
      function crc32(buf) {
        let crc = -1;
        for (let i = 0; i < buf.length; i++) crc = (crc >>> 8) ^ crcTable[(crc ^ buf[i]) & 0xFF];
        return (crc ^ -1) >>> 0;
      }

      const enc = new TextEncoder();
      const entries = [];
      let offset = 0;

      for (const f of files) {
        const nameBytes = enc.encode(f.name);
        const dataBytes = f.content;
        const crc = crc32(dataBytes);
        const size = dataBytes.length;

        // Local header (PK\x03\x04)
        const h = new Uint8Array(30 + nameBytes.length);
        const v = new DataView(h.buffer);
        v.setUint32(0, 0x04034b50, true);
        v.setUint16(4, 20, true);
        v.setUint16(6, 0x0800, true); // UTF-8 filename flag
        v.setUint16(8, 0, true); // Store (no compression)
        v.setUint32(14, crc, true);
        v.setUint32(18, size, true);
        v.setUint32(22, size, true);
        v.setUint16(26, nameBytes.length, true);
        h.set(nameBytes, 30);

        entries.push({ nameBytes, crc, size, offset, header: h, data: dataBytes });
        offset += h.length + size;
      }

      // Central directory headers (PK\x01\x02)
      let cdSize = 0;
      const cdHeaders = [];
      for (const e of entries) {
        const ch = new Uint8Array(46 + e.nameBytes.length);
        const v = new DataView(ch.buffer);
        v.setUint32(0, 0x02014b50, true);
        v.setUint16(4, 20, true);
        v.setUint16(6, 20, true);
        v.setUint16(8, 0x0800, true);
        v.setUint16(10, 0, true);
        v.setUint32(16, e.crc, true);
        v.setUint32(20, e.size, true);
        v.setUint32(24, e.size, true);
        v.setUint16(28, e.nameBytes.length, true);
        v.setUint32(42, e.offset, true);
        ch.set(e.nameBytes, 46);
        cdHeaders.push(ch);
        cdSize += ch.length;
      }

      // End of central directory record (PK\x05\x06)
      const eocd = new Uint8Array(22);
      const ev = new DataView(eocd.buffer);
      ev.setUint32(0, 0x06054b50, true);
      ev.setUint16(8, entries.length, true);
      ev.setUint16(10, entries.length, true);
      ev.setUint32(12, cdSize, true);
      ev.setUint32(16, offset, true);

      // Assemble blob
      const parts = [];
      for (const e of entries) { parts.push(e.header); parts.push(e.data); }
      for (const ch of cdHeaders) parts.push(ch);
      parts.push(eocd);

      const blob = new Blob(parts, { type: "application/zip" });
      const url = URL.createObjectURL(blob);
      const a = document.createElement("a");
      a.href = url;
      a.download = "SilverBullet-Backup-" + new Date().toISOString().slice(0, 10) + ".zip";
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
      setTimeout(() => URL.revokeObjectURL(url), 10000);
    ]])

    zipExporter(files)
    editor.flashNotification("Download started! Check your phone files.", "info")
  end
}
```

````

Files which aren't cached will then be read as zero-size files, but the added side benefit to this is that the full list of filenames will be preserved.
