Skip to content

Instantly share code, notes, and snippets.

@grmartin
Created April 17, 2018 00:27
Show Gist options
  • Save grmartin/db50c079332865d9d93dcb98ad0517f2 to your computer and use it in GitHub Desktop.
Save grmartin/db50c079332865d9d93dcb98ad0517f2 to your computer and use it in GitHub Desktop.
Basic Rsync sync with Password Entry

Basic Rsync sync with Password Entry

Tested on MacOS against a Linux Mint Server with an rsyncd share.

Server Side

The Configuration for the (Linux server) Daemon once can be found in rsyncd.conf, and requires you create /etc/rsyncd.scrt containing the username and password pairs... The secrets file must not be world readable and only accessible by the daemon that runs rsync.

On Mint, You can start rsync via Systemd using:

# systemctl start rsync

Note: Systemd script is rsync or rsyncd depending on distro, and status of the script (reason for failure) can be found by executing systemctl status rsync.

'Client' Side

The execution script is written in tcl for the expect program and can be found in sync_rsync.tcl.

Please substitute username, IP address and password to fit your needs.

You can run this like any shell script by making it executable (chmod a+x sync_rsync.tcl).

log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[Media]
path = /media/media
uid = root
gid = root
read only = yes
list = yes
auth users = glenn
secrets file = /etc/rsyncd.scrt
use chroot = yes
#!/usr/bin/expect -f
# vim: ft=tcl:syntax=tcl
# Does not use SSH, meant only for local in-home networks... Not very secure, but functional...
# Traps and re-emits CTRL+C as well. Tested on MacOS against a Linux Mint Server with an rsyncd share
set SERVER {192.168.0.108}
set RSYNC_USER {glenn}
set OUT_DIR {/Volumes/Rede/Plex/Media}
set PASSWORD {MyPassword}
set ACCESS_POINT {Media}
trap {
send \x03
send_user "Ctrl+C Caught, emitting.\n"
} SIGINT
spawn rsync -avz --delete [format {%s@%s::%s} $RSYNC_USER $SERVER $ACCESS_POINT] $OUT_DIR
expect {Password:}
send "$PASSWORD\n"
expect eof
if {[catch wait]} {
puts {rsync failed}
exit 1
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment