Skip to content

Instantly share code, notes, and snippets.

@gzxu
Last active May 24, 2024 19:57
Show Gist options
  • Save gzxu/614d845aea0e6109f406b5d71edd0175 to your computer and use it in GitHub Desktop.
Save gzxu/614d845aea0e6109f406b5d71edd0175 to your computer and use it in GitHub Desktop.
Run rsync server on Android Termux

Usually we will use this command

rsync --dry-run -a --mkpath --no-o --no-g --no-p -P -c SRC/ DST/

Remove --dry-run to actually copy the files rather than merely comparing

Remove -c to make it faster by comparing mod-time and size rather than checksum

--archive, -a             archive mode; equals -rlptgoD (no -H,-A,-X)
--mkpath                  create the destination's path component
-P                        same as --partial --progress

--recursive, -r           recurse into directories
--links, -l               copy symlinks as symlinks
--times, -t               preserve modification times
--owner, -o               preserve owner (super-user only)
--group, -g               preserve group
--perms, -p               preserve permissions
-D                        same as --devices --specials

--devices                 preserve device files (super-user only)
--specials                preserve special files

--partial                 keep partially transferred files
--progress                show progress during transfer

The above command can be simplified as

rsync --dry-run -rlt --mkpath -P -c SRC/ DST/

You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name"

Examples:

  • rsync --dry-run -a --mkpath --no-o --no-g --no-p -P -c rsync://192.168.43.1:8873/sdcard/DCIM/Camera/ ./
  • rsync --dry-run -a --mkpath --no-o --no-g --no-p -P -c rsync://192.168.43.1:8873/sdcard/Pictures/Screenshots/ ./
  • Other necessary directories
# mkdir -p /data/data/com.termux/files/usr/var/run
# mkdir -p /data/data/com.termux/files/usr/var/log
rsync --daemon --config=rsyncd.conf --no-detach

在 Windows 上的步骤为

  1. 建立防火墙规则,允许 8873 端口入站
  2. 创建文件如下 C:\Users\User\Downloads\rsyncd.conf
port = 8873
use chroot = false
munge symlinks = false
read only = false
open noatime = true

[upload]
path = /mnt/d/rsync
list = true
open noatime = false
  1. 启动服务
rsync --daemon --no-detach --config=/mnt/c/Users/User/Downloads/rsyncd.conf
pid file = /data/data/com.termux/files/usr/var/run/rsyncd.pid
log file = /data/data/com.termux/files/usr/var/log/rsyncd.log
lock file = /data/data/com.termux/files/usr/var/run/rsyncd.lock
port = 8873
use chroot = false
munge symlinks = false
read only = true
open noatime = true
[sdcard]
path = /sdcard
list = true
open noatime = false
# [more necessary directories can be added here]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment