写一个数据库备份脚本,备查:
#!/bin/bash DATE=$(date +%Y%m%d-%H:%M) DES=/config/database-backup MYSQL_U="root" MYSQL_P="xxxxx" MYSQL_H="127.0.0.1" if [ ! -d "$DES" ];then mkdir -p "$DES" fi /usr/bin/mysqldump -u$MYSQL_U -p$MYSQL_P -h $MYSQL_H --all-databases>"$DES/${DATE}.sql" find $DES -name "*.sql" -mtime +7 -exec rm -rf {} \;
然后写个计划任务调用:
# crontab -l
0 */2 * * * /bin/bash /config/back_cloudstack_mariadb.sh >/dev/null 2>&1