1 | <?php
|
---|
2 |
|
---|
3 | include_once(dirname(__FILE__).'/../../Base/Model.php');
|
---|
4 |
|
---|
5 | class Backup extends Model
|
---|
6 | {
|
---|
7 | var $Id;
|
---|
8 | var $Task;
|
---|
9 |
|
---|
10 | function __construct($System, $Id)
|
---|
11 | {
|
---|
12 | parent::__construct($System);
|
---|
13 | $this->Task = new Task($System);
|
---|
14 | $this->Id = $Id;
|
---|
15 | $DbResult = $this->Database->query('SELECT * FROM `Backup` WHERE `Id`='.$Id);
|
---|
16 | if($DbResult->num_rows > 0) $this->Backup = $DbResult->fetch_assoc();
|
---|
17 | else $this->Backup = array();
|
---|
18 | }
|
---|
19 |
|
---|
20 | function Restore()
|
---|
21 | {
|
---|
22 | $ServerId = $this->Backup['Server'];
|
---|
23 | $this->Task->Add('Obnovení databáze', array(
|
---|
24 | 'php www/shell.php ServerLock '.$ServerId,
|
---|
25 | 'mysql --silent --skip-column-names -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_mangos -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_mangos',
|
---|
26 | 'mysql --silent --skip-column-names -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_characters -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_characters',
|
---|
27 | 'mysql --silent --skip-column-names -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_realmd -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_realmd',
|
---|
28 | 'mysql --silent --skip-column-names -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_scriptdev2 -e "show tables" | gawk \'{print "drop table " $1 ";"}\' | mysql -u server'.$ServerId.' -pserver'.$ServerId.' server'.$ServerId.'_scriptdev2',
|
---|
29 | 'mkdir temp/wowhosting',
|
---|
30 | 'tar -xjf backup/wowhosting-'.$this->Id.'.tar.bz2 -C temp',
|
---|
31 | 'mysql --user=server'.$ServerId.' --password=server'.$ServerId.' server'.$ServerId.'_characters < temp/wowhosting/characters.sql',
|
---|
32 | 'mysql --user=server'.$ServerId.' --password=server'.$ServerId.' server'.$ServerId.'_realmd < temp/wowhosting/realmd.sql',
|
---|
33 | 'mysql --user=server'.$ServerId.' --password=server'.$ServerId.' server'.$ServerId.'_mangos < temp/wowhosting/mangos.sql',
|
---|
34 | 'mysql --user=server'.$ServerId.' --password=server'.$ServerId.' server'.$ServerId.'_scriptdev2 < temp/wowhosting/scriptdev2.sql',
|
---|
35 | 'rm -rf temp/wowhosting',
|
---|
36 | 'php www/shell.php ServerDatabaseChange '.$ServerId.' '.$this->Backup['Database'],
|
---|
37 | 'php www/shell.php ServerUnLock '.$ServerId,
|
---|
38 | ));
|
---|
39 | return('Úloha obnovení databáze ze zálohy zařazena do fronty.');
|
---|
40 | }
|
---|
41 |
|
---|
42 | function Create($ServerId)
|
---|
43 | {
|
---|
44 | $Server = new Server($this->System, $ServerId);
|
---|
45 | $Description = 'MaNGOS r'.$Server->Server['Database']['Emulator']['Revision'].', UDB r'.$Server->Server['Database']['Revision'].', SD2 r'.$Server->Server['Database']['ScriptDev2Revision'].', Client '.$Server->Server['Database']['Emulator']['Client']['Version'];
|
---|
46 | $this->Database->insert('Backup', array('Server' => $ServerId, 'Time' => 'NOW()', 'Description' => $Description, 'Lock' => 1, 'Database' => $Server->Server['Database']['Id']));
|
---|
47 | $this->Id = $this->Database->insert_id;
|
---|
48 | $this->Task->Add('Záloha databáze serveru', array(
|
---|
49 | 'php www/shell.php ServerLock '.$ServerId,
|
---|
50 | 'mkdir temp/wowhosting',
|
---|
51 | 'mysqldump --user=server'.$ServerId.' --password=server'.$ServerId.' --opt server'.$ServerId.'_characters > temp/wowhosting/characters.sql',
|
---|
52 | 'mysqldump --user=server'.$ServerId.' --password=server'.$ServerId.' --opt server'.$ServerId.'_realmd > temp/wowhosting/realmd.sql',
|
---|
53 | 'mysqldump --user=server'.$ServerId.' --password=server'.$ServerId.' --opt server'.$ServerId.'_mangos > temp/wowhosting/mangos.sql',
|
---|
54 | 'mysqldump --user=server'.$ServerId.' --password=server'.$ServerId.' --opt server'.$ServerId.'_scriptdev2 > temp/wowhosting/scriptdev2.sql',
|
---|
55 | 'cd temp',
|
---|
56 | 'tar -c -j wowhosting > ../backup/wowhosting-'.$this->Id.'.tar.bz2',
|
---|
57 | 'rm -rf wowhosting',
|
---|
58 | 'cd ..',
|
---|
59 | 'php www/shell.php BackupUnLock '.$this->Id,
|
---|
60 | 'php www/shell.php ServerUnLock '.$ServerId,
|
---|
61 | ));
|
---|
62 | return('Úloha zálohování byla zařazena do fronty.');
|
---|
63 | }
|
---|
64 |
|
---|
65 | function Lock()
|
---|
66 | {
|
---|
67 | $this->Database->update('Backup', 'Id='.$this->Id, array('Lock' => 1));
|
---|
68 | }
|
---|
69 |
|
---|
70 | function UnLock()
|
---|
71 | {
|
---|
72 | $this->Database->update('Backup', 'Id='.$this->Id, array('Lock' => 0));
|
---|
73 | }
|
---|
74 | }
|
---|