Program Documentation: Folder Synchronization Script (Test Task)
This Python program was developed to synchronize two directories - a source directory and a mirror directory - while maintaining an identical copy of the source directory's content in the mirror directory. It also provides logging functionality for synchronization operations and can be configured to execute synchronization at regular time intervals.
1. Log Initialization
The initialize_logging(log_file)
function is responsible for setting up the program's logging system. It defines the log format, detail level, and output handlers to log messages both to a log file and the console output.
2. Directory Synchronization
The folder_sync(source_folder, mirror_folder, sync_interval, log_file)
function performs the synchronization between the source and mirror directories. It uses an infinite loop to execute synchronization periodically based on the specified interval.
During each iteration of the loop, the program performs the following operations:
- Checks if the source and mirror directories exist and creates them if necessary.
- Recursively traverses the source directory to identify new files and directories.
- Copies new files and directories to the mirror directory.
- Updates existing files in the mirror directory if necessary.
- Removes files and directories from the mirror directory that no longer exist in the source directory.
- Logs all operations to the log file and console output.
3. Command-Line Interface Configuration
The start_sync()
function is responsible for setting up and parsing the command-line arguments provided by the user. It uses the argparse
module to define the necessary arguments for running the program:
source_folder
: The path to the source directory.mirror_folder
: The path to the mirror directory.interval_seconds
: The synchronization interval in seconds.log_file
: The path to the log file.
These arguments are parsed from the command line and passed to the folder_sync()
function to initiate the synchronization process.
Design Decisions:
-
Use of Standard Libraries: The program utilizes standard Python libraries such as
os
,shutil
,time
,logging
, andargparse
to avoid external dependencies and make the implementation simpler and more portable. -
Flexible Configuration: The program allows the user to specify the source and mirror directories, synchronization interval, and log file directly from the command line, providing a flexible and customizable user experience.
This script represents my tailored solution designed specifically to meet Veeam's needs for folder synchronization, showcasing both my technical proficiency and attention to detail.
I hope this solution meets your expectations and proves valuable to your organization. Thank you for considering my contribution. I look forward to the opportunity to work with you further.
I hope you like it! :D