Question

I'm trying to make a backup of my database to another hard drive using PHP/Samba. But it doesn't work and I'm stuck.

$dbBackup = 'backup_location.gz.des3';
if (!file_exists($dbBackup)) {
    throw new Exception("Today's backup does not exist!" . $dbBackup);
}
$dbBackup = realpath($dbBackup);

// create path to save on local drive
$savePath = 'folder\subfolder\\' . date('Y') . '\db\bu\\' . date('n') . '\\';
$savePath .= basename($dbBackup);

// build up SMBClient command
$command = 'smbclient';
$command .= ' -N'; // no-pass
$command .= ' -U ' . escapeshellarg($username) . '%' . escapeshellarg($password); // username/password
$command .= ' -O "TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192"'; // some options
$command .= ' -d 0'; // debug level
$command .= ' ' . escapeshellarg($share); // share name, it is \\x.x.com\x\x\x\x\".
$command .= ' -c ' . escapeshellarg('put ' . $dbBackup . ' ' . $savePath); // command to execute

// execute command on shell
$output = shell_exec($command);

// try to detect error's
if (stripos($output, 'NT_STATUS_') !== false) {
    throw new Exception($output);
}

Using this code I retrieve this error: NT_STATUS_OBJECT_PATH_NOT_FOUND

The error gives a path that it cannot find. I can visit the path but the file is obviously not there.

I'm very sure all the paths are correct and so are the user credentials.

Am I doing something wrong? typo's or anything? I'm stuck on this for a few weeks now.

Thanks in advance for any help!

Was it helpful?

Solution

The problem was that the drive I was putting the file on was in a different workgroup.

I added -W MYCORRECTWORKGROUP to the command and it works again!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top