Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. <?php
  2.  
  3. // RM -rf if exist - for test onlu
  4.  
  5. rmdir('zabackupim-workdir');
  6. unlink('test.tar.gz');
  7. unlink('zabackupim.php');
  8.  
  9.  
  10. // Zabackupim setup script v0.1
  11.  
  12. // Start checks
  13.  
  14. // Check disk space
  15.  
  16. $dir = getcwd();
  17. $dt = disk_total_space($dir);
  18. $df = disk_free_space($dir);
  19. $pr = ($df/$dt)*100;
  20. $si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
  21. $base = 1024;
  22.  
  23.  
  24. if ($pr > 55) {
  25.     echo "Check disk space:&nbsp;<strong><span style=\"color:green;\">Test pass!</span></strong><br />";
  26. } else {
  27.     echo "Check disk space:&nbsp;<strong><span style=\"color:red;\">Test fail! It is not enough disk space to create a temporary backup!</span></strong>";
  28.     die('<strong><span style=\"color:red;\"><br />Kill all!</span></strong>');
  29. }
  30.  
  31. // Check create new dir
  32.  
  33. $structure = './test/';
  34.  
  35. if (!mkdir($structure, 0777, true)) {
  36.     echo "Check create new dir:&nbsp;<strong><span style=\"color:red;\">Test fail! Please correct permissions for the site root folder!</span></strong>";
  37.     die('<strong><span style=\"color:red;\"><br />Kill all!</span></strong>');
  38. } else {
  39.     echo "Check create new dir:&nbsp;<strong><span style=\"color:green;\">Test pass!</span></strong><br />";
  40. }
  41. rmdir('test');
  42.  
  43. // Check to create new tar.gz archive file
  44.  
  45. try
  46. {
  47.     $a = new PharData('test.tar');
  48.  
  49.     // ADD FILES TO archive.tar FILE
  50.     $a->addFile('tar.php');
  51.    
  52.     // COMPRESS archive.tar FILE. COMPRESSED FILE WILL BE archive.tar.gz
  53.     $a->compress(Phar::GZ);
  54.  
  55.     // NOTE THAT BOTH FILES WILL EXISTS. SO IF YOU WANT YOU CAN UNLINK archive.tar
  56.     unlink('test.tar');
  57.     echo "Check to create new tar.gz archive file:&nbsp;<strong><span style=\"color:green;\">Test pass!</span></strong><br />";
  58. }
  59. catch (Exception $e)
  60. {
  61.     echo "Check to create new tar.gz archive file:&nbsp;<strong><span style=\"color:red;\">Test fail!</span></strong><br />Exception : " . $e;
  62.     die('<strong><span style=\"color:red;\"><br />Kill all!</span></strong>');
  63.  
  64. }
  65.  
  66. // If all tests is OK, download primary management file and create work-dir
  67.  
  68. $file = 'http://cloudtelehouse.com/zabackupim.php';
  69. $newfile = 'zabackupim.php';
  70. if (!copy($file, $newfile)) {
  71.     echo "Download primary management file:&nbsp;<strong><span style=\"color:red;\">Fail!</span></strong>";
  72.     die('<strong><span style=\"color:red;\"><br />Kill all!</span></strong>');
  73. } else {
  74.     echo "Download primary management file:&nbsp;<strong><span style=\"color:green;\">Pass!</span></strong><br />";
  75. }
  76.  
  77. $structure = './zabackupim-workdir/';
  78.  
  79. if (!mkdir($structure, 0777, true)) {
  80.     echo "Create work-dir:&nbsp;<strong><span style=\"color:red;\">Fail! Please correct permissions for the site root folder!</span></strong>";
  81.     die('<strong><span style=\"color:red;\"><br />Kill all!</span></strong>');
  82. } else {
  83.     echo "Create work-dir:&nbsp;<strong><span style=\"color:green;\">Pass!</span></strong><br />";
  84. }
  85.  
  86. // Finish!!!
  87.  
  88. echo "<strong><span style=\"color:green;\">All tests run successfully, the working environment was created successfully!</span></strong><br />";
  89. echo "<strong><span style=\"color:red;\">Please delete the file zb-setup.php manually! If this is not possible problems in the backup service!</span></strong><br />";
  90. echo "Please go to the <a href=\"http://".$_SERVER['SERVER_NAME']."/zabackupim.php\" target=\"_blank\">Control panel</a> and follow the instructions!<br />";
  91.  
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement