-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsync_backups.py
More file actions
38 lines (33 loc) · 1.2 KB
/
sync_backups.py
File metadata and controls
38 lines (33 loc) · 1.2 KB
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
#!/usr/bin/env python3
#
# Simple script to show off how easy it is to automate the controller API. This script shows off enumerating the
# current backups, downloading, and optionally deleting all the backups from the controller
#
import unifiapi
from pathlib import Path
# MODIFY
dest_dir = Path('/enterpoop/backups/unifi')
delete_backups = False
print("Logging into controller")
c = unifiapi.controller()
s = c.sites['default']()
print("Getting backup listing")
backups = s.c_backups()
for backup in backups:
full_file = Path(dest_dir / Path(backup['filename']))
if full_file.is_file():
stat = full_file.stat()
if stat.st_size != int(backup['size']):
print(f"{full_file} DOES NOT MATCH FILESIZE")
else:
print(f"{full_file} exists and is the right size")
if delete_backups:
print("Deleting {} from controller".format(backup['filename']))
backup.delete()
else:
print("Copying {} to {}".format(backup['filename'], full_file))
try:
full_file.write_bytes(backup.download().read())
except:
# Oops, delete file that could be only partly complete
full_file.unlink()