Look at this code: PHP: <?php/*__PocketMine Plugin__author=PEMapModdername=GitBackupdescription=Needs Git be installed in the computerapiversion=10,11,12version=ALPHAclass=BackupGitPlugin*///Alpha_1.3.10 or above for LevelAPI::getAll()class BackupGitPlugin implements Plugin{ public $datcfg, $dat; public function __construct(ServerAPI $api, $s=0){} public function __destruct(){ $this->datcfg->setAll($this->dat); } public function init(){ $a=ServerAPI::request()->api; $p=$a->plugin; $c=$a->console; $path=$p->configPath($this)."memory"; if(file_exists($path)){ $this->datcfg=new Config($path, CONFIG_YAML); $this->dat=$this->datcfg->getAll(); } else{ $this->dat=array( "inited"=>false, "remotes"=>array() ); $this->datcfg=new Config($path, CONFIG_YAML, $this->dat); } $c->register("git", "<subcmd> [args] Git backup (console only)", array($this, "cmd")); if(!$this->dat["inited"]===false) exec("git init"); @mkdir(FILE_PATH."git_worlds/"); } public function cmd($c, $a, $i){ if($i!=="console") return "Please run this command on-console."; switch(strtolower($a[0])){ case "remote": if($a===array("remote")){ $ret="Remote list:\n"; foreach($this->dat["remotes"] as $name=>$link){ $ret.=" $name: $link"; } return $ret; } if(count($a)!==3) return "Usage: /git remote <name> <HTTP/SSH>"; $this->dat["remotes"][$a[1]]=$a[2]; break; case "addworlds": console("[NOTICE] Creating worlds backup..."); foreach(ServerAPI::request()->api->level->getAll() as $level){ $out=FILE_PATH."git_worlds/".$level->getName()."/"; $in=FILE_PATH."worlds/".$level->getName()."/"; $inDir=dir($in); @unlink($out); @mkdir($out); while(false!==($filename=$inDir->read())){ if(is_file($in.$filename)){ file_put_contents($out.$filename, file_get_contents($in.$filename)); } } $inDir->close(); $out.="chunks/"; $in.="chunks/"; $inDir=dir($in); while(false!==($filename=$inDir->read())){ if(is_file($in.$filename)){ file_put_contents($out.$filename, file_get_contents($in.$filename)); } } console(FORMAT_GREEN."[DEBUG] Copied level ".$level->getName()); } console("[NOTICE] Finished creating world backup"); $msg=""; exec("git add git_worlds/*", $msg); console($msg); exec("git commit -m \"".(isset($a[1]) and $a[1]!=""?$a[1]:"world adding")."\"", $msg); console($msg); break; case "addplugins": $this->duplicateFolder("plugins/"); case "push": if(count($a!=2)) return "Usage: /git push <remote name>"; if(!isset($this->dat["remotes"][$a[1]])) return "Remote ".$a[1]." not found"; $path=$p->configPath($this)."temp"; file_put_contents($path, ""); $subpath=trim($path, FILE_PATH); exec("git push -u \"".$this->dat["remotes"][$a[1]]."\" master > /$subpath &"); return "Pushing worlds. Result at $path."; default: return "Command /git ".$a[0]."doesn't exist."; } } public function duplicateFolder($inSubpath){ $inSubpath=trim($inSubpath, FILE_PATH); if(substr($inSubpath, -1)!=="/")$inSubpath.="/"; $out=FILE_PATH."git_".$inSubpath; if(!is_dir($inSubpath)) return false; $inDir=dir(FILE_PATH.$inSubpath); while(false!==($filename=$inDir->read())){ if(is_file($in.$filename)) file_put_contents($out.$filename, file_get_contents($in.$filename)); elseif(strpos($filename, ".")===false){ $this->duplicateFolder($in.$filename); } } $inDir->close(); return true; }} There are no crashes, but the code does not seem to be working...
Code: <?php /* __PocketMine Plugin__ author=PEMapModder name=GitBackup description=Needs Git be installed in the computer apiversion=10,11,12 version=ALPHA class=BackupGitPlugin */ //Alpha_1.3.10 or above for LevelAPI::getAll() class BackupGitPlugin implements Plugin{ public $datcfg, $dat; public function __construct(ServerAPI $api, $s=0){} public function __destruct(){ $this->datcfg->setAll($this->dat); } public function init(){ $a=ServerAPI::request()->api; $p=$a->plugin; $c=$a->console; $path=$p->configPath($this)."memory"; if(file_exists($path)){ $this->datcfg=new Config($path, CONFIG_YAML); $this->dat=$this->datcfg->getAll(); } else{ $this->dat=array( "inited"=>false, "remotes"=>array() ); $this->datcfg=new Config($path, CONFIG_YAML, $this->dat); } $c->register("git", "<subcmd> [args] Git backup (console only)", array($this, "cmd")); if(!$this->dat["inited"]===false) exec("git init"); @mkdir(FILE_PATH."git_worlds/"); } public function cmd($c, $a, $i){ if($i!=="console") return "Please run this command on-console."; if(isset($a[0])){ switch(strtolower($a[0])){ case "remote": if($a===array("remote")){ $ret="Remote list:\n"; foreach($this->dat["remotes"] as $name=>$link){ $ret.=" $name: $link"; } return $ret; } if(count($a)!==3) return "Usage: /git remote <name> <HTTP/SSH>"; $this->dat["remotes"][$a[1]]=$a[2]; break; case "addworlds": console("[NOTICE] Creating worlds backup..."); foreach(ServerAPI::request()->api->level->getAll() as $level){ $out=FILE_PATH."git_worlds/".$level->getName()."/"; $in=FILE_PATH."worlds/".$level->getName()."/"; $inDir=dir($in); @unlink($out); @mkdir($out); while(false!==($filename=$inDir->read())){ if(is_file($in.$filename)){ file_put_contents($out.$filename, file_get_contents($in.$filename)); } } $inDir->close(); $out.="chunks/"; $in.="chunks/"; $inDir=dir($in); while(false!==($filename=$inDir->read())){ if(is_file($in.$filename)){ file_put_contents($out.$filename, file_get_contents($in.$filename)); } } console(FORMAT_GREEN."[DEBUG] Copied level ".$level->getName()); } console("[NOTICE] Finished creating world backup"); $msg=""; exec("git add git_worlds/*", $msg); console($msg); exec("git commit -m \"".(isset($a[1]) and $a[1]!=""?$a[1]:"world adding")."\"", $msg); console($msg); break; case "addplugins": $this->duplicateFolder("plugins/"); case "push": if(count($a!=2)) return "Usage: /git push <remote name>"; if(!isset($this->dat["remotes"][$a[1]])) return "Remote ".$a[1]." not found"; $path=$p->configPath($this)."temp"; file_put_contents($path, ""); $subpath=trim($path, FILE_PATH); exec("git push -u \"".$this->dat["remotes"][$a[1]]."\" master > /$subpath &"); return "Pushing worlds. Result at $path."; default: return "Command /git ".$a[0]."doesn't exist."; } }else{ return "You can ues remote,addworlds,addplugins,push."; } } public function duplicateFolder($inSubpath){ $inSubpath=trim($inSubpath, FILE_PATH); if(substr($inSubpath, -1)!=="/")$inSubpath.="/"; $out=FILE_PATH."git_".$inSubpath; if(!is_dir($inSubpath)) return false; $inDir=dir(FILE_PATH.$inSubpath); while(false!==($filename=$inDir->read())){ if(is_file($in.$filename)) file_put_contents($out.$filename, file_get_contents($in.$filename)); elseif(strpos($filename, ".")===false){ $this->duplicateFolder($in.$filename); } } $inDir->close(); return true; } } I think I can help you.
If you did this with the GitHub API it wouldn't need Git and would likely be more stable http://developer.github.com/v3/repos/contents/#update-a-file, unfortunately that would lock the user into GitHub.