Skip to content

Service that periodically synchronizes 2 folders.

License

Notifications You must be signed in to change notification settings

Laroto/autofilesync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autofilesync

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.

Parameters

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.

Setting up & Running

To set up the Auto File Sync, follow these steps:

  1. Clone the repository to your local machine. git clone [email protected]:Laroto/autofilesync.git

  2. Start the synchronization:

    1. 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.
    2. Run as a periodic service
      1. Give permissions to the executable
        • sudo chmod +x autofilesync.py
      2. Run the setup script
        • python3 setup_autofilesync.py {source_dir} {replica_dir} {interval} {--dry-run}

Stopping the Sync

If using the service to run the auto file sync, you can simply terminate the running process by executing: python3 stop_autofilesync.py

Inspecting the Synchronization

Log levels

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

Visualizing Logs

Log File

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)

Console

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.

About

Service that periodically synchronizes 2 folders.

Topics

Resources

License

Stars

Watchers

Forks

Languages