Skip to content

Instantly share code, notes, and snippets.

@zoranzaric
Created September 6, 2010 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoranzaric/eae6bb7a1dc25a26d65c to your computer and use it in GitHub Desktop.
Save zoranzaric/eae6bb7a1dc25a26d65c to your computer and use it in GitHub Desktop.
#!/bin/sh
# bup-import-rsnapshot.sh
# Does an import of a rsnapshot archive.
# testing wrapper function for bup
bup() {
echo "$@"
}
usage() {
echo "Usage: bup import-rsnapshot <path to rsnapshot's snapshot_root>"
exit -1
}
[ "$#" -eq 1 ] || usage
if [ ! -e "$1/." ]; then
echo "$1 isn't a directory!"
exit -1
fi
ABSPATH=`readlink -f "$1"`
for SNAPSHOT in "$ABSPATH/"*; do
if [ -e "$SNAPSHOT/." ]; then
for BRANCH_PATH in "$SNAPSHOT/"*; do
if [ -e "$BRANCH_PATH/." ]; then
# Get the snapshot's ctime
DATE=`stat -c %Z "$BRANCH_PATH"`
BRANCH=`basename "$BRANCH_PATH"`
# the echos are only for testing
bup index -ux \
--strip-path=\"$BRANCH_PATH\" \
\"$BRANCH_PATH/\"
bup save \
--strip-path=\"$BRANCH_PATH\" \
--date=\"$DATE\"\
-n \"$BRANCH\" \
\"$BRANCH_PATH/\"
fi
done
fi
done
@apenwarr
Copy link

apenwarr commented Sep 6, 2010

You shouldn't use "-d $filename"; use "-e $filename/." instead. Otherwise symlinks won't work as expected.

Rather than using the "echo" lines for testing, I recommend adding a shell function at the top: bup() { echo "$@" } or something like that. Otherwise it's not a very good test at all, because you're quoting a bunch of stuff differently than you would in real life.

Why do you need the readlink above? bup already knows how to handle symlinks nicely. Just make sure you use the $1/. trick.

Note that bup subcommands can be shell scripts; just put any script into bup/cmd/bup-import-rsnapshot and it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment