-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTSbedrockBackup.vbs
330 lines (264 loc) · 9.43 KB
/
TSbedrockBackup.vbs
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
'File Name: bedrockBackup.vbs
'Author: NeoLich
'Last Edited: 5,9,2020
'Helps with automatic backups for bedrock servers
Dim x : set x = createObject("wscript.shell")
Dim obj : set obj = GetObject("winmgmts:")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim num : num = 1
Dim bbv : bbv = 0
Dim strFolder, strFile, serverFile, worldLoc, backLoc, btime
Function Check 'checks to see if the server is running will return 1 or 0
Dim ProL, pro, pror
set ProL = obj.ExecQuery _
("Select * from Win32_Process")
For Each pro In ProL
If pro.name = "bedrock_server.exe" Then
Check = 1
Exit Function
Else
Check = 0
End If
Next
End Function
Function Multi 'checks how many vbs scripts are open and if more than more are open will close itself
Dim ProL, pro, pror
set ProL = obj.ExecQuery _
("Select * from Win32_Process")
For Each pro In ProL
If pro.name = "wscript.exe" Then
bbv = bbv + 1
End If
Next
If bbv = 1 Then
Exit Function
Else
MsgBox "The Program is already running!!!"
wscript.quit
End If
End Function
Function Copy 'copies the world folder to the backup folder
If Check = 1 Then
Exit Function
Else
Dim a : a = "\\" & Month(Date) & "," & Day(Date) & "," & Year(Date) & "_" & Time()
a = Replace(a,":","")
Dim f : Set f = FSO.CreateFolder(backLoc & a)
FSO.CopyFolder worldLoc, (backLoc & a)
wscript.sleep 1000
End If
End Function
Function Open 'opens the server
If Check = 1 Then
Exit Function
End If
If num = 4 Then
MsgBox "Failed To Open Server!"
exit Function
end If
If (FSO.FileExists(serverFile)) Then
x.run serverFile
num = num + 1
wscript.sleep 60000
Else
MsgBox "Server File Not Found"
wscript.quit
End If
If Check = 0 Then
Open
End If
End Function
Function FiveMinWar 'Sends a five minute warning to the players and then closes the server after 5 minutes
Dim q, t1, t2, t3, t4, t5, t6, t7
q = """"
t1 = "tellraw @a {{}"
t2 = "rawtext"
t3 = ":{[}{{}"
t4 = "text"
t5 = ":"
t6 = "{[}BackUp{]}"
t7 = "{}}{]}{}}{ENTER}"
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " Scheduled for 5 minutes." & q & t7
wscript.sleep 240000
If Check = 1 Then
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " Scheduled for 1 minute." & q & t7
wscript.sleep 30000
End If
If Check = 1 Then
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " Scheduled for 30 seconds." & q & t7
wscript.sleep 20000
End If
If Check = 1 Then
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 10" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 9" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 8" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 7" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 6" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 5" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 4" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 3" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 2" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " 1" & q & t7
wscript.sleep 1000
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " Starting! Goodbye!" & q & t7
x.sendkeys "stop{ENTER}"
wscript.sleep 10000
End If
End Function
Function BackUpFinished 'Will send a message telling when the next server launch time
Dim q, t1, t2, t3, t4, t5, t6, t7
q = """"
t1 = "tellraw @a {{}"
t2 = "rawtext"
t3 = ":{[}{{}"
t4 = "text"
t5 = ":"
t6 = "{[}BackUp{]}"
t7 = "{}}{]}{}}{ENTER}"
If Check = 1 Then
x.AppActivate"bedrock_server.exe"
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " Finished. Server is online. Have Fun." & q & t7
wscript.sleep 1000
x.sendkeys t1 & q & t2 & q & t3 & q & t4 & q & t5 & q & t6 & " Scheduled for " & btime & "." & q & t7
End If
End Function
Function GetPath 'Gets the folder path for the program and file path for the properties file
strFile = Wscript.ScriptFullName
Set objFile = FSO.GetFile(strFile)
strFolder = FSO.GetParentFolderName(objFile)
strFile = strFolder & "\backup.properties"
End Function
Function Properties 'Will get the properties from the backup.properties file
Dim PropertiesFile : Set PropertiesFile = FSO.OpenTextFile("D:\\MinecraftServers\\Bedrock\\backup.properties")
PropertiesFile.skipLine
PropertiesFile.skipLine
serverFile = PropertiesFile.ReadLine
PropertiesFile.skipLine
PropertiesFile.skipLine
worldLoc = PropertiesFile.ReadLine
PropertiesFile.skipLine
PropertiesFile.skipLine
backLoc = PropertiesFile.ReadLine
PropertiesFile.skipLine
PropertiesFile.skipLine
btime = PropertiesFile.ReadLine
PropertiesFile.close
End Function
Function PFCheck 'Checks if backup.properties exists if no will ask for setup
If (FSO.fileExists(strFile)) Then
Exit Function
Else
intAnswer = _
Msgbox("Do you wish to setup BedrockBackup?", _
vbYesNo, "Fisrt Run")
If intAnswer = vbYes Then
PFCreate
Else
MsgBox "BedrockBackup will not work without backup.properties."
wscript.quit
End If
End If
End Function
Function PFCreate 'asks for all locations and create backup.properties
Dim TempServerFile, TempWorldLoc, TempBackLoc, TempBTime, answ
intAnswer = _
Msgbox("Do You wish to change the Directory for the server?" & vbCrLf & "Default : " & strFolder, _
vbYesNo, "Server Directory")
If intAnswer = vbYes Then
answ = vbNo
While answ = vbNo
strFolder = InputBox("Please enter the Directory for the server", "Change Server Directory", strFolder)
answ = MsgBox("Is this the correct Directory for the server?" & vbCrLf & "New : " & strFolder, _
vbYesNo, "Recheck")
Wend
End If
TempServerFile = strFolder & "\bedrock_server.exe"
TempWorldLoc = strFolder & "\worlds"
TempBackLoc = strFolder & "\backups"
TempBTime = "4am"
intAnswer = _
Msgbox("Do You wish to change the Directory for the Backups?" & vbCrLf & "Default : " & TempBackLoc, _
vbYesNo, "Backup Folder")
If intAnswer = vbYes Then
answ = vbNo
While answ = vbNo
TempBackLoc = InputBox("Please enter the Directory for the Backups", "Change Backup Directory", TempBackLoc)
answ = MsgBox("Is this the correct Directory for the backups?" & vbCrLf & "New : " & TempBackLoc, _
vbYesNo, "Recheck")
Wend
End If
intAnswer = _
Msgbox("Do You wish to change the default time for the backups?" & vbCrLf & "Default : " & TempBTime & vbCrLf & "The Program does not start itself you must use Task Scheduler and have this program run at the time you want.", _
vbYesNo, "Backup Time")
If intAnswer = vbYes Then
answ = vbNo
While answ = vbNo
TempBTime = InputBox("Please enter the time for the backups", "Change Server Directory", TempBTime)
answ = MsgBox("Is this the correct time for backups?" & vbCrLf & "New : " & TempBTime, _
vbYesNo, "Recheck")
Wend
End If
Set bfilec = FSO.CreateTextFile (strFile, true)
bfilec.Write "# These are the locations of the different files and folders that BedrockBackup.vbs uses (Example: C:\User\Server\File.exe)" & vbCrLf & vbCrLf & TempServerFile & vbCrLf & "#Path for the Bedrock Server file" & vbCrLf & vbCrLf & TempWorldLoc & vbCrLf & "#Path for the world directory for the server" & vbCrLf & vbCrLf & TempBackLoc & vbCrLf & "#Path for the Directory were the backups will be saved" & vbCrLf & vbCrLf & TempBTime & vbCrLf & "#This is the time the program will say it will backup. You must set up auto backups through Task Scheduler"
If (FSO.folderExists(TempBackLoc)) Then
Else
FSO.CreateFolder TempBackLoc
End If
If (FSO.folderExists(TempWorldLoc)) Then
Else
FSO.CreateFolder TempWorldLoc
End IF
If (FSO.FileExists(TempServerFile)) Then
Else
MsgBox "The Bedrock Server File was not found in the location given. Be sure to have installed the server before running this program."
End If
intAnswer = _
Msgbox("You have finished setting up BedrockBackup." & vbCrLf & "You can now automate the running of the program with Task Scheduler" & vbCrLf & "Do you wish to run BedrockBackup now?", _
vbYesNo, "Finished Setup")
If intAnswer = vbYes Then
Exit Function
Else
wscript.quit
End If
End Function
Function Main 'Closes server, backs up server, reopens server
If Check = 0 Then
Copy
Open
BackUpFinished
Exit Function
Else
FiveMinWar
Copy
Open
BackUpFinished
End If
End Function
Multi
GetPath
PFCheck
Properties
Main