Advertisement
secondcoming

Exile Cleanup

Feb 22nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2.  
  3.     // Set the protection period
  4.     $ProtectionPeriod = 7;
  5.    
  6.     echo "================================\nDatabase Cleanup Started:\n================================\n";
  7.  
  8.     include 'database.php';
  9.  
  10.     // Do db backup
  11.     // -------------------------------------------------------   
  12.  
  13.      
  14.     // if mysqldump is on the system path you do not need to specify the full path
  15.     // simply use "mysqldump --add-drop-table ..." in this case
  16.     $date = date("Y-m-d_H-i-s");
  17.     $dumpfname = 'C:\\xampp\\htdocs\\db\\'.$dbname.'_'.$date.'.sql';
  18.     echo "<hr>$dumpfname<hr>";
  19.     $command = "C:\\xampp\\mysql\\bin\\mysqldump --add-drop-table --host=$dbhost --user=$dbuser --password=$dbpass  exile0940 > $dumpfname";
  20.     system($command);
  21.    
  22.     echo "backup $dumpfname made\n\n";
  23.    
  24.    
  25.     // delete dead players
  26.     $sql = "DELETE FROM player WHERE damage = 1";
  27.     $result = mysqli_query($db_local, $sql);
  28.    
  29.     // delete push bikes
  30.     $sql = "DELETE FROM vehicle WHERE class = 'Exile_Bike_OldBike' OR class = 'Exile_Bike_MountainBike'";
  31.     $result = mysqli_query($db_local, $sql);
  32.    
  33.     // Remove empty containers not used in 48 hours
  34.     $sql = "DELETE FROM container WHERE last_updated_at <= NOW() - INTERVAL 48 HOUR AND cargo_items = '[[],[]]' AND cargo_magazines = '[]' AND cargo_weapons = '[]' AND cargo_container = '[]'";
  35.     $result = mysqli_query($db_local, $sql);
  36.  
  37.     // Remove containers not used in 48 hours not in a territory
  38.     $sql = "DELETE FROM container WHERE last_updated_at <= NOW() - INTERVAL 48 HOUR AND territory_id IS NULL";
  39.     $result = mysqli_query($db_local, $sql);
  40.  
  41.     // Remove old player history
  42.     $sql = "DELETE FROM player_history WHERE died_at <= NOW() - INTERVAL 24 HOUR";
  43.     $result = mysqli_query($db_local, $sql);
  44.  
  45.     // Remove old players
  46.     $sql = "DELETE FROM player WHERE last_updated_at < NOW() - INTERVAL 14 DAY";
  47.     $result = mysqli_query($db_local, $sql);   
  48.  
  49.    
  50.     // Remove constructions outside a territory and older than 48 hours
  51.     $sql = "DELETE FROM construction WHERE territory_id IS NULL AND last_updated_at < NOW() - INTERVAL 2 DAY";
  52.     $result = mysqli_query($db_local, $sql);   
  53.    
  54.     // Delete Abandoned Vehicles
  55.     include 'delete_abandoned_vehicles.php';   
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement