Jump to content

[solved] database backup of main pw and second pw instance


Can
 Share

Recommended Posts

What am I mixing up that this won't work, or better to say will throw "..Base table or view not found..." 

$meta = new ProcessWire($config->paths->root . 'site-meta/', "http://meta.$config->domain");

$backupPath = $config->paths->assets . 'backups/database/';

$backup = new WireDatabaseBackup($backupPath);
$backup->setWire($wire);
$backup->setDatabase($database);
$backup->setDatabaseConfig($config);
$backupFile = $backup->backup(['description' => 'saludos your Cron']);
if ($backupFile) {
    wireZipFile("$backupFile.zip", $backupFile);
    exec("ln -sf $backupFile.zip {$backupPath}newest.sql");
    $log->message("linked $backupFile");
    unlink($backupFile);
}

$backupMeta = new WireDatabaseBackup($backupPath);
$backupMeta->setWire($meta);
$backupMeta->setDatabase($meta->database);
$backupMeta->setDatabaseConfig($meta->config);
$backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron']);
if ($backupMetaFile) {
    wireZipFile("$backupMetaFile.zip", $backupMetaFile);
    exec("ln -sf $backupMetaFile.zip {$backupPath}newestMeta.sql");
    $log->message("linked $backupMetaFile");
    unlink($backupMetaFile);
}

if I comment one of them out they'll work properly

if I'm trying to run both as in the snippet above the second one fails after the first tables with the above error indicating meta.field_date is missing but this field is only present in the above installation (so the "host" processwire)

even tried to explicitly set the tables to backup for the second on with no difference

$backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron', 'tables' => $backupMeta->getAllTables()]);

var_dumping $backupMeta->getAllTables() will show the correct tables, meaning there is no reference to field_date

tried to instantiate WireDatabaseBackup within meta by

$backupMeta = $meta->wire(new WireDatabaseBackup($backupPath));

which works creating pages but in this case throws another error, but as both run from the same pw installation (multisite) there is only one WireDatabaseBackup anyway..

and I also tried to specify a different path

the code is supposed to be part of a cron, right now it sits in my site/init for testing

So to clarify, my setup looks like this

root
	- wire
	- site
	- site-meta
	- index.php
	- index.config.php

everything else works as expected with this setup, so far.

Edited by Can
has been solved
Link to comment
Share on other sites

You should file a bug. WireDatabaseBackup::getAllTables() caches the list of tables in a static variable $tables across instances when it is called without parameters like WireDatabaseBackup::backupPDO() does. Since getAllTables() is only called once in the file (and not called by any other core file), I'm not sure if the caching option is necessary at all.

  • Like 1
Link to comment
Share on other sites

Thanks to you it works now :D

this time I explicitly set tables to backup for both while disabling caching like so

$backup = new WireDatabaseBackup($backupPath);
$backup->setWire($wire);
$backup->setDatabase($database);
$backup->setDatabaseConfig($config);
$backupFile = $backup->backup(['description' => 'saludos your Cron', 'tables' => $backup->getAllTables(false, false)]);
if ($backupFile) {
    wireZipFile("$backupFile.zip", $backupFile);
    exec("ln -sf $backupFile.zip {$backupPath}newest.sql");
    $log->message("linked $backupFile");
    unlink($backupFile);
}

$backupMeta = new WireDatabaseBackup($backupPath);
$backupMeta->setWire($meta);
$backupMeta->setDatabase($meta->database);
$backupMeta->setDatabaseConfig($meta->config);
$backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron', 'tables' => $backupMeta->getAllTables(false, false)]);
if ($backupMetaFile) {
    wireZipFile("$backupMetaFile.zip", $backupMetaFile);
    exec("ln -sf $backupMetaFile.zip {$backupPath}newestMeta.sql");
    $log->message("linked $backupMetaFile");
    unlink($backupMetaFile);
}

I saw this caching but didn't really noticed it's turned on by default and might be responsible..

  • Like 2
Link to comment
Share on other sites

Just found out that ProcessWire already handles the setWireAndDatabaseStuff in WireDatabasePDO::backups.

So, instead of this:

$backupPath = $config->paths->assets . 'backups/database/';
$backupMeta = new WireDatabaseBackup($backupPath);
$backupMeta->setWire($meta);
$backupMeta->setDatabase($meta->database);
$backupMeta->setDatabaseConfig($meta->config);
$backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron']);

...it could be just this:

$backupMeta = $meta->database->backups();
$backupMetaFile = $backupMeta->backup(['description' => 'saludos your Cron']);

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...