Created
November 29, 2012 01:40
-
-
Save mike-zhang/4166192 to your computer and use it in GitHub Desktop.
git备份程序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
''' | |
.ssh/config (windows,for local git server): | |
Host host100 | |
Hostname 192.168.1.100 | |
User git | |
IdentityFile C:/Users/admin/.ssh/id_rsa_gitBackup_host100 | |
repo example: | |
/home/git/test1.git | |
''' | |
def localGitBackup(hostName,dirList): | |
for dirName in dirList: | |
print dirName," : ", | |
if os.path.exists(dirName): | |
strCmd = "cd %s && git pull && cd .." % dirName | |
os.system(strCmd) | |
else: | |
strCmd = "git clone %s:%s.git " % (hostName,dirName) | |
os.system(strCmd) | |
''' | |
.ssh/config (windows,for github): | |
Host github | |
Hostname github.com | |
User git | |
IdentityFile C:/Users/admin/.ssh/id_rsa_github | |
''' | |
#for github repos | |
def githubReposBackup(hostName,userName,repoList): | |
for repo in repoList: | |
print repo," : ", | |
if os.path.exists(repo): | |
strCmd = "cd %s && git pull && cd .." % repo | |
os.system(strCmd) | |
else: | |
strCmd = "git clone %s:%s/%s.git " % (hostName,userName,repo) | |
os.system(strCmd) | |
''' | |
.ssh/config (windows,for github): | |
Host gist | |
Hostname gist.github.com | |
User git | |
IdentityFile C:/Users/admin/.ssh/id_rsa_github_gist | |
''' | |
#for gist | |
def githubGistsBackup(host,gistList): | |
for gist in gistList: | |
print gist," : ", | |
if os.path.exists(gist): | |
strCmd = "cd %s && git pull && cd .." % gist | |
os.system(strCmd) | |
else: | |
strCmd = "git clone %s:%s.git " % (host,gist) | |
os.system(strCmd) | |
if __name__ == "__main__": | |
host_local = "host100" | |
host_github = "github" | |
host_gist = "gist" | |
userName_github = "mike-zhang" | |
dirList_local = [ | |
'test1', | |
'test2' | |
] | |
repoList_github = [ | |
'cppCallLua', | |
'testCodes' | |
] | |
gistList_github = [ | |
'4166192', | |
'4084385' | |
] | |
localGitBackup(host_local,dirList_local) | |
githubReposBackup(host_github,userName_github,repoList_github) | |
githubGistsBackup(host_gist,gistList_github) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
批量获取git数据,方便进行备份。
前提是配置好ssh的config文件并把git命令加入环境变量