Issue with a bash script

Hi,

I’m trying to use restic via the following bash script

#!/bin/bash

# Repo and PW
export RESTIC_REPOSITORY=/media/thomas/USB-Backup1/backup
export RESTIC_PASSWORD=password_here

#What to backup
backup_path=~/Documents ~/Desktop ~/Calibre-Library

#Start Restic
restic -r $RESTIC_REPOSITORY backup $backup_path
restic -r $RESTIC_REPOSITORY forget --keep-last 1 --prune

but get a Fatal: wrong number of parameters for the PATH.
Using the path to more than one dir in the shell works though. Anything i’m missing?

Thanks

Why not put the backup_path folders in quotes (backup_path="~/Documents ~/Desktop ~/Calibre-Library")?

Edit: Screwed up the syntax, fixed.

hmm, then I get

Fatal: all target directories/files do not exist

The variable backup_path is not set in the script. Consider the following line:

backup_path=~/Documents ~/Desktop ~/Calibre-Library

bash thinks that it should call the command ~/Desktop with the argument ~/Calibre-Library and the environment variable foo set to the value ~/Documents. It should also print an error. The following shell script demonstrates this:

#!/bin/bash
foo=~/x ~/y ~/z
echo "foo: $foo"

Running it yields:

$ ./x.sh
./x.sh: line 3: /home/fd0/y: No such file or directory
foo:

Did you see an error?

I’d suggest listing the files/dirs to backup directly after the restic backup command. Otherwise you’ll need to fight with bash until the quoting etc. is right. And that may take some time, good luck :slight_smile:

Thanks, I’ll try my best :slight_smile:

@thob With the following script, are you sure that all the listed folders (~/Documents, ~/Desktop and ~/Calibre-Library) actually exist?

#!/bin/bash

# Repo and PW
export RESTIC_REPOSITORY=/media/thomas/USB-Backup1/backup
export RESTIC_PASSWORD=password_here

#What to backup
backup_path="~/Documents ~/Desktop ~/Calibre-Library"

#Start Restic
restic -r $RESTIC_REPOSITORY backup $backup_path
restic -r $RESTIC_REPOSITORY forget --keep-last 1 --prune

Oh yes, they exist. fd0 solution works.

  1. Aug 2017 21:14 von noreply@forum.restic.net:

If you want to keep your backup_path variable rather than adding the directories in your backup command (so you can reuse it as you expand your script) you might want to quote the value. Don’t quote the variable in your backup command though.

backup_path=“~/Documents ~/Desktop ~/Calibre-Library”

restic -r $RESTIC_REPOSITORY backup $backup_path

And I just noticed you already tried that:

Does it work if you add a “/” after each directory? (~/Documents/)

will try this tonight, thanks for the input

Thinking about it, it actually looks like restic wants each directory separate, so when it’s passed as one argument in quotes it assumes that is the whole path rather than a string made up of multiple paths. Is this right @fd0 ?