Skip to content

nchekwa/syncnow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

syncnow πŸš€

Small Bash script for fast file synchronization from the current working directory (pwd) to one or multiple remote hosts using rsync over ssh.
It is driven by a local config file called .syncnow πŸ“„.


1. What does syncnow do? πŸ€”

  • Syncs selected files/directories from the current directory (SYNC_DIR = pwd) to remote host(s).
  • Uses rsync over ssh (default port 22).
  • Requires a .syncnow file in the directory where you run the command.
  • Supports multiple destinations via SYNC_REMOTE_HOST="host1,host2" (comma-separated list).
  • By default trying to sync with hostname sync-remote-host which can be resolved via /etc/hosts or DNS. You can override this by setting SYNC_REMOTE_HOST.

2. Installation βš™οΈ

  1. Copy the script to /local/sbin (or any directory in your PATH):

    sudo curl --url https://raw.githubusercontent.com/nchekwa/syncnow/refs/heads/main/syncnow --output /usr/local/sbin/syncnow
    sudo chmod +x /usr/local/sbin/syncnow
  2. Make sure /usr/local/sbin is in your PATH:

    echo $PATH
  3. (Optional) Set up SSH keys for the remote host:

    syncnow --auth
  4. In your project directory create a .syncnow file:

    cd /path/to/project
    touch .syncnow
  5. Run synchronization:

    syncnow

    or without confirmation prompt:

    syncnow -y

3. The .syncnow file πŸ“„

The .syncnow file must exist in the directory where you run syncnow.
If it is missing, the script aborts execution.

Example configuration:

# Remote SSH user
SYNC_REMOTE_USER="deploy"

# Single or multiple hosts (comma-separated list)
SYNC_REMOTE_HOST="192.168.1.10,192.168.1.11"

# SSH port
SYNC_REMOTE_PORT="22"

# Target path on remote host (by default can be same as local SYNC_DIR)
SYNC_REMOTE_PATH="/var/www/project"

# Files/directories to sync (example)
SYNC_SOURCE_ITEMS=("src" "config" "docker-compose.yml")

# Whether to include .syncnow in the synced items (Y/N)
SYNC_DOTSYNC_CONFIG="Y"

4. ENV / variables behavior 🌱

  • The script loads .syncnow as ENV:

    set -a
    source "$SYNC_DIR/.syncnow"
    set +a
  • All variables from .syncnow become available in the script environment.

  • Key variables:

    • SYNC_DIR – always pwd (directory from which syncnow is executed).
    • SYNC_REMOTE_USER – SSH user.
    • SYNC_REMOTE_HOST – single host or comma-separated list of hosts.
    • SYNC_REMOTE_PORT – SSH port (currently rsync uses port 22 directly; this variable is ready for future extension).
    • SYNC_REMOTE_PATH – target directory on the remote host(s).
    • SYNC_SOURCE_ITEMS – array of files/directories to sync.
    • SYNC_DOTSYNC_CONFIG – whether to include .syncnow in the synced items list.

5. How it works (flow) πŸ”

  1. You run syncnow in your project directory.
  2. The script:
    • requires .syncnow to exist,
    • SYNC_DIR is your pwd by default,
    • loads variables from .syncnow,
    • builds the host list from SYNC_REMOTE_HOST (supports comma-separated list),
    • checks DNS/host resolution for each host (getent hosts),
    • asks for confirmation (unless -y is used),
    • runs rsync for each item in SYNC_SOURCE_ITEMS to each configured host.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages