| 11 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
6 |
Copyright (C) 2014~2025 MIN ZHI, CHEN
|
| 11 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
#使用命名空間qbpwcf
|
|
|
26 |
namespace qbpwcf;
|
|
|
27 |
|
|
|
28 |
#assets dir
|
|
|
29 |
$assetsDir="assets of cmd::rsync_20241212";
|
|
|
30 |
|
|
|
31 |
#cmd::rysnc的source參數
|
|
|
32 |
$paramSourceOfRsync=$assetsDir."/serverA/vm-disk.qcow2";
|
|
|
33 |
|
|
|
34 |
#cmd::rsync的target參數
|
|
|
35 |
$paramTargetOfRsync=$assetsDir."/serverB/vm-disk.qcow2";
|
|
|
36 |
|
|
|
37 |
#如果存在 $paramTargetOfRsync 檔案
|
|
|
38 |
if(\file_exists($paramTargetOfRsync)){
|
|
|
39 |
|
|
|
40 |
#移除之
|
|
|
41 |
\unlink($paramTargetOfRsync);
|
|
|
42 |
|
|
|
43 |
}#if end
|
|
|
44 |
|
|
|
45 |
#函式說明:
|
|
|
46 |
#使用 linux 的 rsync 指令來進行備份檔案.
|
|
|
47 |
#回傳結果:
|
|
|
48 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
49 |
#$result["error"],錯誤訊息.
|
|
|
50 |
#$result["function"],當前執行的函式名稱.
|
|
|
51 |
#$result["cmd"],執行的指令.
|
|
|
52 |
#必填參數:
|
|
|
53 |
#$conf["source"],字串,需要進行備份的目錄或檔案
|
|
|
54 |
$conf["source"]=$paramSourceOfRsync;
|
|
|
55 |
#$conf["target"],字串,備份到哪個地方或檔案
|
|
|
56 |
$conf["target"]=$paramTargetOfRsync;
|
|
|
57 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
58 |
$conf["fileArgu"]=__FILE__;
|
|
|
59 |
#可省略參數:
|
|
|
60 |
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要複製,預設為"false".
|
|
|
61 |
$conf["recursive"]="true";
|
|
|
62 |
#$conf["exclude"],字串陣列,每個元素代表要排除的項目,預設不指定.
|
|
|
63 |
#$conf["exclude"]=array();
|
|
|
64 |
#$conf["excludeFileType"],字串陣列,每個元素代表要排除的副檔名,預設不指定.
|
|
|
65 |
#$conf["excludeFileType"]=array();
|
|
|
66 |
#$conf["bandWidthLimit"],字串,代表頻寬上限,單為可為K、M、G等,預設不指定.
|
|
|
67 |
$conf["bandWidthLimit"]="400K";
|
|
|
68 |
#$conf["newFileOnly"],字串,是否只複製比較新的檔案,預設為"true"代表要;反之為"false".
|
|
|
69 |
$conf["newFileOnly"]="true";
|
|
|
70 |
#$conf["appendMode"],字串,是否用append的方式複製,適用於檔案內同位置內容一樣的檔案,預設值"false"代表不要;反之為"true".
|
|
|
71 |
$conf["appendMode"]="true";
|
|
|
72 |
#參考資料:
|
|
|
73 |
#無
|
|
|
74 |
#備註:
|
|
|
75 |
#無.
|
|
|
76 |
$rsync=cmd::rsync($conf);
|
|
|
77 |
unset($conf);
|
|
|
78 |
|
|
|
79 |
#如果執行失敗
|
|
|
80 |
if($rsync["status"]==="false"){
|
|
|
81 |
|
|
|
82 |
#函式說明:
|
|
|
83 |
#撰寫log
|
|
|
84 |
#回傳結果:
|
|
|
85 |
#$result["status"],狀態,"true"或"false".
|
|
|
86 |
#$result["error"],錯誤訊息陣列.
|
|
|
87 |
#$result["function"],當前函式的名稱.
|
|
|
88 |
#$result["argu"],使用的參數.
|
|
|
89 |
#必填參數:
|
|
|
90 |
#$conf["path"],字串,log檔案的路徑與名稱.
|
|
|
91 |
$conf["path"]=$logFile;
|
|
|
92 |
#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
|
|
|
93 |
$conf["content"]=$rsync;
|
|
|
94 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
95 |
$conf["fileArgu"]=__FILE__;
|
|
|
96 |
#可省略參數:
|
|
|
97 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
98 |
#$conf["rewrite"]="false";
|
|
|
99 |
#參考資料:
|
|
|
100 |
#無.
|
|
|
101 |
#備註:
|
|
|
102 |
#無.
|
|
|
103 |
$record=logs::record($conf);
|
|
|
104 |
unset($conf);
|
| 226 |
liveuser |
105 |
|
| 11 |
liveuser |
106 |
#如果寫log失敗
|
|
|
107 |
if($record["status"]==="false"){
|
| 226 |
liveuser |
108 |
|
| 11 |
liveuser |
109 |
#印出結果
|
|
|
110 |
var_dump($record);
|
| 226 |
liveuser |
111 |
|
| 11 |
liveuser |
112 |
}#if end
|
| 226 |
liveuser |
113 |
|
| 11 |
liveuser |
114 |
#結束執行,回傳錯誤代碼1
|
|
|
115 |
exit(1);
|
|
|
116 |
|
|
|
117 |
}#if end
|
| 226 |
liveuser |
118 |
|
| 11 |
liveuser |
119 |
#debug
|
| 226 |
liveuser |
120 |
var_dump($rsync);
|