#!/bin/sh

# Database info
DB_USER="USERNAMExxx"
DB_PASS="PASSWORDxxx"
DB_HOST="localhost"
DB_NAME="DBNAMExxx"

# Others vars
BIN_DIR="/usr/bin"            #the mysql bin path
BCK_DIR="/xxx/xxx/xxx"    #the backup file directory
DATE=`date +"%F %T"`   #date+time

$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME > $BCK_DIR/gnucash_db5_$DATE.sql

#还原数据库
#用mysql-front导入前一天的 *.sql 文件即可恢复数据

另存为.sh文件,修改好账号密码及路径,记得chmod +x给权限,设置计划任务即可。