Skip to content

search-replace

search-replace replaces text in the database of an environment, for example after moving a site to a new domain. It reports what would change unless you pass --apply.

Terminal window
kinstactl search-replace my-site http://old.example https://new.example --env live
kinstactl search-replace my-site http://old.example https://new.example --env live --apply --clear-cache --yes

Search and replace in the database.

Terminal window
kinstactl search-replace my-site http://old.example https://new.example --env live
kinstactl search-replace <site> <search> <replace> [options]

Search and replace in the database (dry run unless --apply)

Arguments

ArgumentDescription
sitesite name, display name or ID
searchtext to search for
replacereplacement text

Options

OptionDescription
--env <environment>environment name or ID
--applyperform the replacement instead of reporting matches
--clear-cacheclear the cache after the replacement
--dry-runprint the resolved target and request; change nothing
--no-waitreturn the operation ID instead of waiting
--timeout <minutes>give up waiting after this many minutes (default 30)
--yesskip the confirmation prompt

Global options --profile, --json and --no-input apply too. See scripting and CI.

Kinsta API: GET /sites, POST /sites/tools/search-and-replace

Without --apply the replacement is not performed: Kinsta only reports the matches, and the command asks for no confirmation. Run it this way first and check the result. Add --apply to make the change. That changes content, so the command then asks for confirmation. On a terminal you answer a prompt; in a script pass --yes, otherwise it fails with CONFIRMATION_REQUIRED (exit code 5).

Terminal window
kinstactl search-replace my-site http://old.example https://new.example --env live --apply --yes

--clear-cache clears the cache after the replacement. Take a backup before you apply.

--dry-run is not the same as leaving out --apply: the default report is still a request to Kinsta, while --dry-run only prints the request that would be sent and sends nothing at all.

Without --env, a site with one environment uses it; a site with several gets a picker on a terminal and fails with ENV_REQUIRED in a script. See Sites and environments.

The command waits for Kinsta to finish, and accepts --no-wait and --timeout <minutes>; see operations. The report from Kinsta is the result of the operation and is what is printed on stdout. With --json you get one document with operation_id, status, message and data. With --no-wait the command returns right after the request is accepted: in human mode the operation ID appears only in the Follow with: hint on stderr, and with --json it is operation_id on stdout.