1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- // +----------------------------------------
- // | overlay文件系统目录分布
- // +----------------------------------------
- $lowerDir = realpath(__DIR__."/../../smartLEDZ"); // read层·原始文件
- $upperDir = realpath(__DIR__."/../../smartLEDZ_Upper"); // write层
- $mergedDir = realpath(__DIR__."/../../smartLEDZ_Merged"); // 读写·数据交互层(read层 + write层) - [ 程序运行在此 ]
- $app_path = $lowerDir; // 当前运行的项目主目录
- $targetDir = $lowerDir; //
- if(is_dir($mergedDir)){ // 存在overlay
- $app_path = $mergedDir;
- $targetDir = $mergedDir;
- }
- if(file_exists($app_path . "/logs/gw_back")){
- unlink($app_path . "/logs/gw_back");
- }
- if(!is_dir($app_path . "/restore")) mkdir($app_path . "/restore");
- $unCmd = sprintf("tar -xvf %s/smartLEDZ_DB_U.tar -C %s/restore", $app_path, $app_path);
- exec($unCmd);
- // 检查备份文件是什么APP版本备份的
- exec("tar -tf " . $app_path."/smartLEDZ_DB_U.tar", $output);
- if(in_array("overlay/www/smartLEDZ/db/smartLEDZ.db", $output)){
- // 旧overlay版备份
- exec(sprintf("cp -r %s/restore/overlay/www/smartLEDZ/* %s", $app_path, $targetDir));
- exec(sprintf("rm -rf %s/restore/overlay", $app_path));
- }else if(in_array("mnt/mmcblk0p1/www/smartLEDZ/db/smartLEDZ.db", $output)){
- // 旧版APP备份
- exec(sprintf("cp -r %s/restore/mnt/mmcblk0p1/www/smartLEDZ/* %s", $app_path, $targetDir));
- exec(sprintf("rm -rf %s/restore/mnt", $app_path));
- }else if(in_array("mnt/mmcblk0p1/www/smartLEDZ_Merged/db/smartLEDZ.db", $output)){
- // 新overlay版备份
- exec(sprintf("cp -r %s/restore/mnt/mmcblk0p1/www/smartLEDZ_Merged/* %s", $app_path, $targetDir));
- exec(sprintf("rm -rf %s/restore/mnt", $app_path));
- }
- exec(sprintf("cp -r %s/db/exec.json.bak %s/db/exec.json", $targetDir, $targetDir));
- // 热重载Socket
- file_put_contents($app_path . "/workerman/reload", "");
|