我正在为我们的网站编写备份脚本。它bzip
是网站的文档根目录,然后mysqldump
将数据库添加到备份目录中的文件中。
# this script is meant to be run as root user
# these are not hardcoded in the real script, just here for simplicity's sake
USERNAME="root"
PASSWORD="password"
HOSTNAME="localhost"
DATABASE="client"
# $BACKUP_PATH equals "~/website-backups/clientname.com/2015-02-04@12:16:00"
# $1 equals "/var/www/vhosts/clientname.com"
# this command runs fine, but the resulting file is 0 bytes
mysqldump -u$USERNAME -p$PASSWORD -h $HOSTNAME $DATABASE > $BACKUP_PATH/$(basename $1).sql
如果我只是运行mysqldump -uroot -ppassword -h localhost client > clientname.com.sql
,我会得到一个1.4 MB的正确SQL语句文件。
Here's a link to the Bash script on pastebin
为什么备份脚本中的mysqldump
命令生成一个长度为0字节的SQL文件?