Show More
@@ -1,3 +1,4 b'' | |||||
|
1 | '''BACKUP MANAGER''' | |||
1 | import logging |
|
2 | import logging | |
2 | from mercurial import config |
|
3 | from mercurial import config | |
3 | import tarfile |
|
4 | import tarfile | |
@@ -10,6 +11,8 b' logging.basicConfig(level=logging.DEBUG,' | |||||
10 |
|
11 | |||
11 | class BackupManager(object): |
|
12 | class BackupManager(object): | |
12 | def __init__(self): |
|
13 | def __init__(self): | |
|
14 | self.repos_path = None | |||
|
15 | self.backup_file_name = None | |||
13 | self.id_rsa_path = '/home/pylons/id_rsa' |
|
16 | self.id_rsa_path = '/home/pylons/id_rsa' | |
14 | self.check_id_rsa() |
|
17 | self.check_id_rsa() | |
15 | cur_dir = os.path.realpath(__file__) |
|
18 | cur_dir = os.path.realpath(__file__) | |
@@ -30,7 +33,8 b' class BackupManager(object):' | |||||
30 |
|
33 | |||
31 | def check_id_rsa(self): |
|
34 | def check_id_rsa(self): | |
32 | if not os.path.isfile(self.id_rsa_path): |
|
35 | if not os.path.isfile(self.id_rsa_path): | |
33 |
logging.error('Could not load id_rsa key file in %s', |
|
36 | logging.error('Could not load id_rsa key file in %s', | |
|
37 | self.id_rsa_path) | |||
34 | sys.exit() |
|
38 | sys.exit() | |
35 |
|
39 | |||
36 | def set_repos_path(self, paths): |
|
40 | def set_repos_path(self, paths): | |
@@ -47,9 +51,9 b' class BackupManager(object):' | |||||
47 | bckp_file = os.path.join(self.backup_file_path, self.backup_file_name) |
|
51 | bckp_file = os.path.join(self.backup_file_path, self.backup_file_name) | |
48 | tar = tarfile.open(bckp_file, "w:gz") |
|
52 | tar = tarfile.open(bckp_file, "w:gz") | |
49 |
|
53 | |||
50 | for dir in os.listdir(self.repos_path): |
|
54 | for dir_name in os.listdir(self.repos_path): | |
51 | logging.info('backing up %s', dir) |
|
55 | logging.info('backing up %s', dir_name) | |
52 | tar.add(os.path.join(self.repos_path, dir), dir) |
|
56 | tar.add(os.path.join(self.repos_path, dir_name), dir_name) | |
53 | tar.close() |
|
57 | tar.close() | |
54 | logging.info('finished backup of mercurial repositories') |
|
58 | logging.info('finished backup of mercurial repositories') | |
55 |
|
59 | |||
@@ -70,14 +74,14 b' class BackupManager(object):' | |||||
70 |
|
74 | |||
71 |
|
75 | |||
72 | def rm_file(self): |
|
76 | def rm_file(self): | |
73 | os.remove(self.backup_file_path) |
|
77 | os.remove(os.path.join(self.backup_file_path, self.backup_file_name)) | |
74 |
|
78 | |||
75 |
|
79 | |||
76 |
|
80 | |||
77 | if __name__ == "__main__": |
|
81 | if __name__ == "__main__": | |
78 |
|
|
82 | B_MANAGER = BackupManager() | |
79 |
|
|
83 | B_MANAGER.backup_repos() | |
80 |
|
|
84 | B_MANAGER.transfer_files() | |
81 |
|
|
85 | B_MANAGER.rm_file() | |
82 |
|
86 | |||
83 |
|
87 |
General Comments 0
You need to be logged in to leave comments.
Login now