File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments