-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
executable file
·111 lines (91 loc) · 4.93 KB
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
include './config/dbc.php';
$conn = new MainConfig();
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<?php require_once './include/systemHeader.php'; ?>
</head>
<body>
<div id="wrap" class="" >
<?php require_once './include/navBar.php'; ?>
<div class="content">
<div class="row-fluid">
<div class="span12">
<div class="box" style="padding-left: 10px">
<div class="box-head">
<h4> System Backup</h4>
</div>
<p> </p>
<p> </p>
<p><font size="+1" > Click the button below to run the daily data backup process. </p>
<p>
After successful completion of the backup file, we advise you to copy the file to your secure data storage location.
In case of an emergency breakdown, you can provide us the backup file to restore your system to the previous state where the backup was taken.
</p>
<p>Example backup file name : invosys2014-03-30.zip</p>
<p> </p>
<?php
error_reporting(0);
//set the default file name
$backupName = "invosys" . date("Y-m-d") . "-";
//include [require] mysql dump engine
require_once('MySQLDump.class.php');
$starttime = time();
//mysql info
$dbhost = 'localhost'; //db host
$dbuser = 'root'; //db user name
$dbpass = ''; //db password
$dbname = 'invoicesys'; //db to work with
$drop_table_if_exists = true; //should we drop table if exist?
$somecontent = "/*\n
+-------------------------------------------------------------+\n
+-------------------------------------------------------------+\n
+---------By:Amila Jayasinghe ([email protected])-----------+\n
+-------------------------------------------------------------+\n
*/\n\n";
// no need for editing further
$backup = new MySQLDump(); //create new instance of MySQLDump
$backup->droptableifexists = $drop_table_if_exists; //set drop table if exists
$backup->connect($dbhost, $dbuser, $dbpass, $dbname); //connect
if (!$backup->connected) {
die('Error: ' . $backup->mysql_error);
} //if not connected, display error
$backup->list_tables(); //list all tables
$broj = count($backup->tables); //count all tables, $backup->tables will be array of table names
//echo "<pre>\n"; //start preformatted output
$somecontent .= "-- Dumping tables for database: `$dbname`\n"; //write "intro" ;)
$somecontent .= "\n\nSET FOREIGN_KEY_CHECKS=0; \n"; //write "intro" ;)
//dump all tables:
for ($i = 0; $i < $broj; $i++) {
$table_name = $backup->tables[$i]; //get table name
if ($table_name != 'at_system_users') {
$backup->dump_table($table_name); //dump it to output (buffer)
$somecontent .= $backup->output; //write output
}
}
$somecontent .= "\n\nSET FOREIGN_KEY_CHECKS=1; \n\n"; //write "intro" ;)
//create the zip archive
$zip = new ZipArchive;
$zipfilename = "backup/" . $backupName;
$res = $zip->open($zipfilename, ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString(($backupName . '.sql'), $somecontent);
$zip->close();
echo '  <a href="' . $zipfilename . '"><button name="backup" type="button" class="btn btn-primary btn-lg"> Click Here to Download System Backup</button></a>';
} else {
echo 'Backup file creating failed due to some reason.<br/>Please contact developers for assistance.';
}
?>
<p> </p>
<p> </p>
</div>
</div>
</div>
</div>
</div>
<?php require_once './include/systemFooter.php'; ?>
</body>
</html>