Migrating Gravity Forms from the command line with WP-CLI
GravityMigrate adds wp gk migrate commands to WP-CLI. With them you can export and import a migration file from a terminal, script a move between two servers over SSH, or migrate a site that’s too large to finish in the browser. The commands make and read the same migration file as the GravityMigrate screen in the dashboard, so a file exported on one side imports on the other.
Before you begin #
- WP-CLI on the server you run the commands on, as Installing WP-CLI describes.
- GravityMigrate active on both sites.
- An administrator’s login. Every
wp gk migratecommand needs--user=<administrator login>, and without it the command stops with “Run with --user=<an administrator login>” and the reason. The examples below use--user=admin.
Quick start #
Export from the old site, copy the file across, and import it on the new site:
# On the old site
wp gk migrate export --user=admin --forms=all --output=/tmp/migration.zip
# On the new site, after copying the file there
wp gk migrate import /tmp/migration.zip --user=admin --yesWithout --data, the export holds entries, Views and the pages that embed your forms or Views. Add the other kinds of data you need with --data, as the next section shows.
Exporting a migration file #
wp gk migrate export writes the forms and data you choose into a ZIP file.
# Forms 3 and 5 with their entries, Views and pages
wp gk migrate export --user=admin --forms=3,5 --data=entries,views,posts --output=/srv/backups/forms.zip
# Every form, with entries submitted in the first half of 2026
wp gk migrate export --user=admin --forms=all --data=entries --date-start=2026-01-01 --date-end=2026-06-30 --output=/tmp/first-half.zip
# Encrypt the file with a password
wp gk migrate export --user=admin --forms=all --password="a-strong-password" --output=/tmp/secure.zip
# Put the uploaded files inside the file
wp gk migrate export --user=admin --forms=all --include-files --output=/tmp/standalone.zip| Option | What it does |
|---|---|
--forms=<ids> | Required. Comma-separated form IDs, or all. Here all includes inactive forms and forms in the trash. |
--data=<types> | Comma-separated data types, or all. Without it: entries,views,posts. The types are listed under Data types. |
--date-start=<Y-m-d>,--date-end=<Y-m-d> | Export only the entries submitted on or after the start date and on or before the end date. |
--password=<password> | Encrypt the file. Inspecting or importing it then needs the same password. |
--include-files | Put the files uploaded with the entries inside the migration file, so the new site doesn’t download them from this one. Use it when this site can’t be reached from the new one, or is about to be switched off. The file gets larger. The files inside can add up to 80% of this site’s upload limit, newest first, and the rest are still downloaded from this site during the import. Adds uploads and entries to --data. |
--public-url=<url> | Replace this site’s address with <url> in the content of its pages and in the links of File Upload fields that take one file, so the new site downloads those files from an address it can reach. Use it when the address this site stores, such as a local or staging address, isn’t reachable from the new site. When every uploaded file has to come across, use --include-files. |
--output=<path> | Copy the finished file to this path. Without it, the file stays in wp-content/uploads/gk-migrate-exports/, which is cleared after three hours. |
--porcelain | Print only the path of the file. |
--format=<format> | Print the summary as table (the default) or json. |
When you export a form that uses GP Nested Forms, list the child form’s ID in --forms with its parent’s. The command line doesn’t add child forms on its own, as the GravityMigrate screen does, and a parent imported without its child form arrives without its child entries. How does GravityMigrate handle nested forms? has the details.
Importing a migration file #
wp gk migrate import reads a migration file and adds its forms, entries, Views and other data to the current site, as new forms with new IDs.
# Import everything in the file
wp gk migrate import /tmp/migration.zip --user=admin --yes
# Import only some of the forms and data
wp gk migrate import /tmp/migration.zip --user=admin --forms=3,5 --data=entries,views --yes
# Import a file that has a password
wp gk migrate import /tmp/secure.zip --user=admin --password="a-strong-password" --yes
# Import without downloading the uploaded files
wp gk migrate import /tmp/migration.zip --user=admin --skip-uploads --yes| Option | What it does |
|---|---|
<zip> | The path to the migration file. Required. |
--forms=<ids> | The command imports only these forms, named by the IDs they had on the old site. The default is all. An ID that isn’t in the file stops the command with “Form <id> is not in this bundle”. |
--data=<types> | The data types to import, or all (the default). Only types the file holds are imported. |
--password=<password> | The file’s password. A missing or wrong one stops the command with “The import bundle could not be decrypted.” |
--skip-uploads | Don’t download the uploaded files. The imported entries keep linking to the files on the old site. |
--yes | Import without asking first. Without it, the command asks “This writes forms, entries, and Views into this site. Continue? [y/n]”, and when nobody answers, as in a script, it imports nothing and still exits with 0. |
--porcelain | Print only the IDs of the new forms, one per line. |
--format=<format> | Print the summary as table (the default) or json, with the new form IDs, the number of entries, and the uploaded files downloaded and failed. |
--download-timeout=<secs>,--max-download-bytes=<n>,--max-dump-file-size=<n> | Raise or lower the import’s limits for this run: 300 seconds and 100 MB for each uploaded file it downloads, and 2 GB for the database dump in the file. |
With --data=all, or without --data, an import also brings any settings the file holds. Gravity Forms Settings and GravityKit Settings then replace this site’s own settings, license keys and API credentials included, and the command doesn’t ask about them the way the GravityMigrate screen does. To leave them out, name the other types in --data.
Inspecting a file before importing #
wp gk migrate inspect shows what a migration file holds without importing it. It names the site the file came from, its forms and data types, and whether the uploaded files are inside it.
wp gk migrate inspect /tmp/migration.zip --user=admin
# As JSON, for a script
wp gk migrate inspect /tmp/migration.zip --user=admin --format=jsonAdd --password=<password> for a file that has one. src_url_public says whether the address the file came from is public. For a local or private address it reads NO (private/SSRF-blocked: uploads will not download), and a warning suggests exporting again with --public-url. A public address doesn’t prove the new server can reach it.
Checking migration state #
wp gk migrate status reports whether an import is running, whether an earlier import crashed, and whether an export left files to clean up. While an import runs, it also shows the phase it’s in, such as “Importing entries”, and how many of the phase’s steps are done. An estimate of the seconds left and the seconds since the last step come with it.
wp gk migrate status --user=admin
wp gk migrate status --user=admin --format=json
# Follow a running import until it finishes
wp gk migrate status --user=admin --watch--watch redraws the status every two seconds until the import finishes, and can’t be combined with --format=json. To follow an import from a script, run status --format=json in your own loop.
Clearing stuck migration state #
When an import was interrupted, the next one can stop with “Import already in progress”. Check with wp gk migrate status --user=admin that nothing is still running. Then clear what the interrupted import left behind: its temporary tables, the unpacked file and the progress records.
wp gk migrate reset --user=admin --yesMigrating forms to or from another form plugin #
The command line also runs the migration between Gravity Forms and another form plugin on the same site. The to command copies Gravity Forms forms into the other plugin, and from recreates the other plugin’s forms in Gravity Forms. Both need an administrator, and they work only while the other plugin is active.
Migrating forms from another form plugin explains what comes across and how to read the report.
First, list the plugins this site can migrate to or from:
wp gk migrate plugins --user=admin
wp gk migrate plugins --user=admin --available --format=idsThe list names each plugin’s slug, whether it can be a destination (to) or a source (from), and why not when it can’t. The slugs are contact-form-7, fluent-forms, formidable-forms, forminator, ninja-forms, wpforms and ws-form. --available keeps only the plugins this site can use. Then:
# See what would happen to each field of form 3 in Fluent Forms, and change nothing
wp gk migrate to fluent-forms --user=admin --forms=3 --dry-run
# The same check, printing only the IDs of the forms checked
wp gk migrate to fluent-forms --user=admin --forms=3 --dry-run --format=idsWithout --dry-run, the command creates the forms in the other plugin, or in Gravity Forms with from.
| Option | What it does |
|---|---|
<plugin> | The other plugin’s slug, as wp gk migrate plugins lists it. |
--forms=<ids> | Required. Comma-separated form IDs, or all. With to, the IDs are Gravity Forms form IDs, and all means every active form that isn’t in the trash. With from, they are the other plugin’s own form IDs, and all means every form it lists. |
--dry-run | Print what happens to each field, with the warnings, and change nothing. |
--yes | Run without asking first. A run that creates forms needs it with every --format except table. A --dry-run doesn’t. |
--format=<format> | table (default), json, count or ids. After a run, count and ids cover the forms that were created, and json lists every form with any failure. With --dry-run, they cover the forms that were checked, and nothing is created. |
GravityMigrate prints each form’s warnings after the field report.
Data types #
--data takes a comma-separated list of these types, or all:
| Type | What it holds |
|---|---|
entries | The forms’ entries, with their notes and other entry data. |
uploads | The files uploaded with the entries. Adds entries. |
views | GravityView Views built on the forms. |
posts | The pages and posts that embed the forms or Views. |
revisions | Form revisions. |
addon_feeds | The add-on feeds attached to the forms. Which feeds and add-ons migrate covers what else each add-on needs. |
gravityflow | Gravity Flow history, where the site has it. |
drafts | Entries saved to finish later. |
gf_settings | A set list of Gravity Forms settings. |
gk_settings | GravityKit settings, GravityView’s included. |
rest_api_keys | Gravity Forms REST API keys. |
all includes the last three, which can hold license keys and API credentials. The GravityMigrate screen leaves them off unless you tick them. An export skips a type whose table doesn’t exist on the site, with a warning such as “Skipping data type ‘gravityflow’: its Gravity Forms table does not exist on this site.”
Output and exit codes #
A command that works exits with 0. When a command stops, it prints “Error:” with the reason and exits with 1, so set -e in a shell script stops at the first failure. Warnings print as “Warning:” lines and don’t change the exit code.
A to or from run where some forms fail and others work also exits with 0. In a script, read the result too, for example the failure that --format=json lists for each form.
In a script, use export --porcelain, which prints only the file’s path, and import --porcelain, which prints only the new form IDs. export, import, inspect and status also print their summary as JSON with --format=json.
Scripting a migration between two servers #
A script can export, copy the file across and import it in one run:
#!/bin/bash
set -e
# Export on this site and keep the path of the file
ZIP=$(wp gk migrate export --user=admin --forms=all --porcelain)
# Copy it to the new server and import it there
scp "$ZIP" deploy@destination:/tmp/migration.zip
ssh deploy@destination "wp gk migrate import /tmp/migration.zip --user=admin --yes --porcelain"Troubleshooting #
- “‘gk’ is not a registered wp command” or “‘migrate’ is not a registered subcommand of ‘gk'”: GravityMigrate isn’t active on the site the command runs on. Activate it, and on a multisite network add
--url=<site address>for the right site. - “Run with --user=<an administrator login>”: add
--user=with an administrator’s login or user ID. - “Import already in progress”: an earlier import still holds its lock. Run
wp gk migrate status --user=admin. If nothing is running, runwp gk migrate reset --user=admin --yesand import again. - The uploaded files didn’t come across: the import ran with
--skip-uploads, a file was over the download limits (--max-download-bytes,--download-timeout), or the new site couldn’t reach the old site’s address. Files past the 80% that--include-filespacks are downloaded too, so they need that address as well. Check the file withwp gk migrate inspect, then export again with--include-files. - “The import bundle contains a file whose uncompressed size exceeds the maximum allowed size and was rejected.”: the database dump in the file is larger than the import allows.
wp gk migrate inspectshows its size indump_size_bytes. Raise the limit for one run with--max-dump-file-size=<bytes>.
Related articles #
- Before you begin
- Quick start
- Exporting a migration file
- Importing a migration file
- Inspecting a file before importing
- Checking migration state
- Clearing stuck migration state
- Migrating forms to or from another form plugin
- Data types
- Output and exit codes
- Scripting a migration between two servers
- Troubleshooting
- Related articles