Sync users from production and development environments using wp cli
-
I want to sync users registered at production environment to development environment.
Using the below command sequence for this:
1) Find max user id at the target dev environment using:
wp user list --role='customer' --orderby=ID --order=asc | awk -v max=0 'FNR == 1 {{next}} {{if($1>max){{want=$1; max=$1}}}}END{{print want}}'
2) Export users whose id is larger than the max user id from 1) to csv on the source production env.
wp user list --fields=ID,user_login,user_email,user_pass,user_registered --role='customer' --orderby=ID --order=asc --format=csv --user={root_user} --path={wp_path} --ssh={usr}@{host}:{port} | awk 'FNR == 1 {{next}} $1+0>{max_user_id} {{print ;}}'
3) download the csv file from production to dev env.
4) import the csv to target dev env
wp user import-csv /tmp/users_to_sync.csv --skip-update --user={user} --path={path}
However, there’s an issue that passwords are exported as hashed. After successful step 4, imported user can’t login on the dev. env.
How to sync users correctly if it’s possible at all using wp-cli?
Is downloading users and users_meta tables enough? Maybe it’s simplicity overweighs the complexity of syncing users using wp cli?
- The topic ‘Sync users from production and development environments using wp cli’ is closed to new replies.