Git Backup Script

I run a local git repository on the server located at my house. Here is the latest backup script that I use to archive the git files.

#!/usr/bin/python
#
# This script dumps a git repo to flat files and ftp's these
# files to another network device.
#
import os
import datetime
import ftplib
import sys
import traceback


def main():
    if 5 > len(sys.argv):
        print("Usage: gitBackup <host> <user> <pwd> <remote path>")
        return
    
    host = sys.argv[1]
    user = sys.argv[2]
    pwd = sys.argv[3]
    remotePath = sys.argv[4]
    
    #
    # export the svn data to a compressed file
    #
    dToday      = datetime.date.today()
    strFileName = "git_backup_%s" % dToday.isoformat()
    
    strCmd = "git bundle create /tmp/%s master" % strFileName
    os.system( strCmd )
    strCmd = "git bundle create /tmp/%s.all --all" % strFileName
    os.system( strCmd )
    
    
    os.system("tar -cvzf /tmp/%s.tgz /tmp/%s.all /tmp/%s" % (strFileName, strFileName, strFileName))
    
    #
    # send the svn archive to our backup server
    #
    try:
        s = ftplib.FTP(host, user, pwd)
        s.cwd( remotePath ) # "/Josh/backups" )
        strFilePath = "/tmp/%s.tgz" % strFileName 
        f = open( strFilePath, "rb" )
        s.storbinary( "STOR %s.tgz" % strFileName, f )
        f.close()
        s.quit()
    except Exception as e:
        print("FTP error: %s" % str(e))
    
    #
    # cleanup our temp file
    #
    os.system( "rm /tmp/%s" % strFileName )
    os.system( "rm /tmp/%s.all" % strFileName )
    os.system( "rm /tmp/%s.tgz" % strFileName )
     


#
#
#
if "__main__" == __name__:
    try:
        main()
    except:
        traceback.print_exc()
        
#
# EOF