Mercurial > hg > syntilista
annotate slbackup.php @ 143:3b904b49ce57
Check for missing configuration file for slbackup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 Aug 2017 16:31:19 +0300 |
parents | 36c9cb759326 |
children | d2905ee5ff9c |
rev | line source |
---|---|
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 <?php |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // Syntilista - debt list/management database |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // SQLite3 database backup backend PHP blurb |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // Programmed and designed by Matti Hämäläinen <ccr@tnsp.org> |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // (C) Copyright 2017 Tecnic Software productions (TNSP) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 // Distributed under 3-clause BSD style license, refer to |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 // included file "COPYING" for exact terms. |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 // Settings, etc. |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 $dataName = "backup"; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 $dataSuffix = ".sqlite3"; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 $dataMaxSize = 1024 * 1024; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 $dataBackups = 24; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 $configFile = "slbackup.cfg"; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 if (file_exists($configFile)) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 require_once $configFile; |
143
3b904b49ce57
Check for missing configuration file for slbackup.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
23 else |
3b904b49ce57
Check for missing configuration file for slbackup.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
24 { |
3b904b49ce57
Check for missing configuration file for slbackup.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
25 error_log("SyntilistaBackup: Configuration file '".$configFile."' does not exist!"); |
3b904b49ce57
Check for missing configuration file for slbackup.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
26 exit; |
3b904b49ce57
Check for missing configuration file for slbackup.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
27 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 // Helper functions |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 function stError($msg) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 global $errorSet, $errorMsg; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 $errorSet = TRUE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 $errorMsg = $msg; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 function stGetBackupFilenameFilename($base, $suffix, $num) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 return sprintf("%s%02d%s", $base, $num, $suffix); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 function stRotateBackups($base, $suffix, $num) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 for ($i = $num; $i > 0; $i--) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 $srcFilename = stGetBackupFilenameFilename($base, $suffix, $i - 1); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 if (file_exists($srcFilename)) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 $dstFilename = stGetBackupFilenameFilename($base, $suffix, $i); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 if (file_exists($dstFilename)) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 unlink($dstFilename); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 if (@rename($srcFilename, $dstFilename) === FALSE) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 return FALSE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 return TRUE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 // Actual main code begins here |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 $errorMsg = ""; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 $errorSet = FALSE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 $index = "file"; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 if (!isset($dataSecret) || !isset($dataPath) || |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 $dataSecret == "" || $dataPath == "") |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 error_log("SyntilistaBackup: Invalid configuration."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 exit; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 // Basic check for credentials .. |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 if (isset($_REQUEST["secret"]) && isset($_FILES[$index]) && |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 ($secret = $_REQUEST["secret"]) == $dataSecret) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 $fileName = $_FILES[$index]["tmp_name"]; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 $fileSize = $_FILES[$index]["size"]; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 $fileError = $_FILES[$index]["error"]; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 switch ($fileError) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 case UPLOAD_ERR_INI_SIZE: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 stError("File size exceeds PHP's max upload size."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 case UPLOAD_ERR_PARTIAL: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 stError("File only partially uploaded."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 case UPLOAD_ERR_NO_FILE: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 stError("No file data received!"); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 case UPLOAD_ERR_NO_TMP_DIR: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 stError("Internal error: Temporary file directory not available!"); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 case UPLOAD_ERR_CANT_WRITE: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 stError("Internal error: PHP could not write the file to disk."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 case UPLOAD_ERR_OK: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 default: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 stError("Unknown PHP file error occured."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 if (!$errorSet && $fileSize > $dataMaxSize) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 stError("File is too large (".$fileSize." > ".$dataMaxSize." bytes)."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 if (!$errorSet) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 $path = $dataPath."/".$dataName; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 stRotateBackups($path, $dataSuffix, $dataBackups); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 $dstFilename = stGetBackupFilenameFilename($path, $dataSuffix, 1); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 if (@move_uploaded_file($fileName, $dstFilename) === false) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 stError("Could not move the uploaded file to proper directory."); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 if ($errorSet) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 header("Status: 500 Internal error"); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 header("Content-Type: text/plain"); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 echo $errorMsg; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 else |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 header("Status: 403 Forbidden"); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 header("Content-Type: text/plain"); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 ?> |