backup-functions.php 1.3 KB

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