-
Notifications
You must be signed in to change notification settings - Fork 0
/
ark_backup.py
62 lines (45 loc) · 1.7 KB
/
ark_backup.py
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
import os
import shutil
from ark_manager import *
from paths import *
from debug import get_logger
log = get_logger("ark_other_scripts")
from bro_utils import copytree
def back_up(folder=None):
if folder:
backup_dir = os.path.join(BACKUPS_DIR, folder)
else:
backup_dir = BACKUPS_DIR
log.info(f"Backing up server data into {backup_dir}")
if not os.path.exists(backup_dir):
os.makedirs(backup_dir, exist_ok=True)
run_shell_command_as_user(f"rm -rf {backup_dir}/*", user="root")
for filepath in BACKUP_FILES:
filename = os.path.basename(filepath)
dest = os.path.join(backup_dir, filename)
log.debug(f"Copying {filepath} to {dest}")
shutil.copy(filepath, dest)
for dirpath in BACKUP_DIRS:
dirname = os.path.basename(os.path.normpath(dirpath))
dest = os.path.join(BACKUPS_DIR, dirname)
if not os.path.exists(dest):
os.makedirs(dest, exist_ok=True)
log.debug(f"Copying {dirpath} to {dest}")
copytree(dirpath, dest)
log.info("Backup complete.")
if __name__ == "__main__":
from locks import Lock
import argparse
parser = argparse.ArgumentParser(description='Restart ark server.')
parser.add_argument("--message", dest='message', default=None,
help="Message to add to broadcast, usually reason for restart.")
args = parser.parse_args()
if args.message:
args.message = args.message.strip()
if not args.message.endswith("."):
args.message = args.message + ". "
else:
args.message = args.message + " "
run_with_lock(back_up, message="Backing up.")
else:
print ("Name not main just import")