Exporting Data Out of Vercel KV

Ilya Kaminsky
The Academy
Published in
3 min readJun 26, 2023

--

TL;DR

  1. Download, extract, and prepare to run upstash-redis-dump
  2. Run upstash-redis-dump -db 0 -host HOST -port PORT -pass PASSWORD -tls > redis.dump

More Info

Vercel offers easy to setup storage products. One such product is called Vercel KV, which is powered by Redis through a partnership with Upstash. However, it doesn’t include all of the Redis-native features, as seen in this list of unsupported features. The primary one being the ability to backup and restore the data.

I received an email from Vercel saying that I’ve run out of 30,000 requests. That wasn’t even true. But by that point, I already learned of Upstash’s free tier, which is much more generous than Vercel’s “Hobby” tier:

(Source: WunderGraph — Dodging the Vercel Tax)

All together, that prompted me to try and back up all of my data so I could migrate it someplace else. I ended up spending a bunch of time attempting to export it out. At first via the redis-cli as recommended by the docs:

$ redis-cli --tls -u redis://username:password@subdomain.domain.tld:54321 --rdb redis.rdb
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
sending REPLCONF capa eof
REPLCONF capa error: ERR Command is not available: 'REPLCONF'. See https://vercel.com/docs/errors/vercel-kv-error-codes for details
sending REPLCONF rdb-only 1
REPLCONF rdb-only error: ERR Command is not available: 'REPLCONF'. See https://vercel.com/docs/errors/vercel-kv-error-codes for details
SYNC with master failed: -ERR Command is not available: 'SYNC'. See https://vercel.com/docs/errors/vercel-kv-error-codes for details

When that failed, I tried to run the SAVE command right from the console:

$ redis-cli --tls -u redis://username:password@subdomain.domain.tld:54321
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
subdomain.domain.tld:54321> SAVE
(error) ERR Command is not available: 'SAVE'. See https://vercel.com/docs/errors/vercel-kv-error-codes for details

…but it also failed. As did BGSAVE.

I then looked into writing a script to pull the data out, key-by-key. First, I explored the option of following existing scripts that were mostly written in Python and Go. That didn’t work, likely due to Vercel KV’s TLS requirement:

When you create a Vercel KV store, a Redis store is provisioned with support for TLS v1.2 and v1.3 enabled. There is no way to disable TLS for your KV store.

Lastly, when I tried to use the @vercel/kv library outside of the Next.js framework, it kept throwing a “connection refused” error. It’s worth mentioning that Vercel also created Next.js. And just as I was about to give up, I came across this “Import/Export Data” document from Upstash. That’s where I learned about their nifty tool called upstash-redis-dump.

Using upstash-redis-dump

Below you will find more detailed instructions on how to export and import your data out of Vercel KV and into either a self-hosted Redis instance or onto Upstash.

Prerequisites

  1. Download the appropriate upstash-redis-dump release
    (E.g., upstash-redis-dump_macos_arm64.zip that runs on Apple’s chips)
  2. Extract the binary out of the zip file
  3. Turn it into an executable by running chmod +x on it in the Terminal

Export

Export the data using the following command:

upstash-redis-dump -db 0 -host HOST -port PORT -pass PASSWORD -tls > redis.dump

Be sure to replace HOST, PORT, and PASSWORD using the settings from your Vercel Storage dashboard.

Import

Import to Upstash or any other Redis instance:

redis-cli --tls -u redis://username:password@subdomain.domain.tld:54321 --pipe < redis.dump

You’ll want to replace pretty much everything in that URL. Just be mindful of the --tls flag, which may not be applicable in your case.

Closing Thoughts

I sincerely hope you found this helpful. Please share any feedback by commenting below. And let me know if you know of any other solutions for rapid prototyping whilst minimizing vendor lock-in!

--

--