-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSGBackups.py
41 lines (31 loc) · 976 Bytes
/
SGBackups.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
import ConfigParser
import ftputil
import os
import re
import time
FTP_ADDR = None
FTP_USER = None
FTP_PASS = None
backup_pattern = re.compile('wp\.(.*)\.(.*)\.tar\.gz')
def load_config():
global FTP_ADDR, FTP_USER, FTP_PASS
config = ConfigParser.ConfigParser()
config.read("settings.conf")
FTP_ADDR = config.get('ftp', 'ftp_addr')
FTP_USER = config.get('ftp', 'ftp_user')
FTP_PASS = config.get('ftp', 'ftp_pass')
def get_backups():
local_files = os.listdir("./Backups")
with ftputil.FTPHost(FTP_ADDR, FTP_USER, FTP_PASS) as host:
names = host.listdir(host.curdir)
for name in names:
if host.path.isfile(name) and re.match(backup_pattern, name) and name not in local_files:
print "Downloading: " + name
host.download(name, 'Backups/' + name)
def main():
load_config()
while True:
get_backups()
time.sleep(60*60)
if __name__ == "__main__":
main()