Those lines are in the setup.php file which is called at the end of the config.php. So its not related specifically to the backup.
I'm guessing the error is because its being called from the command line rather than from Apache.
In config.php how do you set the values for
$CFG->wwwroot = '';
$CFG->dirroot = '';
If you use something like
$CFG->wwwroot = 'http://' . $_SERVER['HTTP_HOST'];
Then it won't work because its called from the command line - so replace it with the literal value eg:
$CFG->wwwroot = 'http://www.yourwebsite.com';
and the same for dirroot and dataroot - use literal values instead of functions.