Advertisement
Fallen_Angel01134

Backup Script

Apr 12th, 2020
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import os
  2. from zipfile import ZipFile
  3. from datetime import datetime
  4.  
  5. working_directory = os.getcwd()
  6.  
  7.  
  8. def createFileName():
  9. now = datetime.now()
  10. dt_string = now.strftime("%Y-%m-%d-%H-%M")
  11. zipName = ("Inkbot-" + dt_string + ".zip")
  12. return zipName
  13.  
  14. def createZip(dirName):
  15. fileName = createFileName()
  16. with ZipFile(fileName, 'w') as zipObj:
  17.  
  18. for folderName, subfolders, filenames in os.walk(dirName):
  19. for filename in filenames:
  20.  
  21. filePath = os.path.join(folderName, filename)
  22.  
  23. zipObj.write(filePath)
  24. print("Backup Created")
  25.  
  26. def unZip(fileName):
  27. now = datetime.now()
  28. dt_string = now.strftime("%Y-%m-%d-%H-%M")
  29. print(os.getcwd())
  30. with ZipFile(fileName, 'r') as zipObj:
  31. zipObj.extractall('new_restore-'+ dt_string)
  32. print("Backup Restored")
  33.  
  34. def showZipped():
  35. zipped = []
  36. for file in os.listdir(os.getcwd()):
  37. if file.endswith('.zip'):
  38. zipped.append(os.path.join(file))
  39. print("which folder would you like to restore?")
  40. for x in range(len(zipped)):
  41. print("[" + str(x+1) + "]" + zipped[x])
  42. option= int(input("Choose a back up: "))
  43. fileName = zipped[option-1]
  44. unZip(fileName)
  45.  
  46. def menu():
  47. print("Hello!")
  48. while True:
  49. menu = int(input("""Pick an option:
  50. [1] Backup Immedietly
  51. [2] Schedule Backup
  52. [3] Restore
  53. [4] Exit
  54. """))
  55.  
  56. if menu == 1:
  57. # Zips the current file directory
  58. createZip('Inkbot')
  59.  
  60. elif menu == 2:
  61. # Schedules a balck up
  62. # Emily will do this
  63. pass
  64.  
  65. elif menu == 3:
  66. showZipped()
  67.  
  68. elif menu == 4:
  69. print("Enjoy your day!")
  70. break
  71.  
  72. else:
  73. print("That is not a valid option")
  74.  
  75. if __name__ == '__main__':
  76. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement