]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/minecraft-remote/tasks.py
724b43be67f27cbabcfab1593ec6b37195dd5a7c
[dotfiles.git] / invoke / minecraft-remote / tasks.py
1 from invoke import task
2 from invoke import tasks
3 import os
4 from datetime import datetime as dt
5
6 IP=os.environ.get('LUANTI_IP')
7 USER=os.environ.get('LUANTI_USER')
8 HOME=os.environ.get('LUANTI_HOME')
9 LOCAL_HOME=os.environ.get('HOME')
10
11 TODAY = dt.now().strftime('%Y.%m.%d')
12
13 USER_AT_IP=f'{USER}@{IP}'
14 SSH=f'ssh {USER}@{IP}'
15 SCP=f'scp {USER}@{IP}'
16
17 DATE_TAR=f'{TODAY}.tar'
18
19 # Minecraft
20 LOCAL_BACKUPS=f'{LOCAL_HOME}/backup/minecraft'
21
22 MINECRAFT=f'{HOME}/Minecraft'
23
24 DIRS = ['world', 'world_nether', 'world_the_end', 'plugins']
25
26 # TODO: Set these
27 JAVA=f'{HOME}/java/jdk21/bin/java'
28 JAVA_OPTS=f'--Xms3000 --Xmx6000'
29 OPTIONS=f'--nogui'
30 SERVE=f'screen -S Minecraft -d -m {JAVA} {JAVA_OPTS} {MINECRAFT}/server.jar {OPTIONS}'
31
32 @task
33 def compress_world(c):
34 for world in DIRS:
35 c.run(f'{SSH} -C tar cf /tmp/{world}.{DATE_TAR} --directory={MINECRAFT} {world}')
36 c.run(f'{SSH} -C ls /tmp | grep .tar')
37
38
39 @task(compress_world)
40 def backup(c):
41 stopped = input("Is the server stopped?")
42 if(stopped != 'y'):
43 print("so go stop the server...")
44 exit()
45 c.run(f'mkdir -p {LOCAL_BACKUPS}')
46
47 for world in DIRS:
48 c.run(f'{SCP}:/tmp/{world}.{DATE_TAR} {LOCAL_BACKUPS}')
49
50 c.run(f'ls -lh {LOCAL_BACKUPS} | grep .tar')
51 verify_backup(c)
52
53 @task
54 def verify_backup(c):
55 for world in DIRS:
56 c.run(f'tar tvf {LOCAL_BACKUPS}/{world}.{DATE_TAR} | tail')
57 c.run(f'tar tvf {LOCAL_BACKUPS}/{world}.{DATE_TAR} | wc')
58
59 @task
60 def check_server(c):
61 result = c.run(f'ssh {USER}@{IP} -C screen -ls')
62
63 @task(verify_backup)
64 def serve(c):
65 print(f"Attempting to connect to {IP}")
66 result = c.run(f'ssh {USER}@{IP} -C {SERVE}')
67 print(f'Server should now be running in a remote screen session.')
68 print(result)
69
70
71 @task
72 def serve(c):
73 print(f"Attempting to connect to {IP}")
74 result = c.run(f'ssh {USER}@{IP} -C {SERVE}')
75 print(f'Server should now be running in a remote screen session.')
76 print(result)
77