##// END OF EJS Templates
fixed the backup script path problems
Marcin Kuzminski -
r27:8f29ddc4 default
parent child Browse files
Show More
@@ -1,53 +1,54 b''
1 1 import logging
2 2 from mercurial import config
3 3 import tarfile
4 4 import os
5 5 import datetime
6 6 import sys
7 7 logging.basicConfig(level = logging.DEBUG,
8 8 format = "%(asctime)s %(levelname)-5.5s %(message)s")
9 9
10 10 class BackupManager(object):
11 11 def __init__(self):
12 12
13 cur_dir = os.path.realpath(__file__)
13 14 dn = os.path.dirname
14 self.backup_file_path = os.path.join(dn(dn(dn(__file__))), 'data')
15 self.backup_file_path = os.path.join(dn(dn(dn(cur_dir))), 'data')
15 16 cfg = config.config()
16 17 try:
17 cfg.read(os.path.join(dn(dn(dn(__file__))), 'hgwebdir.config'))
18 cfg.read(os.path.join(dn(dn(dn(cur_dir))), 'hgwebdir.config'))
18 19 except IOError:
19 20 logging.error('Could not read hgwebdir.config')
20 21 sys.exit()
21 22 self.set_repos_path(cfg.items('paths'))
22 23 logging.info('starting backup for %s', self.repos_path)
23 24 logging.info('backup target %s', self.backup_file_path)
24 25
25 26 if not os.path.isdir(self.repos_path):
26 27 raise Exception('Not a valid directory in %s' % self.repos_path)
27 28
28 29 def set_repos_path(self, paths):
29 30 repos_path = paths[0][1].split('/')
30 31 if repos_path[-1] in ['*', '**']:
31 32 repos_path = repos_path[:-1]
32 33 if repos_path[0] != '/':
33 34 repos_path[0] = '/'
34 35 self.repos_path = os.path.join(*repos_path)
35 36
36 37 def backup_repos(self):
37 38 today = datetime.datetime.now().weekday() + 1
38 39 bckp_file = os.path.join(self.backup_file_path,
39 40 "mercurial_repos.%s.tar.gz" % today)
40 41 tar = tarfile.open(bckp_file, "w:gz")
41 42
42 43 for dir in os.listdir(self.repos_path):
43 44 logging.info('backing up %s', dir)
44 45 tar.add(os.path.join(self.repos_path, dir), dir)
45 46 tar.close()
46 47 logging.info('finished backup of mercurial repositories')
47 48
48 49
49 50 if __name__ == "__main__":
50 51 bm = BackupManager()
51 52 bm.backup_repos()
52 53
53 54
General Comments 0
You need to be logged in to leave comments. Login now