Skip to content

Instantly share code, notes, and snippets.

@feythin
Forked from mike-zhang/git_Backup.py
Created November 30, 2012 12:46

Revisions

  1. @mike-zhang mike-zhang revised this gist Nov 29, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git_Backup.py
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ def githubReposBackup(hostName,userName,repoList):
    IdentityFile C:/Users/admin/.ssh/id_rsa_github_gist
    '''
    #for gist
    def githubGistsBackup(host,userName,gistList):
    def githubGistsBackup(host,gistList):
    for gist in gistList:
    print gist," : ",
    if os.path.exists(gist):
    @@ -80,4 +80,4 @@ def githubGistsBackup(host,userName,gistList):

    localGitBackup(host_local,dirList_local)
    githubReposBackup(host_github,userName_github,repoList_github)
    githubGistsBackup(host_gist,userName_github,gistList_github)
    githubGistsBackup(host_gist,gistList_github)
  2. @mike-zhang mike-zhang revised this gist Nov 29, 2012. 1 changed file with 0 additions and 26 deletions.
    26 changes: 0 additions & 26 deletions git_Backup.py
    Original file line number Diff line number Diff line change
    @@ -11,14 +11,6 @@
    /home/git/test1.git
    '''
    def localGitBackup(hostName,dirList):
    '''
    hostName = "host100"
    dirList = [
    'test1',
    'test2'
    ]
    '''

    for dirName in dirList:
    print dirName," : ",
    if os.path.exists(dirName):
    @@ -37,15 +29,6 @@ def localGitBackup(hostName,dirList):
    '''
    #for github repos
    def githubReposBackup(hostName,userName,repoList):
    '''
    hostName = "github"
    userName = "mikezhang9986"
    repoList = [
    'cppCallLua',
    'testCodes'
    ]
    '''

    for repo in repoList:
    print repo," : ",
    if os.path.exists(repo):
    @@ -64,15 +47,6 @@ def githubReposBackup(hostName,userName,repoList):
    '''
    #for gist
    def githubGistsBackup(host,userName,gistList):
    '''
    host = "gist"
    userName = "mikezhang9986"
    gistList = [
    '4166192',
    '4084385'
    ]
    '''

    for gist in gistList:
    print gist," : ",
    if os.path.exists(gist):
  3. @mike-zhang mike-zhang renamed this gist Nov 29, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @mike-zhang mike-zhang revised this gist Nov 29, 2012. 1 changed file with 42 additions and 15 deletions.
    57 changes: 42 additions & 15 deletions git_checkout.py
    Original file line number Diff line number Diff line change
    @@ -10,14 +10,16 @@
    repo example:
    /home/git/test1.git
    '''
    def localGitBackup():
    def localGitBackup(hostName,dirList):
    '''
    hostName = "host100"
    dirs = [
    dirList = [
    'test1',
    'test2'
    ]
    '''

    for dirName in dirs:
    for dirName in dirList:
    print dirName," : ",
    if os.path.exists(dirName):
    strCmd = "cd %s && git pull && cd .." % dirName
    @@ -34,15 +36,17 @@ def localGitBackup():
    IdentityFile C:/Users/admin/.ssh/id_rsa_github
    '''
    #for github repos
    def githubReposBackup():
    def githubReposBackup(hostName,userName,repoList):
    '''
    hostName = "github"
    userName = "mikezhang9986"
    repoNames = [
    repoList = [
    'cppCallLua',
    'testCodes'
    ]
    '''

    for repo in repoNames:
    for repo in repoList:
    print repo," : ",
    if os.path.exists(repo):
    strCmd = "cd %s && git pull && cd .." % repo
    @@ -59,24 +63,47 @@ def githubReposBackup():
    IdentityFile C:/Users/admin/.ssh/id_rsa_github_gist
    '''
    #for gist
    def githubGistsBackup():
    hostName = "gist"
    userName = "mikezhang9986"
    repoNames = [
    def githubGistsBackup(host,userName,gistList):
    '''
    host = "gist"
    userName = "mikezhang9986"
    gistList = [
    '4166192',
    '4084385'
    ]
    '''

    for gist in repoNames:
    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 " % (hostName,gist)
    strCmd = "git clone %s:%s.git " % (host,gist)
    os.system(strCmd)

    if __name__ == "__main__":
    localGitBackup()
    githubReposBackup()
    githubGistsBackup()
    host_local = "host100"
    host_github = "github"
    host_gist = "gist"

    userName_github = "mikezhang9986"

    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,userName_github,gistList_github)
  5. @mike-zhang mike-zhang revised this gist Nov 29, 2012. 1 changed file with 55 additions and 56 deletions.
    111 changes: 55 additions & 56 deletions git_checkout.py
    Original file line number Diff line number Diff line change
    @@ -10,74 +10,73 @@
    repo example:
    /home/git/test1.git
    '''
    def localGitBackup():
    hostName = "host100"
    dirs = [
    'test1',
    'test2'
    ]

    hostName = "host100"
    dirs = [
    'test1',
    'test2'
    ]

    for dirName in dirs:
    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)

    raw_input("Press Enter to continue")
    for dirName in dirs:
    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 = "github"
    userName = "mikezhang9986"
    repoNames = [
    'cppCallLua',
    'testCodes'
    ]

    for repo in repoNames:
    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
    Python code for github backup:
    #for github
    import os
    hostName = "github"
    userName = "mikezhang9986"
    repoNames = [
    'cppCallLua',
    'testCodes'
    ]
    for repo in repoNames:
    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)
    Python code for gist backup:
    '''
    #for gist
    import os
    hostName = "gist"
    userName = "mikezhang9986"
    repoNames = [
    '4166192',
    '4084385'
    ]
    def githubGistsBackup():
    hostName = "gist"
    userName = "mikezhang9986"
    repoNames = [
    '4166192',
    '4084385'
    ]

    for gist in repoNames:
    print gist," : ",
    if os.path.exists(gist):
    strCmd = "cd %s && git pull && cd .." % gist
    os.system(strCmd)
    else:
    strCmd = "git clone %s:%s.git " % (hostName,gist)
    os.system(strCmd)
    '''
    for gist in repoNames:
    print gist," : ",
    if os.path.exists(gist):
    strCmd = "cd %s && git pull && cd .." % gist
    os.system(strCmd)
    else:
    strCmd = "git clone %s:%s.git " % (hostName,gist)
    os.system(strCmd)

    if __name__ == "__main__":
    localGitBackup()
    githubReposBackup()
    githubGistsBackup()
  6. @mike-zhang mike-zhang revised this gist Nov 29, 2012. 1 changed file with 59 additions and 8 deletions.
    67 changes: 59 additions & 8 deletions git_checkout.py
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,15 @@
    import os

    '''
    .ssh/config (windows):
    .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
    '''
    '''

    hostName = "host100"
    dirs = [
    @@ -19,14 +19,65 @@

    for dirName in dirs:
    print dirName," : ",
    if os.path.exists(dirName):
    print "exists"
    strCmd = "cd %s && git pull && cd .." % dirName
    print strCmd
    if os.path.exists(dirName):
    strCmd = "cd %s && git pull && cd .." % dirName
    os.system(strCmd)
    else:
    print "not exists"
    else:
    strCmd = "git clone %s:%s.git " % (hostName,dirName)
    os.system(strCmd)

    raw_input("Press Enter to continue")

    '''
    .ssh/config (windows,for github):
    Host github
    Hostname github.com
    User git
    IdentityFile C:/Users/admin/.ssh/id_rsa_github
    Host gist
    Hostname gist.github.com
    User git
    IdentityFile C:/Users/admin/.ssh/id_rsa_github_gist
    Python code for github backup:
    #for github
    import os
    hostName = "github"
    userName = "mikezhang9986"
    repoNames = [
    'cppCallLua',
    'testCodes'
    ]
    for repo in repoNames:
    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)
    Python code for gist backup:
    #for gist
    import os
    hostName = "gist"
    userName = "mikezhang9986"
    repoNames = [
    '4166192',
    '4084385'
    ]
    for gist in repoNames:
    print gist," : ",
    if os.path.exists(gist):
    strCmd = "cd %s && git pull && cd .." % gist
    os.system(strCmd)
    else:
    strCmd = "git clone %s:%s.git " % (hostName,gist)
    os.system(strCmd)
    '''
  7. MikeZhang revised this gist Nov 29, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_checkout.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    IdentityFile C:/Users/admin/.ssh/id_rsa_gitBackup_host100
    repo example:
    /home/git/test1.git
    /home/git/test1.git
    '''

    hostName = "host100"
  8. MikeZhang created this gist Nov 29, 2012.
    32 changes: 32 additions & 0 deletions git_checkout.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import os

    '''
    .ssh/config (windows):
    Host host100
    Hostname 192.168.1.100
    User git
    IdentityFile C:/Users/admin/.ssh/id_rsa_gitBackup_host100
    repo example:
    /home/git/test1.git
    '''

    hostName = "host100"
    dirs = [
    'test1',
    'test2'
    ]

    for dirName in dirs:
    print dirName," : ",
    if os.path.exists(dirName):
    print "exists"
    strCmd = "cd %s && git pull && cd .." % dirName
    print strCmd
    os.system(strCmd)
    else:
    print "not exists"
    strCmd = "git clone %s:%s.git " % (hostName,dirName)
    os.system(strCmd)

    raw_input("Press Enter to continue")