Skip to content

Commit 84d45bc

Browse files
committed
done with backend
1 parent a164a0b commit 84d45bc

File tree

7 files changed

+62
-0
lines changed

7 files changed

+62
-0
lines changed

backup_utility.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import shutil
3+
import datetime
4+
5+
def backup_files():
6+
# Prompt the user to enter the source folder
7+
source_folder = input("Enter the source folder: ")
8+
9+
# Verify that the source folder exists
10+
if not os.path.exists(source_folder):
11+
print("Source folder does not exist.")
12+
return
13+
14+
# Prompt the user to enter the destination folder
15+
destination_folder = input("Enter the destination folder: ")
16+
17+
try:
18+
# Create a timestamp for the backup folder name
19+
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
20+
backup_folder = os.path.join(destination_folder, f"backup_{timestamp}")
21+
22+
# Create the backup folder
23+
os.makedirs(backup_folder)
24+
25+
# Walk through the source folder and copy files to the backup folder
26+
for root, dirs, files in os.walk(source_folder):
27+
for file in files:
28+
source_path = os.path.join(root, file)
29+
destination_path = os.path.join(backup_folder, os.path.relpath(source_path, source_folder))
30+
shutil.copy2(source_path, destination_path)
31+
32+
print("Backup created successfully.")
33+
print("Backup location:", backup_folder)
34+
35+
except OSError as e:
36+
print("Error:", e)
37+
38+
# Run the backup_files function
39+
backup_files()
40+
41+
# Prompt the user for confirmation to continue
42+
while True:
43+
user_input = input("Do you want to perform another backup? (yes/no): ")
44+
if user_input.lower() == "yes":
45+
backup_files()
46+
elif user_input.lower() == "no":
47+
print("Thank you for using Python Folder Backup utility")
48+
break
49+
else:
50+
print("Invalid input. Please enter 'yes' or 'no'.")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<html>
2+
3+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<html>
2+
3+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

testsource/gewr.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<html>
2+
3+
</html>

testsource/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

0 commit comments

Comments
 (0)