Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from zipfile import ZipFile
- from datetime import datetime
- working_directory = os.getcwd()
- def createFileName():
- now = datetime.now()
- dt_string = now.strftime("%Y-%m-%d-%H-%M")
- zipName = ("Inkbot-" + dt_string + ".zip")
- return zipName
- def createZip(dirName):
- fileName = createFileName()
- with ZipFile(fileName, 'w') as zipObj:
- for folderName, subfolders, filenames in os.walk(dirName):
- for filename in filenames:
- filePath = os.path.join(folderName, filename)
- zipObj.write(filePath)
- print("Backup Created")
- def unZip(fileName):
- now = datetime.now()
- dt_string = now.strftime("%Y-%m-%d-%H-%M")
- print(os.getcwd())
- with ZipFile(fileName, 'r') as zipObj:
- zipObj.extractall('new_restore-'+ dt_string)
- print("Backup Restored")
- def showZipped():
- zipped = []
- for file in os.listdir(os.getcwd()):
- if file.endswith('.zip'):
- zipped.append(os.path.join(file))
- print("which folder would you like to restore?")
- for x in range(len(zipped)):
- print("[" + str(x+1) + "]" + zipped[x])
- option= int(input("Choose a back up: "))
- fileName = zipped[option-1]
- unZip(fileName)
- def menu():
- print("Hello!")
- while True:
- menu = int(input("""Pick an option:
- [1] Backup Immedietly
- [2] Schedule Backup
- [3] Restore
- [4] Exit
- """))
- if menu == 1:
- # Zips the current file directory
- createZip('Inkbot')
- elif menu == 2:
- # Schedules a balck up
- # Emily will do this
- pass
- elif menu == 3:
- showZipped()
- elif menu == 4:
- print("Enjoy your day!")
- break
- else:
- print("That is not a valid option")
- if __name__ == '__main__':
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement