5
votes

I'm trying to scp a backup tgz file from one server to another every night. The backup script uses the following $date var just fine but when I modify it slightly for scp it breaks:

#!/bin/sh
date=`date +%Y-%m-%d`
rbfile=`/backups/$date_00h00.tgz`
scp $rbfile user@myserverip:

But the script dies with the error:

/backups/.tgz: No such file or directory

On a side note, I really should switch to rsync for better remote backups - the tgz files are at 3.5GB now. Any recommended tutorials?

1

1 Answers

4
votes

when using $date_00h00 you tell bash to use the variable named date_00h00, because letters, numbers and _ characters are allowed as variables names.

Enclose the variable name in {} and it will correct the problem :

rbfile=`/backups/${date}_00h00.tgz`