backuptest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. $_SERVER = array();
  3. $_SERVER['SERVER_NAME'] = 'gershwinklata1.avatarclassroom.com';
  4. define('CLI_SCRIPT', 1);
  5. require_once('config.php');
  6. require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  7. $backup_types = array(
  8. 'course' => backup::TYPE_1COURSE,
  9. 'activity' => backup::TYPE_1ACTIVITY
  10. );
  11. if (count($argv) < 3) {
  12. print "Usage: ".$argv[0]." <user> <type> <course_or_activity_id> [<file_to_show_afterwards>]\n";
  13. exit;
  14. }
  15. $user_doing_the_backup = intval($argv[1]); //2; // Set this to the id of your admin accouun
  16. $backup_type_arg = $argv[2];
  17. if (!isset($backup_types[$backup_type_arg])) {
  18. print "Backup type $backup_type_arg not supported.\n";
  19. exit;
  20. }
  21. $backup_type = $backup_types[$backup_type_arg];
  22. //$course_module_to_backup = 2; // Set this to one existing choice cmid in your dev site
  23. $course_module_to_backup = intval($argv[3]); //27; //3; // Set this to one existing choice cmid in your dev site
  24. if (!$course_module_to_backup || !$user_doing_the_backup) {
  25. print "Parameters wrong\n";
  26. exit;
  27. }
  28. $bc = new backup_controller($backup_type, $course_module_to_backup, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $user_doing_the_backup);
  29. //$bc = new backup_controller(backup::TYPE_1COURSE, $course_module_to_backup, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $user_doing_the_backup);
  30. $bc->execute_plan();
  31. $backupdir = '../resources/moodledata/temp/backup';
  32. $folder = null;
  33. $highestmtime = 0;
  34. foreach (glob($backupdir.'/*') as $f) {
  35. if (!is_dir($f)) {
  36. continue;
  37. }
  38. if ( !$folder || (filemtime($f) > $highestmtime) ) {
  39. $folder = $f;
  40. $highestmtime = filemtime($f);
  41. }
  42. }
  43. //$folderbits = explode('/',$folder);
  44. //$folder = array_pop($folderbits);
  45. print "\n\n";
  46. print "Most recent backup folder, probably the one I created: \n";
  47. print "$folder\n";
  48. if (isset($argv[4])) {
  49. if ($cmd = $argv[4]) {
  50. echo `cat $folder/$argv[4]`;
  51. }
  52. }