Sanity dataset export hangs on "Adding assets to archive" step

34 replies
Last updated: Apr 6, 2021
Hi chaps, is it normal that
npx sanity dataset export <mydatasetname> --raw - >file.tar.gz
should run forever, hanging (bizarrely) on the
Adding assets to archive...
step?
AI Update

I understand the frustration! The "Adding assets to archive..." step taking a very long time or appearing to hang is something that can happen with dataset exports, though it's not always clear whether it's actually hanging or just processing slowly.

From the official dataset export documentation, the standard usage is to specify the output file directly:

# Recommended approach
npx sanity dataset export <mydatasetname> file.tar.gz

The syntax you're using (--raw - > file.tar.gz) with piping to stdout isn't documented as the standard way to export datasets. The typical export workflow documented by Sanity involves specifying the output file directly rather than piping output.

Here's what I'd recommend trying:

  1. Use the standard export syntax (most reliable):

    npx sanity dataset export <mydatasetname> file.tar.gz

    This is the documented approach and should work more predictably.

  2. If you only need document data without assets:

    npx sanity dataset export <mydatasetname> file.ndjson --no-assets

    This skips asset processing entirely and exports just your documents in NDJSON format, which is much faster.

  3. Be patient with large asset collections: If your dataset has many or large assets, the "Adding assets to archive..." step can genuinely take a very long time (potentially hours). According to the documentation on export issues, exports of large datasets can experience timeouts but may still complete successfully.

If the standard export command also appears to hang on the asset step for an unreasonable amount of time (more than an hour for moderate-sized datasets), you might be hitting resource limits or network issues. In that case, you could try exporting without assets first to get your documents, then handle assets separately if needed.

The key takeaway: stick with the documented export syntax rather than using --raw with piping, as that's not the standard workflow and may behave unpredictably.

Show original thread
34 replies
What document statistics are you working with? You can find that at manage.sanity.io .
I’m not sure what that means. How many documents?
Hi
user T
, sorry you're running into trouble exporting your dataset. It's indeed odd that it shows the assets step when using the
--raw
or
--no-assets
flags.
Could you check if this works when entered directly in the CLI (i.e. not via a script) from your project's studio root folder?

sanity dataset export development development.tar.gz --raw
Also, could you DM me your project ID?
FWIW I just tried again without
--raw
etc, and it works:
? File "/tmp/foo.tar.gz" already exists, would you like to overwrite it? Yes
Exporting dataset "development" to "/tmp/foo.tar.gz"
✔ Exporting documents... (2824/2824)
✔ Downloading assets... (1721/1721)
✔ Adding assets to archive...
✔ Clearing temporary files...
Export finished (4m 29s)
user M
that’s exactly how i’m running it
this worked:
npx sanity dataset export development --asset-concurrency 20 /tmp/foo.tar.gz
(but with all the assets)
Thanks for any help btw 🙂
@sanity/cli version 2.7.4
if that helps
That's helpful context, thanks. In that case you could skip my first question above - we'll see if we can spot any errors using the project ID you just shared 🙂
thank you!
BTW I’m pretty new to Sanity, so unsure whether it’s just operator error on my part.
Hey, even weirder…
Doesn't look like it. From what I can tell, you're using the command and flags correctly. Hope the logs give a hint here 🙂
I just tried it again
npx sanity dataset export development /tmp/foo2.tar.gz --raw
and it ran to completion super fast
maybe it’s an API issue and the cli output was a redherring?
? File "/tmp/foo2.tar.gz" already exists, would you like to overwrite it? Yes
Exporting dataset "development" to "/tmp/foo2.tar.gz"
✔ Exporting documents... (4545/4545)
✔ Downloading assets...
✔ Adding assets to archive...
✔ Clearing temporary files...
Export finished (3.7s)
or maybe having done a full export with assets before, made some difference to doing a raw export after?
i’m struggling to see what else changed.
Did you always place the
--raw
flag at the end? I think there's a known issue when it's placed earlier in the command and not correctly picked up.
I experimented with it before and after the filepath
Perhaps that’s the difference
Are we really hitting bugs due to brittle/fragile commandline option parsing in 2021? 😉
(I mean, good to know, and I’ll keep it in mind to avoid it, so thank you, but also…wow?)
Sorry, that sounds a bit ungrateful of me. I am very grateful if this is in fact the answer.
user M
do you see anything interesting in the logs?
It's worth verifying on our end as well that this is indeed the issue, but I do recall seeing it pop up recently. Bugs are of all the ages I guess 😉 You should feel confident to place flags arbitrarily everywhere else though.
I'll keep you posted on this one but recommend placing it deliberately at the end for now unless that continues to give throw errors.
I’m happy to write this off as “CLI parsing is fragile, ensure we build command line correctly” if you think that’s the issue.
sure, i’ll note that.
thanks very much!
between you and me, i like the old bugs the best 😉
Thanks
user A
and
user M
for all your help! Hopefully all queries in the future will be this simple.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?