-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.py
37 lines (30 loc) · 1.05 KB
/
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
import asyncio
import logging
import os
SLEEP_TIME = 24*60*60 # 24 hours
PREFIX = "backup : "
BACKUP_DIR = "./backup"
async def start_backup(logger: logging.Logger, msgQueue: asyncio.Queue):
if not os.path.exists(BACKUP_DIR):
os.makedirs(BACKUP_DIR)
while True:
try:
exit_code = os.system(f'sudo /bin/bash ./backup.sh')
if exit_code != 0:
logger.error(PREFIX + "Error in creating backup, trying again...")
await asyncio.sleep(10)
else:
logger.info(PREFIX + "New Backup created")
msgQueue.put_nowait(True)
await asyncio.sleep(SLEEP_TIME)
except:
logger.error(PREFIX + "Error in creating backup, trying again...")
await asyncio.sleep(10)
def last_backup_time():
if not os.path.exists(BACKUP_DIR):
return ""
files = os.listdir(BACKUP_DIR)
if len(files) == 0:
return ""
files.sort()
return files[-1][7:] # remove first 7 chars from backup_<time>