Giter Club home page Giter Club logo

folder-sync's Introduction

Synchronize two folders

version_badge

Synchronize two folders: source and replica. Keep a full, identical copy of source folder at replica folder.

Contents

Requirements

  • python>=3.9
  • python-crontab ( if you want to use cronjobs instead of using the while cycle)

Setup

# 1.
conda create -n myenv python=3.9 -y
conda activate myenv

# 2.1.
# Clone repo
git clone https://github.com/AndreGraca98/folder-sync.git
pip install python-crontab
python setup.py install

# OR

# 2.2.
# Install package
pip install git+https://github.com/AndreGraca98/folder-sync.git

# 3.
# If $HOME/bin/ is not in the $PATH add it in the ~/.bashrc and reload terminal
printf "export "PATH="\$HOME/bin:\$PATH\n\n\n" >> ~/.bashrc
source ~/.bashrc

Usage

❗IMPORTANT❗: After setup it is possible to use this tool as a command instead of calling python. Use sync-folders ... from anywhere in the system instead of python main.py ...

usage: main.py [-h] {cronjob,inf-loop,run-once} ...

Syncronize files between two directories

positional arguments:
  {cronjob,inf-loop,run-once}
    cronjob             Syncronize files between two directories using a cronjob
    inf-loop            Syncronize files between two directories using an infinite loop
    run-once            Syncronize files between two directories

options:
  -h, --help            show this help message and exit

1. Sync folders once

python main.py run-once --src /path/to/folder --dst /path/to/new/folder --log-file ./sync.log 
usage: main.py run-once [-h] --src SRC --dst DST [--log-path LOG_FILE] [--log-lvl LOG_LEVEL]

optional arguments:
  -h, --help            show this help message and exit
  --src SRC             Source directory
  --dst DST             Destination directory
  --log-path LOG_FILE, --log-file LOG_FILE
                        Log file path
  --log-lvl LOG_LEVEL, --log-level LOG_LEVEL
                        Log level
  -d, --dry-run         Dry run the syncronization

2. Sync folders using a while loop

python main.py inf-loop --src /path/to/folder --dst /path/to/new/folder --log-file ./sync.log --interval 3600 
usage: main.py inf-loop [-h] --src SRC --dst DST [--log-path LOG_FILE] [--log-lvl LOG_LEVEL] [--interval SYNC_INTERVAL]

optional arguments:
  -h, --help            show this help message and exit
  --src SRC             Source directory
  --dst DST             Destination directory
  --log-path LOG_FILE, --log-file LOG_FILE
                        Log file path
  --log-lvl LOG_LEVEL, --log-level LOG_LEVEL
                        Log level
  --interval SYNC_INTERVAL, --sync-interval SYNC_INTERVAL
                        Sync interval in seconds. Defaults to 3600 seconds.
  -d, --dry-run         Dry run the syncronization

3. Sync folders using cronjobs

python main.py cronjob --src /path/to/folder --dst /path/to/new/folder --log-file ./sync.log --interval "@hourly" 
usage: main.py cronjob [-h] --src SRC --dst DST [--log-path LOG_FILE] [--log-lvl LOG_LEVEL] [--interval SYNC_INTERVAL]

optional arguments:
  -h, --help            show this help message and exit
  --src SRC             Source directory
  --dst DST             Destination directory
  --log-path LOG_FILE, --log-file LOG_FILE
                        Log file path
  --log-lvl LOG_LEVEL, --log-level LOG_LEVEL
                        Log level
  --interval SYNC_INTERVAL, --sync-interval SYNC_INTERVAL
                        Sync interval in cron format. Defaults to @hourly.  
  -d, --dry-run         Dry run the syncronization

Project requirements

  • Synchronization must be one-way: after the synchronization content of the replica folder should be modified to exactly match content of the source folder
  • Synchronization should be performed periodically
  • File creation/copying/removal operations should be logged to a file and to the console output
  • Folder paths, synchronization interval and log file path should be provided using the command line arguments
  • It is undesirable to use third-party libraries that implement folder synchronization
  • It is allowed (and recommended) to use external libraries implementing other well-known algorithms. For example, there is no point in implementing yet another function that calculates MD5 if you need it for the task – it is perfectly acceptable to use a third-party (or built-in) library

TODO

  1. something
  2. other thing

folder-sync's People

Contributors

andregraca98 avatar

Stargazers

Trash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.