Skip to content

Commit 5a280d6

Browse files
Merge pull request #2514 from Juhibhojani/master
Backup Generator
2 parents 2f26dfa + dcd7425 commit 5a280d6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-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)

Backup Generator/readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Backup Generator
2+
3+
The "File Backup Script" is a Python script designed to create a backup of files from a source directory and store them in a destination directory. The script uses the shutil and os modules to perform file operations and timestamp the backup folders. Below are the details on how to use this script
4+
5+
# Working
6+
7+
In the backup_files function, you need to specify the source directory and destination directory:
8+
- Replace /path/to/source_directory with the path to the directory containing the files you want to back up.
9+
- Replace /path/to/destination_directory with the path to the directory where the backup files should be stored.
10+
11+
# Requirements
12+
13+
- os
14+
- shutil

0 commit comments

Comments
 (0)