]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/minecraft-remote/tasks.py
Add Minecraft invoke commands
[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 dims = ['world', 'world_nether', 'world_the_end']
25
26 @task
27 def compress_world(c):
28 for world in dims:
29 c.run(f'{SSH} -C tar cf /tmp/{world}.{DATE_TAR} --directory={MINECRAFT} {world}')
30 c.run(f'{SSH} -C ls /tmp | grep .tar')
31
32
33 @task(compress_world)
34 def backup(c):
35 stopped = input("Is the server stopped?")
36 if(stopped != 'y'):
37 print("so go stop the server...")
38 exit()
39 c.run(f'mkdir -p {LOCAL_BACKUPS}')
40
41 for world in dims:
42 c.run(f'{SCP}:/tmp/{world}.{DATE_TAR} {LOCAL_BACKUPS}')
43
44 c.run(f'ls -lh {LOCAL_BACKUPS} | grep .tar')
45 verify_backup(c)
46
47 @task
48 def verify_backup(c):
49 for world in dims:
50 c.run(f'tar tvf {LOCAL_BACKUPS}/{world}.{DATE_TAR} | tail')
51 c.run(f'tar tvf {LOCAL_BACKUPS}/{world}.{DATE_TAR} | wc')
52
53 @task
54 def check_server(c):
55 result = c.run(f'ssh {USER}@{IP} -C screen -ls')
56
57 @task(verify_backup)
58 def serve(c):
59 print(f"Attempting to connect to {IP}")
60 result = c.run(f'ssh {USER}@{IP} -C {SERVE}')
61 print(f'Server should now be running in a remote screen session.')
62 print(result)
63