简体   繁体   中英

Rsync files from remote using find

I would like to synchronize remote files with local directory. Files must be from today 0AM. I tried to download files with this command, but this method does not work. How can I achieve my goal?

ssh user@192.168.1.100 'find /home/user/test/ -mtime -1 -type f' | rsync --archive --verbose -zz --human-readable --rsh='ssh user@192.168.1.100:/home/user/test/' '/e/rc/'

/e/rc/ is my local windows directory - script is launched from git bash console (find and rsync are avaible)

Your commands have 2 problems
1) ssh password is constantly asked so made 2 separated commands to list and copy.
2) Items in list contains /home/user/test which rsync will try to copy to /home/user/test/home/user/test, throwing an error. Files basename is needed.

# we need to get file basename since rsync+ssh will copy with respect to user home
files=$(ssh user@192.168.0.10 "find /home/user/test/ -mtime -1 -type f -exec basename {} ';'")
# do the actual copy reading list of files-from stdout
echo "$files" | rsync -avz --files-from=- user@192.168.0.10:test/ '/e/rc/'

I don't use git bash so if $(...) expression does not work try to use backticks or use a full fledged bash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM