Home > Software design >  Restore mysql backup via crontab not working
Restore mysql backup via crontab not working

Time:09-14

Good afternoon, I want to automate redundancy for Redmine. I have created a second server, which is waiting for the first one to crash, while updating its database. However, at the moment of updating the database is a strange problem, I'll try to describe it.

Running the script manually from the console, the database is copied and updated without any problems, but as soon as I call the same script from crontab database is only downloaded but no restores.

Maybe there is some special way to restore the database via crontab?

OS: Debian 11

The redmine build by bitnami

Here is the script code itself

#!/bin/sh
ssh -f -L3310:localhost:3306 [email protected] -N
MYSQL_PWD=******** mysqldump --column-statistics=0 -P 3310 -h 127.0.0.1 -u root --databases bitnami_redmine --add-drop-database > /home/bitnami/backups/db_backups/redmine_db_mon_1.sql

sleep 5
killall ssh

sleep 2
sudo /opt/bitnami/ctlscript.sh stop apache

sleep 2
MYSQL_PWD=******** mysql -u root < /home/bitnami/backups/db_backups/redmine_db_mon_1.sql

sleep 2
sudo /opt/bitnami/ctlscript.sh start apache

CodePudding user response:

Since I am too lazy to understand and configure replication, synchronization and other things, made a simple script.

So, to make it work I had to add sudo to Mysql, which is strange. But it's like this

sudo mysql -uroot -p***** < /home/bitnami/backups/db_backups/redmine_db_mon_1.sql
  • Related