brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: rsync --files-from copies exactly the files you list

Backup
~/tips/tip-rsync-files-from

rsync -a --files-from=list.txt /home/me/ backup:/backup/

Reads the list of files to transfer from a text file or from standard input.

Sometimes I don’t want a whole folder, just the twenty files I picked. Excluding everything else with filter rules gets tedious fast. rsync can take the list itself.

rsync -a --files-from=list.txt /home/me/ backup:/backup/

Every line in list.txt is a path relative to the source directory. A line like docs/notes.txt ends up as /backup/docs/notes.txt, so the folder structure comes along. A name with a trailing slash also sends the immediate contents of that directory. If the file is -, rsync reads the list from standard input:

find . -name '*.md' -print0 | rsync -a --from0 --files-from=- ./ backup:/notes/

--from0 means the names end with a null character instead of a newline, which keeps names with spaces or odd characters safe.

One caveat from the manual: -a does not imply -r when you use --files-from. If you want the contents of a listed folder all the way down, add -r yourself. Listing single files also doesn’t make their unlisted siblings eligible for deletion at the destination.

The manual also says that --dirs is implied by --files-from, and that the side effects of --files-from are not positional on the command line, so it does not matter where you put it. With --no-implied-dirs, the attributes of the implied directories from the source names are not included in the transfer.

Further reading: rsync manual

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql restic find "*.txt" restic stats tmutil verifychecksums /path/to/backup-item All Backup tips (45) All topics

Link