1

I have a php script that does backups. The backups have been failing, because one of the first commands throws an error and stops the script. When I run the script in the terminal, it works just fine. I even set up the cron to run at the next minute, so I know the machine is active, the external hard drive is mounted and accessible, etc, but then it still fails.

This is the command I'm executing:

/Users/kenny/google-cloud-sdk/bin/gsutil cp gs://backups.mydomain.com/sql/mydomain-db.2023-06-17-1687023004.sql.gz /Users/kenny/extdrive/backup.mydomain/backups/2023/sql/2023-06-17/mydomain-db.2023-06-17-1687023004.sql.gz 2>&1

And my logs show:

Copying gs://backups.herdboss.com/sql/herdboss-db.2023-06-17-1687023004.sql.gz...

==> NOTE: You are downloading one or more large file(s), which would run significantly faster if you enabled sliced object downloads. This feature is enabled by default but requires that compiled crcmod be installed (see "gsutil help crcmod").

OSError: Operation not permitted.

ERROR: COMMAND EXIT CODE: 1

One potential clue, is that I checked on the message about crcmod needing to be enabled to help the download speed, but I've already got crcmod installed. I followed the instructions from gsutil help crcmod and it said the configuration was good.

I'm not sure if that helps identify the problem, but there does seem to be at least some environmental difference when I run from cron vs run from the command line.

Any ideas?


If it matters, here is the php that I use the run the command:

$cmd = "$gsutil cp $gspath $backupdir/$filename";
execandlog($cmd);


function execandlog(string $command, string $inputtext = null, bool $shouldhorkonerrorexitcode = true, int &$exitcode = null): ?string {
    $fullcommand = "$command 2>&1";
    logmesg($fullcommand);
    
    $descriptors = [
        0 => ($inputtext === null) ? STDIN : ['pipe', 'r'],
        1 => ['pipe', 'w'],
        2 => STDERR,
    ];
    
    $pipes = [];    
    $process = proc_open($fullcommand, $descriptors, $pipes);
    $output = null;
    
    if (is_resource($process)) {
        if ($inputtext !== null) {
            if (false === fwrite($pipes[0], $inputtext)) {
                logmesg("ERROR: UNABLE TO WRITE TEXT TO INPUT PIPE");
                exit(-1);
            }
            
            fclose($pipes[0]);
        }
        
        $output = '';
        $commandoutputstream = $pipes[1];
        while (false === feof($commandoutputstream)) {
            $line = trim(fgets($commandoutputstream, 4096));
            $output .= "$line\n";
            logmesg($line);
        }
        fclose($commandoutputstream);
        
        $status = proc_get_status($process);
        $exitcode = $status['exitcode'];
        proc_close($process);
        
        if ($exitcode !== 0) {
            // Something went wrong
            logmesg("ERROR: COMMAND EXIT CODE: $exitcode");
            if ($shouldhorkonerrorexitcode) {
                exit(-1);
            }
        }
    }
    
    return $output;
}

0

You must log in to answer this question.

Browse other questions tagged .