Subversion Repositories qbpwcf-lib(archive)

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
828 liveuser 1
<?php
2
 
3
#使用命名空間qbpwcf
4
namespace qbpwcf;
5
 
6
#assets dir
7
$assetsDir="assets of cmd::rsync_20241212";
8
 
9
#cmd::rysnc的source參數
10
$paramSourceOfRsync=$assetsDir."/serverA/vm-disk.qcow2";
11
 
12
#cmd::rsync的target參數
13
$paramTargetOfRsync=$assetsDir."/serverB/vm-disk.qcow2";
14
 
15
#如果存在 $paramTargetOfRsync 檔案
16
if(\file_exists($paramTargetOfRsync)){
17
 
18
	#移除之
19
	\unlink($paramTargetOfRsync);
20
 
21
	}#if end
22
 
23
#函式說明:
24
#使用 linux 的 rsync 指令來進行備份檔案.
25
#回傳結果:
26
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27
#$result["error"],錯誤訊息.
28
#$result["function"],當前執行的函式名稱.
29
#$result["cmd"],執行的指令.
30
#必填參數:
31
#$conf["source"],字串,需要進行備份的目錄或檔案
32
$conf["source"]=$paramSourceOfRsync;
33
#$conf["target"],字串,備份到哪個地方或檔案
34
$conf["target"]=$paramTargetOfRsync;
35
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
36
$conf["fileArgu"]=__FILE__;
37
#可省略參數:
38
#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要複製,預設為"false".
39
$conf["recursive"]="true";
40
#$conf["exclude"],字串陣列,每個元素代表要排除的項目,預設不指定.
41
#$conf["exclude"]=array();
42
#$conf["excludeFileType"],字串陣列,每個元素代表要排除的副檔名,預設不指定.
43
#$conf["excludeFileType"]=array();
44
#$conf["bandWidthLimit"],字串,代表頻寬上限,單為可為K、M、G等,預設不指定.
45
$conf["bandWidthLimit"]="400K";
46
#$conf["newFileOnly"],字串,是否只複製比較新的檔案,預設為"true"代表要;反之為"false".
47
$conf["newFileOnly"]="true";
48
#$conf["appendMode"],字串,是否用append的方式複製,適用於檔案內同位置內容一樣的檔案,預設值"false"代表不要;反之為"true".
49
$conf["appendMode"]="true";
50
#參考資料:
51
#無
52
#備註:
53
#無.
54
$rsync=cmd::rsync($conf);
55
unset($conf);
56
 
57
#如果執行失敗
58
if($rsync["status"]==="false"){
59
 
60
	#函式說明:
61
	#撰寫log
62
	#回傳結果:
63
	#$result["status"],狀態,"true"或"false".
64
	#$result["error"],錯誤訊息陣列.
65
	#$result["function"],當前函式的名稱.
66
	#$result["argu"],使用的參數.
67
	#必填參數:
68
	#$conf["path"],字串,log檔案的路徑與名稱.
69
	$conf["path"]=$logFile;
70
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
71
	$conf["content"]=$rsync;
72
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
73
	$conf["fileArgu"]=__FILE__;
74
	#可省略參數:
75
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
76
	#$conf["rewrite"]="false";
77
	#參考資料:
78
	#無.
79
	#備註:
80
	#無.
81
	$record=logs::record($conf);
82
	unset($conf);
83
 
84
	#如果寫log失敗
85
	if($record["status"]==="false"){
86
 
87
		#印出結果
88
		var_dump($record);
89
 
90
		}#if end
91
 
92
	#結束執行,回傳錯誤代碼1
93
	exit(1);
94
 
95
	}#if end
96
 
97
#debug
98
var_dump($rsync);