-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.py
64 lines (61 loc) · 2.42 KB
/
backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Created by Kyle Goetke
# v0.4 - April 23, 2022
import win32api
import time
from datetime import datetime
import subprocess
import sys
import os
target_drive = "E:\\"
print("--------")
print(f"{target_drive} not located. Waiting for drive.")
print("--------")
while True:
time.sleep(3)
drive_list = win32api.GetLogicalDriveStrings()
drive_list = drive_list.split("\x00")[0:-1] # the last element is ""
#? print("Checking drives:")
#? time.sleep(1)
for letter in drive_list:
drive = "{0}".format(letter)
if drive != target_drive:
#? print(" ", drive)
#? time.sleep(1)
continue
elif drive == target_drive:
#? print(" ", drive)
#? time.sleep(0.25)
user_check = input(f"\nDo you want to copy from {drive} (Y/N)?\n> ").upper()
if user_check[0] == "Y":
src_path = f"{drive}"
now = datetime.now()
current_time = now.strftime("%b_%d_%Y_%H_%M") # 24 hr time
#? current_time = now.strftime("%b_%d_%Y_%I_%M_%p") # 12 hr time
custom_path = input("\nWould you like to name the destination folder (Y/N)?\n> ").upper()
if custom_path[0] == "Y":
custom_path = input("\nEnter folder name:\n> ")
dest_path = f"D:\\{custom_path}_{current_time}\\"
else:
dest_path = f"D:\\NEW_BACKUP_{current_time}\\"
try:
robocopy_output = subprocess.call(f"robocopy {src_path} {dest_path} /E /V /COPYALL /DCOPY:DAT /R:10 /W:5", shell=True)
if robocopy_output != 1:
print("\nError encountered:", robocopy_output, file=sys.stderr)
print("")
else:
print("Robocopy returned:", robocopy_output, file=sys.stderr)
except OSError as e:
print("Execution failed:", e, file=sys.stderr)
else:
os.system("cls")
print("\n--------")
print("E:\\ not located. Waiting for drive.")
print("--------")
else:
print("BIG ISSUE!!!")
print("Detected drive {drive} caught by else")
#? print("All drives checked.")
#? time.sleep(1)
#? print("Starting new check in 15 seconds.")
#? time.sleep(3)
#? print("--------")