Sign inSign up

insrch/rsync

By insrch

•Updated about 1 year ago

Docker Rsync Sync is a lightweight container for automated file sync over SSH using rsync and cron.

Image
Networking
Web servers
Operating systems
0

573

insrch/rsync repository overview

⁠Docker Rsync

Github page: https://github.com/insrchofsnrs/rsync-docker⁠

⁠Overview

Initially, I was looking for a ready-made solution but couldn't find one that met my needs, especially with support for ARM and a simple setup. So, I decided to create my own Docker image and share it for others who are also looking for an easy-to-use solution.

By specifying the folder with the SSH key for remote connection, the sync schedule, the remote folder path, along with the host and user details, your files will be copied to the folder on the host where the container is running.

This Docker image provides a lightweight, automated solution for synchronizing remote files using rsync over SSH. It is designed for scheduled sync operations using cron, ensuring that remote directories stay up to date without manual intervention.

⁠Features

  • Automated file synchronization using rsync.
  • Secure SSH authentication via private keys.
  • Customizable cron scheduling for periodic syncs.
  • PUID (User ID) and PGID (Group ID) set the file ownership for synchronized files. They ensure the files are written with the correct user and group permissions on the host system.
  • Lightweight Alpine-based image for minimal resource usage.

⁠Installation

⁠Running the Container
docker run -d \
  --name rsync \
  -v /path/to/local_folder:/data \
  -v /path/to/ssh_keys:/mnt/ssh_keys:ro \
  -e REMOTE_USER=user \
  -e REMOTE_HOST=host.com \
  -e REMOTE_PATH=/remote/directory \
  -e SSH_KEY_FILE=id_rsa \
  -e CRON_SCHEDULE="0 * * * *" \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Etc/UTC \
  --restart unless-stopped \
  insrch/rsync:latest

⁠Environment Variables

VariableDescriptionDefault
REMOTE_USERUsername for the remote serverRequired
REMOTE_HOSTRemote server addressRequired
REMOTE_PATHDirectory on the remote server to sync fromRequired
SSH_KEY_FILESSH private key filename that sould be used for remote connectionid_rsa
CRON_SCHEDULECron expression defining sync scheduleRequired
PUIDUser ID for file ownership during sync1000
PGIDGroup ID for file ownership during sync1000
TZTimezone for the container (e.g., UTC, Europe/London)UTC

⁠Usage Examples

⁠Basic Usage
docker run -d \
  -v ~/Downloads:/data:/data \
  -v ~/.ssh:/mnt/ssh_keys:ro \
  -e REMOTE_USER=ubuntu \
  -e REMOTE_HOST=192.168.69.12 \
  -e REMOTE_PATH=/home/ubuntu/downloads \
  -e SSH_KEY_FILE=id_rsa \
  -e CRON_SCHEDULE="0 2 * * *" \
  insrch/rsync:latest

This configuration syncs files from the remote directory every day at 2 AM.

⁠Using Docker Compose
services:
  rsync:
    image: insrch/rsync:latest
    container_name: rsync
    restart: unless-stopped
    volumes:
      - /local/data:/data
      - /path/to/ssh_keys:/mnt/ssh_keys:ro
    environment:
      - REMOTE_USER=user
      - REMOTE_HOST=example.com
      - REMOTE_PATH=/remote/directory
      - SSH_KEY_FILE=id_rsa
      - CRON_SCHEDULE=0 3 * * *
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC

This example sets up a sync at 3 AM daily using Docker Compose.

⁠Troubleshooting

⁠User / Group Identifiers

When using volumes (-v flags), permissions issues can occur between the host OS and the container. To avoid this, you can specify the user PUID and group PGID.

Make sure that any volume directories on the host are owned by the same user and group you specify. This will resolve any permission issues seamlessly.

For example, if PUID=1000 and PGID=1000, you can find your own identifiers by running the following command:

id your_user

Example output:

uid=1000(your_user) gid=1000(your_user) groups=1000(your_user)
⁠SSH Key Not Found

Ensure the SSH key is correctly mounted and the file exists:

ls -l /path/to/ssh_keys/
⁠Incorrect Permissions

If syncing fails due to permission errors, adjust ownership:

chown 1000:1000 /local/data -R
⁠Checking Logs

Use the following command to inspect the logs:

docker logs -f container_id

⁠Contributing

If you would like to contribute, feel free to submit a pull request or open an issue on GitHub.

Tag summary

Content type

Image

Digest

sha256:a75fcdb87…

Size

8.5 MB

Last updated

about 1 year ago

docker pull insrch/rsync