Auto File Sync is a Python-based tool designed to keep two directories synchronized on Linux systems.
It automatically copies new or modified files from a source directory to a replica directory at specified intervals. The sync process can be run either manually or periodically as a background service.
The following parameters can be configured for the auto file sync:
source_dir
: The directory from which files will be synced.replica_dir
: The directory to which files will be synced.interval
: The interval at which the sync process will be triggered.log_file
: The path to the file where the logs will be stored.
To set up the Auto File Sync, follow these steps:
-
Clone the repository to your local machine.
git clone [email protected]:Laroto/autofilesync.git
-
Start the synchronization:
- Run once
python3 autofilesync.py {souce_dir} {replica_dir} {--dry-run}
{--dry-run}
will execute all the logic but will not make any modifications to the files.
- Run as a periodic service
- Give permissions to the executable
sudo chmod +x autofilesync.py
- Run the setup script
python3 setup_autofilesync.py {source_dir} {replica_dir} {interval} {--dry-run}
- Give permissions to the executable
- Run once
If using the service to run the auto file sync, you can simply terminate the running process by executing:
python3 stop_autofilesync.py
There are 3 levels of verbosity in this program: ERROR, INFO, and DEBUG.
- The ERROR level shows messages where the program malfunctions
- The INFO level shows the operations that are being performed (eg: copy or remove)
- The DEBUG level shows detailed information in directory-level about the directory that is being worked on, what files are inside it, what files are about to be modified, etc
The outputs are stored in a log file, provided as an input parameter for the program to run. In this file, the logs only go to the INFO level (DEBUG logs will not be shown)
Alternatively, we can check the debug logs on the systemd level with
sudo journalctl -u sync.service
.
--tail {number of lines}
will show only the{number of lines}
most recent logs.-f
will follow the log, meaning that as new log messages arrive, they will be printed on the console.- These flags can be used in combination.