Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2. backup('notecms', 'root');
  3. function backup($name, $user, $pass = NULL) {
  4. $filename='/note_db_backup_'.date('G_a_m_d_y').'.sql';
  5. if ($pass == NULL) {
  6. $result=exec('mysqldump notecms --single-transaction --user='. $user .' -r '. $filename . ' 2>&1', $output, $return_var);
  7. }
  8. else {
  9. $result=exec('mysqldump notecms --single-transaction --user='. $user .' -p='. $pass .' -r '. $filename . ' 2>&1', $output, $return_var);
  10. }
  11. if($return_var == 0){
  12. //return 0;
  13. if (!chmod($filename, 0600)) {
  14. die('could not change backup permissions');
  15. }
  16. deleteold();
  17. }
  18. else {
  19. print_r($output);
  20. global $backup_output;
  21. $backup_output = $output;
  22. //return 1;
  23. }
  24. }
  25.  
  26. function deleteold() {
  27. $filecount = count(scandir("../backup/")) - 2;
  28. if ($filecount > 5) {
  29. $files = glob( '../backup/*' );
  30. array_multisort(
  31. array_map( 'filemtime', $files ),
  32. SORT_NUMERIC,
  33. SORT_ASC,
  34. $files
  35. );
  36. unlink($files[0]);
  37. }
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement