Skip to content

Commit 9051877

Browse files
authored
Add files via upload
1 parent 832c2ea commit 9051877

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Backup Generator/backup_generator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import shutil
3+
import datetime
4+
5+
def backup_files(source_dir, destination_dir):
6+
"""
7+
Backup files from the source directory to the destination directory.
8+
:param source_dir: The directory containing the files to be backed up.
9+
:param destination_dir: The directory where the backup files will be stored.
10+
"""
11+
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
12+
backup_dir = os.path.join(destination_dir, f"backup_{timestamp}")
13+
14+
try:
15+
shutil.copytree(source_dir, backup_dir)
16+
print(f"Backup created successfully at {backup_dir}")
17+
except OSError as e:
18+
print(f"Error creating backup: {e}")
19+
20+
if __name__ == "__main__":
21+
# Replace these paths with the appropriate source and destination directories
22+
source_directory = "/path/to/source_directory"
23+
destination_directory = "/path/to/destination_directory"
24+
25+
backup_files(source_directory, destination_directory)

0 commit comments

Comments
 (0)