-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVjFunctions.php
146 lines (122 loc) · 3.32 KB
/
VjFunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* http://www.cyberzo.com/
* Developed By: Vijay Naidu
* Email: vijay@cyberzo.com
* Date: 28-8-2015 IST
*/
require 'config.php';
require 'AmazonWebService/aws-autoloader.php';
require 'VjAmazonS3.php';
$logFileName = dirname(__FILE__).DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR.date('Y-m-d_H-i-s').".log";
function echoConsole($mess = '', $isExit = false){
$val = '';
if(!empty($mess)) {
$val = $mess . "\n";
}
backupLog($mess);
echo $val;
if($isExit){
exit;
}
}
function lockBackupProcess(){
//backupProcess.lock
fopen("backupProcess.lock", "w") or die("Unable to create lock file \"backupProcess.lock\" !");
if(file_exists('backupProcess.lock')){
echoConsole("Created backup lock file.");
}
else{
echoConsole("Unable to create lock file.", true);
}
}
function isBackupRunningAlready(){
$alreadyStarted = true;
if(!file_exists('backupProcess.lock')){
$alreadyStarted = false;
}
return $alreadyStarted;
}
function removeBackupProcessLock(){
if(file_exists('backupProcess.lock')){
unlink('backupProcess.lock');
}
}
function lockRestoreProcess(){
//restoreProcess.lock
fopen("restoreProcess.lock", "w") or die("Unable to create lock file \"restoreProcess.lock\" !");
if(file_exists('restoreProcess.lock')){
echoConsole("Created Restore lock file.");
}
else{
echoConsole("Unable to create lock file.", true);
}
}
function isRestoreRunningAlready(){
$alreadyStarted = true;
if(!file_exists('restoreProcess.lock')){
$alreadyStarted = false;
}
return $alreadyStarted;
}
function removeRestoreProcessLock(){
if(file_exists('restoreProcess.lock')){
unlink('restoreProcess.lock');
}
}
function backupLog($mess=""){
global $logFileName;
if(!empty($mess)){
$logFile = fopen($logFileName, "a+") or die("Unable to create log file.");
if(file_exists($logFileName)){
$lMess = date('Y-m-d H:i:s')."=> Mess: ".$mess." \n";
fwrite($logFile, $lMess);
}
fclose($logFile);
}
}
function getConsoleInput($mess = ""){
$value = "";
if(!empty($mess)){
echo $mess;
backupLog($mess);
$inputValue = fopen ("php://stdin","r");
$value = trim(fgets($inputValue));
if($value=='' || $value==' '){
$value = getConsoleInput($mess);
}
backupLog($value);
echo "\n";
}
return trim($value);
}
function getSorted($items = array(), $sortDirection='desc'){
$fiItems = $items;
if(!empty($items)){
$sortKey = 'timestamp';
$sortArr = array();
foreach($items as $key => $item){
$sortArr[$key] = $item[$sortKey];
}
$srtDirection = SORT_ASC;
if($sortDirection == 'desc'){
$srtDirection = SORT_DESC;
}
array_multisort($sortArr, $srtDirection, $fiItems);
}
return $fiItems;
}
function showArrayOptionsInConsole($arr = array(), $nos=0){
if(!empty($arr)){
$ini = 0;
foreach($arr as $ar){
$mess = $ini.". Backup taken on ".$ar['date_time']." of size ".$ar['readable_size'];
echoConsole($mess);
$ini++;
if($nos==$ini){
break;
}
}
}
}
?>