-2

I have a scenario where I need to copy production database to my dev database on daily basis. Both are different servers. What I have thought of writing a cronjob that will do the stuff. I have written a php script. I am connecting to remote production server via sshpass, taking its dump and then populating that dump.

exec("sshpass -p 'mypassword' ssh root@IP_ADDRESS:PORT");
exec("mysqldump -u root -p DB > production_dump.sql");
exec("mysql -u root -p test < production_dump.sql");

But at first line it throws error of stating

ssh: Could not resolve hostname IP_ADDRESS:PORT: Name or service not known

I have tried given solution on internet but non of them worked. Can any on please explain what I am doing wrong?

4

1 Answer 1

1

Your command is failing because it's not formatted right. You need to use one of the following formats:

sshpass -p 'mypassword' ssh root@IP_ADDRESS PORT
sshpass -p 'mypassword' ssh root@IP_ADDRESS -p PORT
sshpass -p 'mypassword' ssh ssh://root@IP_ADDRESS:PORT

However, I'm not sure if the rest of the script will work, especially if it starts asking for a password. A bash script would be the way to go.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.