-
-
Save zoranzaric/eae6bb7a1dc25a26d65c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.