[Solved] Including password in restore command?

Is it possible to add the MySQL Administrator password to the “bench restore” command as an argument?

I am moving fresh database backups to a hot spare server every hour during the business day.
I would like to be able to set a con job to chdir to the frappe-bench directory and run the bench restore command (and include the password on the command line).

This would make it pretty easy to jump to a backup server instance when it is already no more than an hour behind the primary server.

I could setup a script to take on restoring the backup (as long as I can find a way to include password)

This would keep a running server less than an hour behind the primary server and ready to take over if the need arose.

I am open to ideas on this one. This is a v10 production system. I have everything else working. I just need to figure out hos to do most of the startup with a single script

Any guidance here is going to very apreciated.


Does anyone know if this is possible?

If not (or not sure), then is there a mysql command that I can use to accomplish the same thing?




According to frappe/commands/site.py
You should try bench restore --mariadb-root-password your_sql_password


Thank You 1,000% @pipech

Thank was excellent detective work!
I would not have had any idea how to ferret out that piece of information on my own.

The command works now as a single command line without having to wait for a password prompt.

Here is an example of the exact command I used based on the following assumptions:

  • the MariaDB root password is: H@ppyK@mper
  • the compressed sql backup file is unzipped into the user home folder: kewlkid
  • the unzipped file is called: mybackup.sql
  • the ERPNext site is the default site1.local site
  • so, running this command from the /home/kewlkid/frappe-bench/ directory:

sudo bench --force --site site1.local restore --mariadb-root-password H@ppyK@mper /home/kewlkid/mybackup.sql

This worked exactly the way wanted. I posted the command syntax here for anyone else that may want to use a single command in the future as a way to semi-automate the process.

Thank you again for the pointer to the correct answer.