You may need to use a second configuration file for both mysql schemas (and you should consider using a dedicated mysql user which have read only permissions for that - but this would be out of this scope)
My suggested solution:
To specify a config file, you need to add this to your mysqldump cmd: --defaults-file=/path/to/your/file
You could extend your backup script like that (just open the already existing file using sudo and replace its content with this one):
#!/usr/bin/bash
source ~/.${1}.my.cnf >/dev/null 2>&1
mkdir -p ~/backups/${1}
mysqldump --defaults-file=~/.${1}.my.cnf --single-transaction --add-drop-table $database | gzip > ~/backups/${1}/${1}-database-$(date +%Y%m%d-%H%M%S).sql.gz
Then, for each app that you want to backup, create a .(app name).my.cnf file containing the specific app mysql user/pass info.
i.e.
~/.mautic.my.cnf <= containing Mautic DB info)
~/.moodle.my.cnf <= (containing Moodle DB info)
Youâll also need to add a line inside both of the MySQL client configuration files:
database=your-db-schema-name
i.e. ~/.mautic.my.cnf
[client]
password=HudbIikbfd563eNBnh
user=mautic
[server]
database=mautic
i.e. ~/.moodle.my.cnf
[client]
password=HudbIikbfd563eNBnh
user=moodle
[server]
database=moodle
Then run your backup script like that:
mbackup mautic #This is for backing up Mautic DB
mbackup moodle #This is for backing up Moodle DB
In a crontab:
0 4 * * * /usr/local/bin/mbackup mautic
0 4 * * * /usr/local/bin/mbackup moodle
From there you should be good to go in order to use that quick basic backup script with any other projects that you may have.
EDIT: Forgot to remove the âmauticâ reference within the backup script - sorry about it, fixed!