Rsync – Exclude AppData but Include Firefox Bookmarks

cygwin;rsync

I want to backup my Windows home directory using cygwin and rsync:

rsync.exe -vrt --delete --exclude=AppData "/cygdrive/C/Users/user1/" "/cygdrive/D/backup/"

As you can see I excluded the AppData directory.

Is it possible to include my Firefox bookmarks in the following path?

AppData/Roaming/Mozilla/Firefox/Profiles/*/places.sqlite

The asterisk stands for a the profile name. It's not known because Firefox generates random names there.

Maybe it's possible using an exclude script with –exclude-from?

I know it's possible to copy the places.sqlite to another folder using power shell and then backup this folder.

But maybe it's possible directly with rsync.

Best Answer

This is pretty much a duplicate of rsync: Use filters to exclude top-level directory but include some of its subdirectories.

You need to include the AppData folder tree for searching to that you can find places.sqlite, but exclude everything except that file.

rsync --dry-run -av --prune-empty-dirs \
    --include '/AppData/Roaming/Mozilla/Firefox/Profiles/*/places.sqlite' \
    --include '*/' \
    --exclude '/AppData/***' \
    '/cygdrive/C/Users/user1/' '/cygdrive/D/backup/'

The --prune-empty-dirs stops the destination being filled with directories that would otherwise remain empty, so that rsync creates only the directories it needs to hold the files it's copying. (It's a little strange that this isn't the default action, but it isn't.)

On my system, places.sqlite was under Profiles/* rather than Profile/* so I've adjusted my suggested command accordingly. As you might expect, remove --dry-run when you're happy with the result.

Related Question