Skip to content

Instantly share code, notes, and snippets.

@passy
Created May 20, 2010 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passy/407405 to your computer and use it in GitHub Desktop.
Save passy/407405 to your computer and use it in GitHub Desktop.
"""
Clones a list of repositories from git.local.lan and pushes it
into a (from the outside) "read-only" branch on weluse.de.
"""
import subprocess
import tempfile
import os
import shutil
# A list of tuples. First is the source, second the destination.
REPOSITORIES = [
('git@git.local.lan:yoosello/mainline.git',
'gitosis@weluse.de:yoosello_upstream.git'),
('git@git.local.lan:medimops/welmopter.git',
'gitosis@weluse.de:welmopter_upstream.git'),
('git@git.local.lan:medimops/verteilermops.git',
'gitosis@weluse.de:verteilermops_upstream.git'),
]
def call(cmd):
ret = subprocess.call(cmd.split(' '))
if ret != 0:
raise Exception("Running command {0} failed!".format(cmd))
def push(repo, destination):
os.chdir(repo)
call("git remote add --mirror upstream {0}".format(destination))
call("git push upstream --mirror")
def run():
cwd = os.getcwd()
for source, destination in REPOSITORIES:
# Go back to our original dir
os.chdir(cwd)
# Create a temporary directory
tmpdir = tempfile.mkdtemp('gitclone')
print("Starting to backup {0}.".format(source))
try:
call("git clone {0} {1}".format(source, tmpdir))
except KeyboardInterrupt:
raise
except:
# An error in this place is usually an unresponsive host or an
# access deny.
# TODO: Send a notification mail.
continue
try:
push(tmpdir, destination)
print("Backup of {0} successful.".format(source))
finally:
shutil.rmtree(tmpdir)
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment