Page 1 of 1

Minecraft Backup Script

Posted: Sun Dec 11, 2011 12:53 pm
by Samuel98
Jacekk,

Can you show me your public servers backup script please.

Thanks,
SamzRulez(Sam) :D

Re: Minecraft Backup Script

Posted: Sun Dec 11, 2011 1:36 pm
by jacek
Yes :)
	// 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;
	}
This is the method that does the world backup, there is also
	// 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);
			}
		}
	}
which runs every hour or so to remove any old backups.

And finally
	// backs up the server set up.
	public function server(){
		
	}
Which I still need to make ;)

Re: Minecraft Backup Script

Posted: Sun Dec 11, 2011 1:54 pm
by Samuel98
Content Deleted

Re: Minecraft Backup Script

Posted: Sun Dec 11, 2011 1:56 pm
by Samuel98
Content Deleted

Re: Minecraft Backup Script

Posted: Sun Dec 11, 2011 2:08 pm
by jacek
SamzRulez wrote:wow thats confusing.
There are simpler ones around... http://www.google.co.uk/search?hl=en&q= ... kup+scirpt

Re: Minecraft Backup Script

Posted: Mon Dec 12, 2011 6:18 pm
by Samuel98
Content Deleted

Re: Minecraft Backup Script

Posted: Mon Dec 12, 2011 9:20 pm
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 ;)