Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import strftime as date
- import os, glob
- ##
- ## FUNCTIONS
- ##
- def getFiles(rootdir):
- fileList = []
- for root, subFolders, files in os.walk(rootdir):
- for file in files: fileList.append(os.path.join(root,file).replace("\\","/"))
- return fileList
- def cmpFile(file1,file2):
- f1=open(file1,"rb");f2=open(file2,"rb")
- val=(f1.read()==f2.read())
- f1.close();f2.close()
- return val
- def cmpFolder(folder1,folder2):
- set1=[i[len(folder1)+1:] for i in getFiles(folder1)]
- set2=[i[len(folder2)+1:] for i in getFiles(folder2)]
- if set1!=set2 or : return False
- else:
- matches=0
- for i in set1:
- for j in set2:
- if i==j:
- if cmpFile(folder1+"/"+i,folder2+"/"+j): matches+=1
- if matches!=len(set1): return False
- return True
- def doDelete(dir):
- os.system("RMDIR /S /Q \"%s\""%dir)
- def doBackup(bkuploc,dir):
- os.system("XCOPY /E /I /K /Q \"%s\" \"%s\""%(bkuploc,dir))
- def getDrive():
- x=input("Backup Array Drive Location: ")
- if x in ("C","D","E","F"):
- print("Invalid Drive")
- return getDrive()
- else:
- return x
- def restamp(drive):
- f1=drive+":/Backup Contents *.txt"
- f2=drive+":/Backup Contents "+date("%m-%d-%Y")+".txt"
- os.system("RENAME %s %s"%(f1,f2))
- ##
- ## INIT
- ##
- backedup=[]
- CoreLocation="C:/Documents and Settings/Tyler/Desktop/Core/"
- BkupDirs=(
- "Downloads",
- "Games/DEFCON",
- "Games/Minecraft",
- "Games/Katawa Shoujo",
- "Media/Images", #porn
- "Media/Documents",
- "Media/Music",
- "Internet/Firefox",
- )
- x=getDrive():
- DriveLoc=getDrive()
- print()
- print("Initiating Core Backup")
- print()
- ##
- ## ANALYSIS & BACKUP
- ##
- for i in BkupDirs:
- print("-------")
- print("Analyzing "+i.replace("/","\\"))
- if cmpFolder(CoreLocation+i,DriveLoc+":/"+i):
- print(" >%s does not require updating"%i.replace("/","\\"))
- else:
- print(" >%s will be updated"%i)
- print(" >Destroying outdated %s"%i)
- doDelete(DriveLoc+":/"+i)
- print(" >Backing up %s"%i)
- doBackup(CoreLocation,DriveLoc+":/"+i)
- backedup.append(i)
- print(" >%s is now up to date"%i)
- print()
- ##
- ## BACKUP CONTENTS UPDATE
- ##
- print("-------")
- print("The following directories were backed up:")
- for i in backedup:
- print(" "+i)
- print("-------")
- print("Flushing new backup contents to record")
- restamp(DriveLoc)
- filepath=glob.glob(DriveLoc+":/Backup Contents *.txt")[0]
- bcont=open(filepath,"w+")
- bcont.write(
- "\n".join(getFiles(DriveLoc+":/"))
- )
- bcont.close()
- print("Backup completed")
- input("Hit enter to exit"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement