Darrell
Writing from my phone so pardon the formatting ... Great to hear that it worked although it surprises me ... That link I sent explaining how to block certain php functions (like system() ) is usually a part of 'hardening' a web server ... Before I set up my own vps server with digital ocean (now moved to linode), I used several of the bigger named hosting companies like blue web, liquid web, etc ... system() was generally always blocked ... I think when I did the presentation a couple years ago on cwp (CentOS web panel) I might have touched on some of the settings it used , with the function blocks being one of them.
I would suggest a change to the backup_file ... Add .gz on the end and then insert a pipe to gzip to compress the backup
$backup_file='/home/<private>/public_html/<private>.com/demo/admin/backups/'.$dbname.'_'.date("Y-m-d-H-i-s").'.sql.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname |gzip >> $backup_file";
As far as where to learn this (bash scripting in general), I had a friend ask me this a while back ... A Google search for "bash 101" found what appeared to be a good set of starting points. Codecademy.com looks like they've got a bash tutorial but I haven't looked at it ... But I did go through their python tutorial a couple years ago and it was pretty good.
Minus the php starting and ending tags it looks like your script should translate to bash with minimal edits ... Variable assignments work the same way except you do not need the $ in the assignment, only when you use the variable. Also no spaces around the =
system($command) becomes exec $command
And I had to tweak the date ... You get some extra periods in the file name .. but basically it works:
I literally did a 'cp dbbackup.php dbbackup.sh' and then edited
#!/bin/bash
dbhost='localhost';
dbuser='spotweb';
dbpass='xxx';
dbname='spotweb';
backup_file='/var/www/html/'.$dbname.'_'.$(date "+%m-%d-%Y-%H%M%S").'.sql';
command="/usr/bin/mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname > $backup_file";
echo $command;
exec $command
chmod +x dbbackup.sh
./dbbackup.sh
Boom 😂
I added the full path to mysqldump .. if you need to run this from cron using full paths is always recommended because they $PATH inside cron is limited. Likewise the gzip would also need /usr/bin