Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Having trouble with making a backup script for automatically updating the var folder to another server nightly

BDATE=`date +%F`
 rsync --exclude=foldera/folderb -bavz --backup-dir=backup-$(BDATE) root@someserver.com:/path/to/var

This doesn't seem to be working when I run it, have I done something wrong?

Cheers

share|improve this question

migrated from webmasters.stackexchange.com Jun 14 '11 at 13:22

This question came from our site for pro webmasters.

2 Answers 2

up vote 0 down vote accepted

At a first glance, your problem seems to be the --backup-dir flag. The $(BDATE) won't expand to the date. Just try this from a terminal:

BDATE="14-06-2011"

echo $BDATE --> 14-06-2011

echo foo-$(BDATE) --> DATE: command not found foo-

if you use this foo-$BDATE it will work: echo foo-$BDATE --> foo-14-06-2011

Also, can you please post the output if it still doesn't work?

share|improve this answer

$( ) is command substitution, like the backticks: `` If you are trying isolate a variable you use curly braces, e.g., ${foo}_bar will reference the var foo. In this case, $BDATE doesn't need any such isolation. FYI $(( )) is arithmetic evaluation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.