-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (23 loc) · 856 Bytes
/
main.py
File metadata and controls
29 lines (23 loc) · 856 Bytes
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
import settings
from subprocess import Popen
from datetime import date
import time
import os
def backup_db(db_id):
now = date.today()
file = settings.BACKUP_TEMPLATES[db_id] + "_" + now.strftime("%Y-%m-%d")
cmd = settings.BACKUP_BIN + " -U " + settings.DATABASE_USER + " -Fp -b -v -f " + file + " " + settings.DATABASES[db_id]
process = Popen(cmd, shell=False)
process.wait()
def cleanup():
seconds = time.time() - (settings.DAYS_TO_RETAIN * 24 * 60 * 60)
for root, dirs, files in os.walk(settings.BACKUP_DIR, topdown=False):
for f in files:
file_path = os.path.join(root, f)
stat = os.stat(file_path)
if stat.st_mtime <= seconds:
os.remove(file_path)
if __name__ == '__main__':
for i in range(0, len(settings.DATABASES)):
backup_db(i)
cleanup()