1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cornford\Backup\Engines; |
4
|
|
|
|
5
|
|
|
class BackupEngineSqlite extends BackupEngineAbstract |
6
|
|
|
{ |
7
|
|
|
private const ENGINE_NAME = 'sqlite'; |
8
|
|
|
private const ENGINE_EXTENSION = 'sqlite'; |
9
|
|
|
private const ENGINE_EXPORT_PROCESS = 'cp'; |
10
|
|
|
private const ENGINE_RESTORE_PROCESS = 'cp'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Get export process. |
14
|
|
|
* |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
public function getExportProcess() |
18
|
|
|
{ |
19
|
|
|
return self::ENGINE_EXPORT_PROCESS; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get restore process. |
24
|
|
|
* |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
|
|
public function getRestoreProcess() |
28
|
|
|
{ |
29
|
|
|
return self::ENGINE_RESTORE_PROCESS; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get database file extension. |
34
|
|
|
* |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
public function getFileExtension() |
38
|
|
|
{ |
39
|
|
|
return self::ENGINE_EXTENSION; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Export the database to a file path. |
44
|
|
|
* |
45
|
|
|
* @param string $filepath |
46
|
|
|
* |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
public function export($filepath) |
50
|
|
|
{ |
51
|
|
|
$command = sprintf( |
52
|
|
|
'%s %s %s', |
53
|
|
|
$this->getExportCommand(), |
54
|
|
|
escapeshellarg($this->getDatabase()), |
55
|
|
|
escapeshellarg($filepath) |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
return $this->getBackupProcess()->run($command, __FUNCTION__); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Restore the database from a file path. |
63
|
|
|
* |
64
|
|
|
* @param string $filepath |
65
|
|
|
* |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public function restore($filepath) |
69
|
|
|
{ |
70
|
|
|
$command = sprintf( |
71
|
|
|
'%s -f %s %s', |
72
|
|
|
$this->getRestoreCommand(), |
73
|
|
|
escapeshellarg($filepath), |
74
|
|
|
escapeshellarg($this->getDatabase()) |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
return $this->getBackupProcess()->run($command, __FUNCTION__); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|