1

我正在尝试编写一个简单的备份脚本,它执行以下操作:

#!/bin/bash
#backupScript

mysqldump mysql -uxxxxx -pxxxxx Database1 Database2 | gzip > "MainWordPress.gz"

time_stamp = `date +%Y%m%d.%H%M`
file_name = 'backup-{$time_stamp}.tar.gz'
sources = 'DIR/ MainWordPress.gz'
tar -cvf file_name sources

rm MainWordPress.gz

cp file_name some/destination

但问题是它不喜欢:

./runBackup.sh: line 6: time_stamp: command not found
./runBackup.sh: line 7: file_name: command not found
./runBackup.sh: line 8: sources: command not found
tar: sources: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

我很困惑......

4

2 回答 2

7

删除等号周围的空格:

#!/bin/bash
#backupScript

mysqldump mysql -uxxxxx -pxxxxx Database1 Database2 | gzip > "MainWordPress.gz"

time_stamp=$(date +%Y%m%d.%H%M)
file_name="backup-${time_stamp}.tar.gz"
sources='DIR/MainWordPress.gz'
tar -cvf file_name sources

rm MainWordPress.gz

cp file_name some/destination
于 2013-10-30T16:49:46.337 回答
2

删除变量和之间的空格=

#!/bin/bash
#backupScript

mysqldump mysql -uxxxxx -pxxxxx Database1 Database2 | gzip > "MainWordPress.gz"

time_stamp=`date +%Y%m%d.%H%M`
file_name='backup-{$time_stamp}.tar.gz'
sources='DIR/ MainWordPress.gz'
tar -cvf file_name sources

rm MainWordPress.gz

cp file_name some/destination
于 2013-10-30T16:50:06.787 回答