88 $requiredFolders = array($this->tmpFolder, $this->currentBackupFolder, $this->archiveBackupFolder);
90 foreach ($requiredFolders as
$folder)
97 \YAWK\sys::setSyslog(
$db, 52, 2,
"failed to create " .
$folder .
"", 0, 0, 0, 0);
108 \YAWK\sys::setSyslog(
$db, 52, 2,
"failed to set permissions of folder " .
$folder .
"", 0, 0, 0, 0);
124 if ($this->
run(
$db) ===
true)
142 if (isset($this->backupMethod) && (!empty($this->backupMethod)))
144 switch ($this->backupMethod)
149 $this->storeSqlTmp =
"true";
176 $this->storeSqlTmp =
"false";
207 $this->storeSqlTmp =
"true";
210 if (isset($_POST[
'database']) && (!empty($_POST[
'database'])))
259 if (is_writeable($this->targetFolder))
261 $this->configFile = $this->targetFolder.$this->configFilename;
263 if (isset($this->storeSqlTmp) && ($this->storeSqlTmp ==
"true"))
265 if (!is_dir($this->tmpFolder.
"database"))
267 mkdir($this->tmpFolder.
"database");
276 if (is_file($this->configFile))
282 \YAWK\sys::setSyslog(
$db, 51, 1,
"backup ini file written, but not found - please check: $this->configFile", 0, 0, 0, 0);
288 \YAWK\sys::setSyslog(
$db, 52, 2,
"failed to write backup config file $this->configFile", 0, 0, 0, 0);
294 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to write backup config file: $this->configFile - target folder not writeable", 0, 0, 0, 0);
307 $this->configFile = $iniFile;
309 if (is_file($this->configFile))
312 $this->backupSettings = parse_ini_file($this->configFile);
314 if (is_array($this->backupSettings))
320 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to parse ini file: $this->configFile is there, but backupSettings array is not set", 0, 0, 0, 0);
327 \YAWK\sys::setSyslog(
$db, 51, 1,
"failed to parse ini file: $this->configFile not found", 0, 0, 0, 0);
341 if (is_array($this->currentBackupFiles))
381 require_once
'backup-mysqlBackup.php';
383 $this->mysqlBackup = new \YAWK\BACKUP\DATABASE\mysqlBackup($this->backupSettings);
386 if ($this->mysqlBackup->initMysqlBackup(
$db, $this->overwriteBackup, $this->zipBackup, $this->storeSqlTmp) ===
true)
404 require_once
'backup-fileBackup.php';
406 $this->fileBackup = new \YAWK\BACKUP\FILES\fileBackup(
$db);
409 if ($this->fileBackup->initFolderBackup(
$db, $this->overwriteBackup, $this->zipBackup) ===
true)
427 if (extension_loaded(
'zip'))
450 if (!file_exists($source))
456 $zip = new \ZipArchive();
459 if (!$zip->open($destination, \ZIPARCHIVE::CREATE))
465 $source = str_replace(
'\\',
'/', realpath($source));
468 if (is_dir($source) ===
true)
471 $elements = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
474 foreach ($elements as $file)
477 $file = str_replace(
'\\',
'/', $file);
480 if( in_array(substr($file, strrpos($file,
'/')+1), array(
'.',
'..')) )
484 $file = realpath($file);
487 if (is_dir($file) ===
true)
489 $zip->addEmptyDir(str_replace($source .
'/',
'', $file .
'/'));
492 else if (is_file($file) ===
true)
494 $zip->addFromString(str_replace($source .
'/',
'', $file), file_get_contents($file));
499 else if (is_file($source) ===
true)
501 $zip->addFromString(basename($source), file_get_contents($source));
508 if (is_file($destination))
518 if (isset(
$_GET[
'archiveID']) && (!empty(
$_GET[
'archiveID'])))
520 $downloadArchiveLink =
"#archive-".$_GET[
'archiveID'];
522 $downloadFile = $this->downloadFolder.$_GET[
'folder'].
".zip";
526 <script type='text/javascript'>
527 $(document).ready(function()
528 { // change href attribute for this archive to direct donwload file
529 $('$downloadArchiveLink').attr('href', '$downloadFile')
530 // emulate a users click to force direct download
531 $('$downloadArchiveLink')[0].click();
532 // if this is not working, the user have to click on that link.
541 \YAWK\sys::setSyslog(
$db, 52, 3,
"failed to create download archive: $destination", 0, 0, 0, 0);
555 if (isset($file) && (!empty($file)
559 $this->restoreFile = $file;
560 $this->restoreFolder =
$folder;
563 if (is_writeable($this->tmpFolder))
565 $source = $this->restoreFolder.$this->restoreFile;
566 $target = $this->tmpFolder.$this->restoreFile;
569 copy($source, $target);
572 if (is_file($target))
576 $zip = new \ZipArchive;
578 $res = $zip->open($target);
582 $zip->extractTo($this->tmpFolder);
588 if (is_file($this->tmpFolder.$this->configFilename))
591 $this->backupSettings = $this->
parseIniFile(
$db, $this->tmpFolder.$this->configFilename);
594 if (is_array($this->backupSettings) && (!empty($this->backupSettings)))
597 switch ($this->backupSettings[
'METHOD'])
604 $this->restoreStatus = $this->
doRestore(
$db, $this->restoreFolders);
613 $this->restoreFolders = array(
'database');
614 $this->restoreStatus = $this->
doRestore(
$db, $this->restoreFolders);
624 $this->restoreFolders = array(
'media/');
625 $this->restoreStatus = $this->
doRestore(
$db, $this->restoreFolders);
635 $this->restoreStatus = $this->
doRestore(
$db, $this->restoreFolders);
647 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to restore backup: restore settings array is not set", 0, 0, 0, 0);
654 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to restore backup: ini file not found - $this->tmpFolder.$this->configFilename", 0, 0, 0, 0);
660 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to restore: unable to open ZIP file", 0, 0, 0, 0);
666 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to restore: unable to unzip backup package - ZIP extension not loaded.", 0, 0, 0, 0);
672 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to copy backup package: $source not copied to $target", 0, 0, 0, 0);
679 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to restore backup: tmp folder ($this->tmpFolder) is not writeable", 0, 0, 0, 0);
685 \YAWK\sys::setSyslog(
$db, 52, 1,
"failed to restore backup: file not set", 0, 0, 0, 0);
706 foreach ($this->restoreFolders as
$folder)
709 if (is_dir(dirname($this->tmpFolder.$folder)))
717 $this->restoreStatus[][
$folder][
'success'] =
"true";
722 $this->restoreStatus[][
$folder][
'success'] =
"false";
723 $this->restoreStatus[][
$folder][
'error'] =
"failed to copy " . $this->tmpFolder .
"$folder check permissions of ../$folder";
731 if (is_file($this->tmpFolder.
"database-backup.sql_error"))
733 unlink($this->tmpFolder.
"database-backup.sql_error");
736 if (is_file($this->tmpFolder.
"database-backup.sql_filepointer"))
738 unlink($this->tmpFolder.
"database-backup.sql_filepointer");
743 if (file_exists($this->tmpFolder.
"database-backup.sql"))
746 if (is_file($this->tmpFolder.$this->configFilename))
749 $this->backupSettings = $this->
parseIniFile(
$db, $this->tmpFolder.$this->configFilename);
751 $activeTables = explode(
',', $this->backupSettings[
'TABLES']);
753 array_pop($activeTables);
755 $db->dropTables($activeTables);
758 if (
$db->import($this->tmpFolder.
"database-backup.sql",
'') ===
true)
760 $this->restoreStatus[][
'database'][
'success'] =
"true";
765 $this->restoreStatus[][
'database'][
'success'] =
"true";
766 $this->restoreStatus[][
'database'][
'error'] =
"failed to restore database backup.";
771 else if (is_dir(dirname($this->tmpFolder.
"database/")))
774 if (is_file($this->tmpFolder.
"database/".$this->configFilename))
777 $this->backupSettings = $this->
parseIniFile(
$db, $this->tmpFolder.
"database/".$this->configFilename);
779 $activeTables = explode(
',', $this->backupSettings[
'TABLES']);
781 array_pop($activeTables);
783 $db->dropTables($activeTables);
787 if (file_exists($this->tmpFolder.
"database/database-backup.sql"))
789 if (
$db->import($this->tmpFolder.
"database/database-backup.sql",
'') ===
true)
791 $this->restoreStatus[][
'database'][
'success'] =
"true";
796 $this->restoreStatus[][
'database'][
'success'] =
"true";
797 $this->restoreStatus[][
'database'][
'error'] =
"failed to restore database backup.";
807 $this->restoreStatus[][
$folder][
'error'] =
"failed to restore ../$folder : folder is not there or not writeable";
842 $iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
$folder));
844 foreach($iterator as
$item)
864 if (!isset($filemode) || (empty($filemode)))
916 return substr(sprintf(
'%o', fileperms(
$folder)), -4);
if(!isset($language)||(!isset($lang))) $item
run($db)
Run a new backup, depending on chosen backup method.
doRestore($db, $restoreFolders)
Restore Data physically to folder, restore .sql file to database if needed.
checkFolders($restoreFolders)
check restore folders, check + set permissions of restore folders
runFileBackup($db)
Run File Backup from $sourceFolder.
setPermissions($folder, $filemode)
set folder permissions and do some chmod stuff to with given $filemode to $folder
checkPermissions($folder)
check folder permissions and return permissions as string (eg 0755)
__construct($db)
backup constructor. prepare temp folder on class instantiation
setIniFile(object $db)
Set backup information file (backup.ini)
getArchiveBackupFilesArray()
get all files from archive backup folder into array
runDatabaseBackup($db, $storeSqlTmp)
Include mysql backup class and run mysqldump backup.
init($db)
Init Backup Class (run backup)
checkZipFunction()
Check if ZipArchive function exists.
getCurrentBackupFilesArray()
get all files from current backup folder into array
parseIniFile($db, $iniFile)
Parse backup ini file.
zipFolder($db, $source, $destination)
Zip a whole folder from $source to $destination.zip.
restore($db, $file, $folder)
Manage how a backup will be restored from backup folder.
Mysqli database class; returns db connection object.
static getFilesFromFolderToArray($folder)
returns an array containing only files from folder (no subfolders)
static getSubfoldersToArray($folder)
returns an array containing only files from folder (no subfolders)
static xcopy($source, $dest, $permissions=0755)
Copy a file, or recursively copy a folder and its contents.
static recurseRmdir($dir)
remove a directory recurse
static writeIniFile($array, $file)
write ini file
This class serves methods to create backup from files.
$backup archiveBackupFiles