Search code examples
amazon-s3centosbackuprestoreduplicity

Duplicity: Restore with spaces in directory names


I'm attempting to restore a file using a duplicity wrapper script (duplicity-restore.sh), contents below:

#!/bin/bash
# Export some ENV variables so you don't have to type anything
export AWS_ACCESS_KEY_ID="AWS_KEY"
export AWS_SECRET_ACCESS_KEY="AWS_Secret_key"
export PASSPHRASE="######"

# Your GPG key
GPG_KEY=######

# The destination
DEST="s3://s3.amazonaws.com/<path-to-bucket>"

if [ $# -lt 3 ]; then echo "Usage $0 <date> <file> <restore-to>"; exit; fi

duplicity \
--encrypt-key=${GPG_KEY} \
--sign-key=${GPG_KEY} \
--file-to-restore $2 \
--restore-time $1 \
${DEST} $3

# Reset the ENV variables. Don't need them sitting around
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export PASSPHRASE=

I'm having difficulty restoring files that are stored in directories with spaces in their names. I've tried the following:

No quotes or escape slashes:

./duplicity-restore.sh "2018-02-08" dir1/dir2/dir name with spaces/filename.txt /destination/

Above results in error "dir1/dir2/dir not found in archive - no files restored."

Quoting the entire path argument:

./duplicity-restore.sh "2018-02-08" "dir1/dir2/dir name with spaces/filename.txt" /destination/

Above results in error "Expected 2 args, got 15"

Quoting only the directory with spaces in the name:

./duplicity-restore.sh "2018-02-08" dir1/dir2/'dir name with spaces'/filename.txt

Above results in error "Expected 2 args, got 15"

Escape slashes next to each space in directory name:

./duplicity-restore.sh "2018-02-08" dir1/dir2/dir\ name\ with\ spaces/filename.txt /destination/

Above results in error "Expected 2 args, got 15"

It seems that, no matter how I try to escape the spaces in my directory names, Duplicity treats each space as a separate argument. The file I'm trying to restore is several directories deep, and ALL of the directories contain spaces in their names.

Duplicity version is 0.7.17, running on CentOS 7 and backing up to an Amazon S3 bucket.


Solution

  • that's a bug in your wrapper shell script, not in duplicity. if you want an argument to be kept treated as one you will have to rewrap it in quotes.

    duplicity ... --file-to-restore "$2" ...
    

    ..ede/duply.net