[sf-lug] question about cp -al

Akkana Peck akkana at shallowsky.com
Tue Sep 20 09:54:05 PDT 2016


Alex Kleider writes:
> Googling "rsync --link-dest option explanation"
> I stumbled upon the following:
> https://jimmyg.org/blog/2007/incremental-backups-using-rsync.html
> and found it helpful.
> There's a tricky part in that if a relative path is specified, it must be
> relative to the destination, not to the current working directory.

Not related to --link-dest since I do my backups to a separately
mounted external disk, but this might be useful to people using
rsync for backups:

I have some files and directories I exclude from backups (who needs
to waste time and disk space backing up the Mozilla cache?) and I
also sometimes want to do "mini-backups" where I exclude a lot more.
I used to tear my hair out trying to come up with simple aliases to
do this, and gradually built up a zsh function to make it easy
(would probably work in bash too, I haven't checked). My current
backup functions look like this:

####################################################################
# Full and nearly-full backups.

dobackup() {
    if [[ $# -eq 0 || $1 == '' ]]; then
        echo "Back up to where?"
        return
    fi

    # Exclude files/dirs with these names from all backups, even full ones:
    fullexcludes=( Cache .cache LOG log core \
        'VirtualBox VMs' .config/chromium .googleearth/Temp \
        'you get the idea' )

    # Exclude these from "mini" backups (e.g. if low on backup disk space)
    moreexcludes=( '*.mp4' '*.img' '*.iso' .googleearth "..." )

    # Build up the excludes list:
    excludesflags=( )
    for ex in $fullexcludes; do
        excludesflags+="--exclude"
        excludesflags+="$ex"
    done

    if [[ $# -eq 2 && $2 == "mini" ]]; then
        echo "Mini backup to" $1
        for ex in $moreexcludes; do
            excludesflags+="--exclude"
            excludesflags+="$ex"
        done
    else
        echo "Full backup to" $1
    fi

    pushd ~
    echo sudo rsync -av --delete --delete-excluded "${excludesflags[@]}" ./ $1
    sleep 2
    sudo rsync -av --delete --delete-excluded "${excludesflags[@]}" ./ $1
    popd
}

#
# Usage: fullbackup target, e.g. fullbackup /mnt/backupdisk/username/
#
fullbackup() {
    dobackup "$1" full
}

minibackup() {
    dobackup "$1" mini
}

####################################################################

I'm not a shell scripting expert: there's probably some clever
way to get zsh to expand these excludes lists with "--excludes"
preceding each one without doing the loop, but this works even if
it's not elegant.

        ...Akkana




More information about the sf-lug mailing list