Search code examples
rsync

Rsync Excluding folders


I am running a rsync script and I want to exclude certain folders. I know with rsync you have to create a .txt file and add all the excludes in there but I am wondering is it possible to just have a global string in the script that includes all the excludes I want and then just added that global into the rsync command?

Global String Example

ROOT_EXCLUDE="--exclude=/dev --exclude=/proc --exclude=/sys --exclude=/temp --exclude=/run --exlucde=/mnt --exlcude=/media

Rsync Command

rsync -au --exclude 'ROOT_EXCLUDE' /Users/Me/Home /Users/me/Backup

Solution

  • Take a look at /etc/environment and setup your constant here. I haven't tested, but it might work how you had shown above. Please update if you figure it out.

    Or if you want a super quick hacky method this might work, too. Create a bash script like below. It kind of accomplishes your initial goal (except you're storing your constant in a bash file instead)

    echo "dev
    proc
    sys
    temp
    run
    mnt
    media
    " >> ~/exclude.txt
    rsync -auvr --exclude-from '~/exclude.txt' /Users/Me/Home /Users/me/Backup
    rm ~/exclude.txt