Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Multicraft - Backup Using API

ryanpetris May 10th, 2015 268 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. require('MulticraftAPI.php');
  3.  
  4. $api = new MulticraftAPI('http://<your multicraft url>/api.php', '<your username>', '<your api key>');
  5.  
  6. function getData($result) {
  7.     if (!$result['success']) {
  8.         die($result['errors'][0]);
  9.     }
  10.  
  11.     return $result['data'];
  12. }
  13.  
  14.  
  15. $date = date('YmdHis');
  16.  
  17. exec('mkdir /tmp/minecraft-backups-' . $date);
  18.  
  19. $servers = getData($api->listServers());
  20.  
  21. foreach ($servers['Servers'] as $server_id => $server_name) {
  22.     print("Backing up server " . $server_name . " (id " . $server_id . ")\n");
  23.     print("    Disabling automatic saving...\n");
  24.  
  25.     $api->sendConsoleCommand($server_id, 'save-on');
  26.     $api->sendConsoleCommand($server_id, 'save-all');
  27.     $api->sendConsoleCommand($server_id, 'save-off');
  28.  
  29.     sleep(10);
  30.  
  31.     print("    Compressing server directory...\n");
  32.  
  33.     exec('mkdir /tmp/minecraft-backups-' . $date . '/' . $server_name);
  34.     exec('tar czf /tmp/minecraft-backups-' . $date . '/' . $server_name . '/' . $date . '.tar.gz /<your multicraft path>/servers/server' . $server_id . '/* 2>/dev/null');
  35.  
  36.     print("    Enabling automatic saving...\n");
  37.  
  38.     $api->sendConsoleCommand($server_id, 'save-on');
  39. }
  40.  
  41. print("Sending backups to backup server...\n");
  42.  
  43. exec('RSYNC_PASSWORD="<your rsync password>" rsync -rt /tmp/minecraft-backups-' . $date . '/* rsync://<your rsync url>/');
  44. exec('rm -rf /tmp/minecraft-backups-' . $date);
  45.  
  46. print("Backup complete.\n");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top