Minecraft Backup Script

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
Samuel98
Posts: 46
Joined: Wed Oct 05, 2011 1:20 am
Location: United Kingdom
Contact:

Minecraft Backup Script

Post by Samuel98 »

Jacekk,

Can you show me your public servers backup script please.

Thanks,
SamzRulez(Sam) :D
Image

Samuel Carr
Server Developer
W: http://epiccrafts.co.uk
E: [url]mailto://samuel.carr@epiccrafts.co.uk[/url]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft Backup Script

Post by jacek »

Yes :)

[syntax=php] // backs up all worlds.
public function worlds(){
if (!$this->server->is_running() || !$this->server->plugin->ready){
return false;
}

$start = microtime(true);

$this->server->save_off();
$this->server->save_all(true);

$worlds = $this->server->plugin->get_worlds();

foreach ($worlds as $world => $folder){
shell_exec('cp -R ' . escapeshellarg($folder) . ' ' . escapeshellarg("{$GLOBALS['core_path']}/data/backups/worlds"));
}

$this->server->save_on();

$old_cwd = getcwd();

chdir("{$GLOBALS['core_path']}/data/backups/worlds/");

foreach ($worlds as $world => $folder){
shell_exec('tar -czf ' . escapeshellarg("{$world}_" . time() . ".tar.gz") . ' ' . escapeshellarg($folder));
shell_exec('rm -Rf ' . escapeshellarg($folder));
}

chdir($old_cwd);

$time_taken = round(microtime(true) - $start, 3);

$this->server->say('Backup completed in ' . $time_taken . ' seconds');

return $time_taken;
}[/syntax]
This is the method that does the world backup, there is also

[syntax=php] // removes any backups that are older than the configured time.
public function cleanup(){
$files = scandir("{$GLOBALS['core_path']}/data/backups/worlds");
unset($files[0], $files[1]);

foreach ($files as $file){
$full_path = "{$GLOBALS['core_path']}/data/backups/worlds/{$file}";

if (filectime($full_path) < (time() - ($GLOBALS['config']['backups']['max_map_backup_age'] * 3600))){
unlink($full_path);
}
}
}[/syntax]
which runs every hour or so to remove any old backups.

And finally

[syntax=php] // backs up the server set up.
public function server(){

}[/syntax]
Which I still need to make ;)
Image
User avatar
Samuel98
Posts: 46
Joined: Wed Oct 05, 2011 1:20 am
Location: United Kingdom
Contact:

Re: Minecraft Backup Script

Post by Samuel98 »

Content Deleted
Last edited by Samuel98 on Sun Mar 22, 2015 9:34 pm, edited 1 time in total.
Image

Samuel Carr
Server Developer
W: http://epiccrafts.co.uk
E: [url]mailto://samuel.carr@epiccrafts.co.uk[/url]
User avatar
Samuel98
Posts: 46
Joined: Wed Oct 05, 2011 1:20 am
Location: United Kingdom
Contact:

Re: Minecraft Backup Script

Post by Samuel98 »

Content Deleted
Last edited by Samuel98 on Sun Mar 22, 2015 9:34 pm, edited 1 time in total.
Image

Samuel Carr
Server Developer
W: http://epiccrafts.co.uk
E: [url]mailto://samuel.carr@epiccrafts.co.uk[/url]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft Backup Script

Post by jacek »

SamzRulez wrote:wow thats confusing.

There are simpler ones around... http://www.google.co.uk/search?hl=en&q= ... kup+scirpt
Image
User avatar
Samuel98
Posts: 46
Joined: Wed Oct 05, 2011 1:20 am
Location: United Kingdom
Contact:

Re: Minecraft Backup Script

Post by Samuel98 »

Content Deleted
Last edited by Samuel98 on Sun Mar 22, 2015 9:34 pm, edited 1 time in total.
Image

Samuel Carr
Server Developer
W: http://epiccrafts.co.uk
E: [url]mailto://samuel.carr@epiccrafts.co.uk[/url]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft Backup Script

Post by jacek »

SamzRulez wrote:You spelt it wrong lol. :P

We don't need to know how to spell any more thanks to spell-check and google ;)
Image
Post Reply