Back up only actual files in directory structure

backupsymlink

I want to backup my savegames:

+ /Library/Containers/com.doublefine.dfaosx/***
+ /Library/Containers/com.doublefine.dottosx/***

I initially wanted to do this as part of a larger rsync backup. However, because of some macOS sandbox insanity, the folders include dozens of symlinks that I don't want to backup up, and excluding these has proven difficult with rsync (see related question).

How can I backup only the valuable savegame files and exclude the symlinks, without explicitly specifying a lot of subfolders. I want to specify "Back up all real files under this root folder, excluding symlinks and subfolders that don't ultimately contain a real file".

I tried zip also, but it doesn't even seem to have an option to exclude symlinks. Can tar do it? It would be best if rsync can do it, but if not, any standard Unix tool would be acceptable.

The files I want to backup are as below. Of course I could specify them explicitly, but I want to learn a way to backup real files and ignore symbolic links without getting specific about it.

Library/Containers/com.doublefine.dfaosx/Container.plist
Library/Containers/com.doublefine.dfaosx/Data/Documents/BrokenAge/saves/*
Library/Containers/com.doublefine.dfaosx/Data/Library/Saved Application State/com.doublefine.dfaosx.savedState/*

The files in saves are called auto.sav, auto.cav, slot_1.sav, slot_2.sav and then some.

Example of symbolic links are (there are about 60 of these, most of which are irrelevant for the game, they are just created by default as a means of reaching some Library files):

Library/Containers/com.doublefine.dfaosx/Data/Library/ColorPickers

Best Answer

You can pass a list of file names to backup to tar by running find first:

cd ~/Library/Containers/
tar -T <(find com.doublefine.dfaosx -type f -print) -cvzf ~/dfaosx.tar.gz
tar -T <(find com.doublefine.dottosx -type f -print) -cvzf ~/dfaosx.tar.gz

If you prefer rsync it supports a --files-from option which more or less does the same as -T for tar.