##// END OF EJS Templates
r435:0e8ef6f1 merge default
parent child Browse files
Show More
@@ -33,8 +33,8 b' depend() {'
33 33
34 34 start() {
35 35 ebegin "Starting $APP_NAME"
36 cd $APP_PATH
37 start-stop-daemon --start --quiet\
36 start-stop-daemon -d $APP_PATH -e PYTHON_EGG_CACHE="/tmp" \
37 --start --quiet \
38 38 --pidfile $PID_PATH \
39 39 --user $RUN_AS \
40 40 --exec $DAEMON -- $DAEMON_OPTS
@@ -43,7 +43,8 b' start() {'
43 43
44 44 stop() {
45 45 ebegin "Stopping $APP_NAME"
46 start-stop-daemon --stop --quiet \
46 start-stop-daemon -d $APP_PATH \
47 --stop --quiet \
47 48 --pidfile $PID_PATH || echo "$APP_NAME - Not running!"
48 49 if [ -f $PID_PATH ]; then
49 50 rm $PID_PATH
@@ -38,15 +38,16 b' DAEMON_OPTS="serve --daemon \\'
38 38 case "$1" in
39 39 start)
40 40 echo "Starting $APP_NAME"
41 cd $APP_PATH
42 start-stop-daemon --start --quiet\
41 start-stop-daemon -d $APP_PATH -e PYTHON_EGG_CACHE="/tmp" \
42 --start --quiet \
43 43 --pidfile $PID_PATH \
44 44 --user $RUN_AS \
45 45 --exec $DAEMON -- $DAEMON_OPTS
46 46 ;;
47 47 stop)
48 48 echo "Stopping $APP_NAME"
49 start-stop-daemon --stop --quiet \
49 start-stop-daemon -d $APP_PATH \
50 --stop --quiet \
50 51 --pidfile $PID_PATH || echo "$APP_NAME - Not running!"
51 52 if [ -f $PID_PATH ]; then
52 53 rm $PID_PATH
@@ -54,14 +55,18 b' case "$1" in'
54 55 ;;
55 56 restart)
56 57 echo "Restarting $APP_NAME"
57 #stop
58 start-stop-daemon --stop --quiet \
58 ### stop ###
59 echo "Stopping $APP_NAME"
60 start-stop-daemon -d $APP_PATH \
61 --stop --quiet \
59 62 --pidfile $PID_PATH || echo "$APP_NAME - Not running!"
60 63 if [ -f $PID_PATH ]; then
61 64 rm $PID_PATH
62 65 fi
63 #start
64 start-stop-daemon --start --quiet\
66 ### start ###
67 echo "Starting $APP_NAME"
68 start-stop-daemon -d $APP_PATH -e PYTHON_EGG_CACHE="/tmp" \
69 --start --quiet \
65 70 --pidfile $PID_PATH \
66 71 --user $RUN_AS \
67 72 --exec $DAEMON -- $DAEMON_OPTS
@@ -26,7 +26,6 b' Mercurial repositories backup manager'
26 26
27 27
28 28 import logging
29 from mercurial import config
30 29 import tarfile
31 30 import os
32 31 import datetime
@@ -36,44 +35,32 b' logging.basicConfig(level=logging.DEBUG,'
36 35 format="%(asctime)s %(levelname)-5.5s %(message)s")
37 36
38 37 class BackupManager(object):
39 def __init__(self, id_rsa_path, repo_conf):
40 self.repos_path = None
41 self.backup_file_name = None
42 self.id_rsa_path = id_rsa_path
43 self.check_id_rsa()
44 cur_dir = os.path.realpath(__file__)
45 dn = os.path.dirname
46 self.backup_file_path = os.path.join(dn(dn(dn(cur_dir))), 'data')
47 cfg = config.config()
48 try:
49 cfg.read(os.path.join(dn(dn(dn(cur_dir))), repo_conf))
50 except IOError:
51 logging.error('Could not read %s', repo_conf)
52 sys.exit()
53 self.set_repos_path(cfg.items('paths'))
38 def __init__(self, repos_location, rsa_key, backup_server):
39 today = datetime.datetime.now().weekday() + 1
40 self.backup_file_name = "mercurial_repos.%s.tar.gz" % today
41
42 self.id_rsa_path = self.get_id_rsa(rsa_key)
43 self.repos_path = self.get_repos_path(repos_location)
44 self.backup_server = backup_server
45
46 self.backup_file_path = '/tmp'
47
54 48 logging.info('starting backup for %s', self.repos_path)
55 49 logging.info('backup target %s', self.backup_file_path)
56 50
57 if not os.path.isdir(self.repos_path):
58 raise Exception('Not a valid directory in %s' % self.repos_path)
59 51
60 def check_id_rsa(self):
61 if not os.path.isfile(self.id_rsa_path):
62 logging.error('Could not load id_rsa key file in %s',
63 self.id_rsa_path)
52 def get_id_rsa(self, rsa_key):
53 if not os.path.isfile(rsa_key):
54 logging.error('Could not load id_rsa key file in %s', rsa_key)
64 55 sys.exit()
65 56
66 def set_repos_path(self, paths):
67 repos_path = paths[0][1].split('/')
68 if repos_path[-1] in ['*', '**']:
69 repos_path = repos_path[:-1]
70 if repos_path[0] != '/':
71 repos_path[0] = '/'
72 self.repos_path = os.path.join(*repos_path)
57 def get_repos_path(self, path):
58 if not os.path.isdir(path):
59 logging.error('Wrong location for repositories in %s', path)
60 sys.exit()
61 return path
73 62
74 63 def backup_repos(self):
75 today = datetime.datetime.now().weekday() + 1
76 self.backup_file_name = "mercurial_repos.%s.tar.gz" % today
77 64 bckp_file = os.path.join(self.backup_file_path, self.backup_file_name)
78 65 tar = tarfile.open(bckp_file, "w:gz")
79 66
@@ -88,12 +75,13 b' class BackupManager(object):'
88 75 def transfer_files(self):
89 76 params = {
90 77 'id_rsa_key': self.id_rsa_path,
91 'backup_file_path':self.backup_file_path,
92 'backup_file_name':self.backup_file_name,
78 'backup_file':os.path.join(self.backup_file_path,
79 self.backup_file_name),
80 'backup_server':self.backup_server
93 81 }
94 82 cmd = ['scp', '-l', '40000', '-i', '%(id_rsa_key)s' % params,
95 '%(backup_file_path)s/%(backup_file_name)s' % params,
96 'root@192.168.2.102:/backups/mercurial' % params]
83 '%(backup_file)s' % params,
84 '%(backup_server)s' % params]
97 85
98 86 subprocess.call(cmd)
99 87 logging.info('Transfered file %s to %s', self.backup_file_name, cmd[4])
@@ -106,7 +94,12 b' class BackupManager(object):'
106 94
107 95
108 96 if __name__ == "__main__":
109 B_MANAGER = BackupManager('/home/pylons/id_rsa', 'repositories.config')
97
98 repo_location = '/home/repo_path'
99 backup_server = 'root@192.168.1.100:/backups/mercurial'
100 rsa_key = '/home/id_rsa'
101
102 B_MANAGER = BackupManager(repo_location, rsa_key, backup_server)
110 103 B_MANAGER.backup_repos()
111 104 B_MANAGER.transfer_files()
112 105 B_MANAGER.rm_file()
General Comments 0
You need to be logged in to leave comments. Login now