backup-functions.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. trait BackupFunctions
  3. {
  4. public function fileArray($files)
  5. {
  6. foreach ($files as $file) {
  7. if (file_exists($file)) {
  8. $list[] = $file;
  9. }
  10. }
  11. if (!empty($list)) {
  12. return $list;
  13. }
  14. }
  15. public function backupDB($type = 'config')
  16. {
  17. $directory = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
  18. @mkdir($directory, 0770, true);
  19. switch ($type) {
  20. case 'config':
  21. break;
  22. case 'full':
  23. break;
  24. default:
  25. }
  26. $orgFiles = array(
  27. 'orgLog' => $this->organizrLog,
  28. 'loginLog' => $this->organizrLoginLog,
  29. 'config' => $this->userConfigPath,
  30. 'database' => $this->config['dbLocation'] . $this->config['dbName']
  31. );
  32. $files = $this->fileArray($orgFiles);
  33. if (!empty($files)) {
  34. $this->writeLog('success', 'BACKUP: backup process started', 'SYSTEM');
  35. $zipname = $directory . 'backup[' . date('Y-m-d_H-i') . '][' . $this->version . '].zip';
  36. $zip = new ZipArchive;
  37. $zip->open($zipname, ZipArchive::CREATE);
  38. foreach ($files as $file) {
  39. $zip->addFile($file);
  40. }
  41. $zip->close();
  42. $this->writeLog('success', 'BACKUP: backup process finished', 'SYSTEM');
  43. return true;
  44. } else {
  45. return false;
  46. }
  47. }
  48. public function getBackups()
  49. {
  50. $path = $this->config['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
  51. @mkdir($path, 0770, true);
  52. $files = array_diff(scandir($path), array('.', '..'));
  53. return array_reverse($files);
  54. }
  55. }