Giter Club home page Giter Club logo

autosyncdir's Introduction

autosyncdir

A simple bash script which lets you automatically synchronize one or more directories to a target folder whenever files in the watched directories change.

This is a much more primitive variant of the lsyncd tool. Unlike lsyncd though, this script can also run in Cygwin terminal or in Git Bash on Windows.

Installation

  1. Download the autosyncdir.sh script to any directory on your PC. You can also do that by Git-cloning the whole project.
  2. The script relies on inotifywait and rsync. Parent directories of these programs need to be in the system PATH (see script's source code for more details).
  3. Put the script's directory to the system PATH, so that you can run it easily just by its name.

Usage

Simply run the script without any parameters in order to get the basic usage help.

Press Ctrl+C at any time to terminate the script.

On Windows, you will typically run the script from Git Bash ("a customized distro of MSYS2"; part of Git for Windows), or Cygwin terminal.

Ad-hoc script usage

You can run the script directly for an ad-hoc usage.

On Windows:

$ autosyncdir.sh 'c:\path\to\source_dir1\' 'c:\path\to\source_dir2\' 'c:\path\to\target_dir'
$ # an alternative with forward slashes:
$ # autosyncdir.sh c:/path/to/source_dir1/ c:/path/to/source_dir2/ c:/path/to/target_dir
# Starting the sync loop
# Syncing...
sending incremental file list

sent 98 bytes  received 12 bytes  220.00 bytes/sec
total size is 13  speedup is 0.12
# Waiting for changes...
===> Watching c:\path\to\source_dir1\ -r*.* for create, modify, delete, move
===> Watching c:\path\to\source_dir2\ -r*.* for create, modify, delete, move

On Linux:

$ autosyncdir.sh /path/to/source_dir1/ /path/to/source_dir2/ /path/to/target_dir
# Starting the sync loop
# Syncing...
sending incremental file list

sent 98 bytes  received 12 bytes  220.00 bytes/sec
total size is 13  speedup is 0.12
# Waiting for changes...
===> Watching /path/to/source_dir1/ -r*.* for create, modify, delete, move
===> Watching /path/to/source_dir2/ -r*.* for create, modify, delete, move

Persisted script usage

Usually, you will want to prepare another script where you can persist all what you need to synchronize.

Here is an example of such a script (name it e.g. sync_my_dirs.sh).

On Windows:

#!/bin/bash

# Starts to automatically watch and sync all my directories.

server_cfg='c:\server1\cfg'

autosyncdir.sh 'c:\project1\env\devel\' $server_cfg'\project1' &
autosyncdir.sh 'c:\project2\env\devel\' $server_cfg'\project2' &

wait

On Linux:

#!/bin/bash

# Starts to automatically watch and sync all my directories.

server_cfg=~/server1/cfg

autosyncdir.sh ~/project1/env/devel/ $server_cfg/project1 &
autosyncdir.sh ~/project2/env/devel/ $server_cfg/project2 &

wait

Passing custom options to inotifywait and rsync

You can override options which are passed by the script to inotifywait and rsync by setting environment variables as in the following example.

#!/bin/bash

# default: "-r" (recursive)
export INOTIFYWAIT_OPTS=" "

# WARNING: Be careful with the --delete option, as it will delete missing files in the target directory!
# default: "-avz" (archive, verbose, compress)
export RSYNC_OPTS="-avz --delete"

autosyncdir.sh /path/to/source_dir /path/to/target_dir

autosyncdir's People

Contributors

pbodnar 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.