Mercurial > hg > syntilista
annotate slbackup.php @ 142:36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
and a PHP script on the remote server. Needs more work, testing and better
error handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 Aug 2017 15:44:33 +0300 |
parents | |
children | 3b904b49ce57 |
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; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 // Helper functions |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 function stError($msg) |
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 global $errorSet, $errorMsg; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 $errorSet = TRUE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 $errorMsg = $msg; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 } |
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 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 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
|
37 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 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
|
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 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 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
|
43 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 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
|
45 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 $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
|
47 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
|
48 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 $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
|
50 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
|
51 unlink($dstFilename); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 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
|
54 return FALSE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 return TRUE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
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 // 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
|
63 // |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 $errorMsg = ""; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 $errorSet = FALSE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 $index = "file"; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 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
|
69 $dataSecret == "" || $dataPath == "") |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 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
|
72 exit; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 // 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
|
76 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
|
77 ($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
|
78 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 $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
|
80 $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
|
81 $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
|
82 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 switch ($fileError) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 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
|
86 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
|
87 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 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
|
90 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
|
91 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 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
|
94 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
|
95 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 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
|
98 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
|
99 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 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
|
102 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
|
103 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 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
|
106 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 default: |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 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
|
110 break; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 } |
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 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
|
114 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 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
|
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) |
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 $path = $dataPath."/".$dataName; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 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
|
122 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 $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
|
124 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
|
125 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 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
|
127 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 if ($errorSet) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 echo $errorMsg; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 } |
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 else |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 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
|
140 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
|
141 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 ?> |