Hi I want to rsync data but not including some files. There are some security files in the root folder .name.cfg.lXrMLc, name.cfg.FT3uKg, name.cfg.pQ82bS, etc that I don't need, seem like the pattern start with name.cfg. following by different id. I tried rsync --exclude=.*name.cfg
, --exclude=.*name.cfg.*
--exclude=*.name.cfg.*
but non of these work. What's the right pattern for exclude?
'*name.cfg*'
should work.
What I see in the question is that there is always a dot in front of the name next to the exclude option, but there is no dot for two of the mentioned examples. Wrapping the exclude statement in quotation marks may be helpful as well in some cases. As an additional tip for handling a backup script with a list of files to exclude, we could split it into a backup script file and an exclude list file.
E.g. backup.sh
#!/bin/bash
# `/<dir>/` > Content of directory will be saved
# `/<dir>` > Directory will be saved
SOURCES="/path/to/be/backed/up"
TARGET="/path/to/backup/location/"
EXCLUDE="--exclude-from=exclude.lst"
RSYNCCONF="--delete"
LOGFILE="--log-file=backup.log"
RSYNC=`which rsync`
$RSYNC -avrpuE $RSYNCCONF $SOURCES $TARGET $EXCLUDE $LOGFILE
exit 0
and the exclude.lst
that is specified in the script above could look like:
*node_modules
*test-ledger
*target/*
*.vscode-test
*name.cfg*
etcetera.
Of course this is just one way of handling things but I hope this helps.