Blame | Last modification | View Log | Download | RSS feed
<?php
global $BACKUP_DATA;
$BACKUP_DATA = array(
'client' => array(
'table' => 'client',
'fields' => array( 'name',
'notes',
'internal_notes',
'added_date',
'removed_date'
),
'query' => 'select name,notes,internal_notes,added_date,removed_date from client',
'insert' => 'insert into client(name,notes,internal_notes,added_date,removed_date) select <name>,<notes>,<internal_notes>,<added_date>,<removed_date>'
),
'site' => array(
'table' => 'site',
'fields' => array( 'client',
'name',
'notes',
'added_date',
'removed_date'
),
'query' => 'select client.name client, site.name name,site.notes,site.added_date,site.removed_date from site join client using (client_id)',
'insert' => 'insert into site(client_id,name,notes,added_date,removed_date) select client_id,<name>,<notes>,<added_date>,<removed_date> from client where name = <client>'
),
'client_alias' => array(
'table' => 'client_alias',
'fields' => array( 'client',
'alias',
'added_date',
'removed_date'
),
'query' => 'select client.name client, alias,client_alias.added_date,client_alias.removed_date from client_alias join client using (client_id)',
'insert' => 'insert into client_alias(client_id,alias,added_date,removed_date) select client_id,<alias>,<added_date>,<removed_date> from client where name = <client>'
),
'attrib' => array(
'table' => 'attrib',
'fields' => array( 'name',
'added_date',
'removed_date'
),
'query' => 'select name,added_date,removed_date from attrib',
'insert' => 'insert into attrib(name,added_date,removed_date) select <name>,<added_date>,<removed_date>'
),
'device_type' => array(
'table' => 'device_type',
'fields' => array( 'name',
'show_as_system',
'added_date',
'removed_date'
),
'query' => 'select name,show_as_system,added_date,removed_date from device_type',
'insert' => 'insert into device_type(name,show_as_system,added_date,removed_date) select <name>,<show_as_system>,<added_date>,<removed_date>'
),
'computers' => array(
'table' => 'device',
'fields' => array( 'client',
'site',
'device_type',
'name',
'notes',
'added_date',
'removed_date'
),
'query' => " select client.name client, site.name site, device_type.name device_type, device.name,device.notes,device.added_date,device.removed_date
from device join device_type using (device_type_id) join site using (site_id) join client using (client_id)
where device_type.show_as_system = 'Y' and device.part_of is null
",
'insert' => 'insert into device(site_id,device_type_id,name,notes,added_date,removed_date)
select min(site.site_id),device_type.device_type_id,<name>,<notes>,<added_date>,<removed_date>
from client join site using (client_id), device_type
where client.name = <client> and site.name=<site> and device_type.name=<device_type>
group by device_type.device_type_id'
),
'virtual servers' => array(
'table' => 'device',
'fields' => array( 'client',
'site',
'device_type',
'part_of',
'name',
'notes',
'added_date',
'removed_date'
),
'query' => " select client.name client, site.name site, device_type.name device_type, parent.name part_of, device.name,device.notes,device.added_date,device.removed_date
from device join device_type using (device_type_id) join site using (site_id) join client using (client_id) join device parent on device.part_of = parent.device_id
where device_type.show_as_system = 'Y'
",
'insert' => 'insert into device(site_id,device_type_id,part_of,name,notes,added_date,removed_date)
select site.site_id,device_type.device_type_id,parent.device_id,<name>,<notes>,<added_date>,<removed_date>
from client join site using (client_id) join device parent, device_type
where client.name = <client> and site.name=<site> and device_type.name=<device_type> and parent.name = <part_of>'
),
'device_attribs' => array(
'table' => 'device_attrib',
'fields' => array('client',
'site',
'device',
'attrib',
'value',
'added_date',
'removed_date'
),
'query' => "select client.name client,
site.name site,
device.name device,
attrib.name attrib,
device_attrib.value value,
device_attrib.added_date,
device_attrib.removed_date
from device_attrib join device using (device_id) join site using (site_id) join client using (client_id) join attrib using (attrib_id) join device_type using (device_type_id)
where device_type.show_as_system = 'Y'",
'insert' => 'insert into device_attrib(device_id,attrib_id,value,added_date,removed_date)
select device.device_id,attrib.attrib_id,<value>,<added_date>,<removed_date>
from client join site using (client_id) join device using (site_id),attrib
where client.name = <client> and site.name=<site> and device.name=<device> and attrib.name = <attrib>'
),
'device_alias' => array(
'table' => 'device_alias',
'fields' => array( 'device',
'alias',
'added_date',
'removed_date'
),
'query' => 'select device.name device, alias,device_alias.added_date,device_alias.removed_date from device_alias join device using (device_id)',
'insert' => 'insert into device_alias(device_id,alias,added_date,removed_date)
select device_id,<alias>,<added_date>,<removed_date> from device where name = <device>'
),
'report' => array(
'table' => 'report',
'fields' => array( 'name',
'query',
'parameters',
'screen_report'
),
'query' => 'select name,query,parameters,screen_report from report',
'insert' => 'insert into report(name,query,parameters,screen_report)
select <name>,<query>,<parameters>,<screen_report>'
),
'login' => array(
'table' => 'login',
'fields' => array( 'login_id',
'email',
'pass',
'where_clause',
'added_date',
'removed_date'
),
'query' => ' select login_id,email,pass,where_clause,added_date,removed_date from login;',
'insert' => 'insert into login(login_id,email,pass,where_clause,added_date,removed_date)
select <login_id>,<email>,<pass>,<where_clause>,<added_date>,<removed_date>'
),
);
function backup() {
//$tmpfname = tempnam("/tmp", "BDB");
$tmpfname = '/tmp/' . date('YmdHiss') . 'camp.sql';
$handle = fopen($tmpfname, "w");
global $BACKUP_DATA;
$returnValues = array();
$tableNames = array();
foreach ($BACKUP_DATA as $job => $info) {
$tableNames[$info['table']] = 1;
}
foreach ($tableNames as $tableName => $trash) {
//fwrite($handle, "select '$tableName', count(*) from $tableName;\n");
fwrite($handle, "delete from $tableName;\n"); // delete everything in the table
fwrite($handle, "ALTER table $tableName auto_increment=1;\n"); // and set any auto_increments to start at 1
}
foreach ($BACKUP_DATA as $job => $info) {
fwrite($handle, "/* $job */\n");
$table = $info['table'];
$resource = mysql_query( $info['query'] );
$fieldNames = implode($info['fields'], ',');
while ($thisRow = mysql_fetch_assoc($resource)) {
$insertQuery = $info['insert'];
foreach ($info['fields'] as $thisField) {
$insertQuery = search_replace_string($insertQuery, '<' . $thisField . '>', makeSafeSQLValue($thisRow[$thisField]) );
}
fwrite($handle, "$insertQuery;\n");
}
}
fclose($handle);
system ( "gzip $tmpfname" );
$tmpfname .= '.gz';
header('Content-type: application/gzip');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="' . basename($tmpfname) . '"');
readfile($tmpfname);
unlink($tmpfname);
}
// initialize any module definitions also
$InstalledModules = array();
// get module information
$data = queryDatabaseExtended( "select theValue from _system where removed_date is null and group_name = 'Modules'");
if ($data) {
foreach ($data['data'] as $row) {
$InstalledModules[] = $row['theValue'];
}
// note, we are only going to include the database.php. All other stuff is left to the individual modules
// $_SESSION['file system root'] is set in login.php, and is the path to the root of this application, so all else is relative
foreach ($InstalledModules as $directory) {
include_once( $_SESSION['file system root'] . "/$directory/backupDB.php");
}
}
?>
Generated by GNU Enscript 1.6.5.90.