Jumpserver高可用集群部署:MariaDB及Redis数据库定时备份

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jumpserver高可用集群部署:MariaDB及Redis数据库定时备份相关的知识,希望对你有一定的参考价值。

1、编写MariaDB及Redis数据库备份脚本

vi /sas/jumpserver/tools/db-backup.sh

#!/bin/bash

MariadbPath=/sas/db-backup/mariadb/
RedisPath=/sas/db-backup/redis/
SaveDays=7

echo "[$(date +"%Y-%m-%d %H:%M:%S")] ============ Start database backup task ============" &>> /var/log/db-backup.log

# mariadb backup
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Start mariadb backup task ..." &>> /var/log/db-backup.log

mysqldump -uroot -pXXXXXXXX jumpserver >$MariadbPath$(date +"%Y%m%d-%H%M%S").sql

if [ $? -eq 0 ]; then
    # only delete old backup files when new backup success !

    ExistBackupFiles=`ls $MariadbPath | wc -l`
    if [ $ExistBackupFiles -gt $SaveDays ]; then

        # only delete old backup files when exist backup files more then 7 days !
        # mariadb backup files clean

        echo "[$(date +"%Y-%m-%d %H:%M:%S")] Start mariadb backup files clean task ..." &>> /var/log/db-backup.log

        find $MariadbPath -type f -mtime +$SaveDays | xargs rm -rvf &>> /var/log/db-backup.log      

        echo "[$(date +"%Y-%m-%d %H:%M:%S")] Mariadb backup files clean task finished ! " &>> /var/log/db-backup.log
    fi
fi

echo "[$(date +"%Y-%m-%d %H:%M:%S")] Mariadb backup task finished ! " &>> /var/log/db-backup.log

# redis backup
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Start redis backup task ..." &>> /var/log/db-backup.log

redis-cli -a xxxxxxxx SAVE &>> /var/log/db-backup.log
cp -v /ssd/redis/dump.rdb $RedisPath$(date +"%Y%m%d-%H%M%S").rdb &>> /var/log/db-backup.log

if [ $? -eq 0 ]; then

        # only delete old backup files when new backup success !

        ExistBackupFiles=`ls $RedisPath | wc -l`
        if [ $ExistBackupFiles -gt $SaveDays ]; then

                # only delete old backup files when exist backup files more then 7 days !
                # redis backup files clean

                echo "[$(date +"%Y-%m-%d %H:%M:%S")] Start redis backup files clean task ..." &>> /var/log/db-backup.log

                find $RedisPath -type f -mtime +$SaveDays | xargs rm -rvf &>> /var/log/db-backup.log

                echo "[$(date +"%Y-%m-%d %H:%M:%S")] Redis backup files clean task finished ! " &>> /var/log/db-backup.log
        fi
fi

echo "[$(date +"%Y-%m-%d %H:%M:%S")] Redis backup task finished ! " &>> /var/log/db-backup.log

# 添加执行权限
chmod +x /sas/jumpserver/tools/db-backup.sh

2、配置计划任务

vi /etc/crontab

# database backup task
0 2 * * * root /sas/jumpserver/tools/db-backup.sh

以上是关于Jumpserver高可用集群部署:MariaDB及Redis数据库定时备份的主要内容,如果未能解决你的问题,请参考以下文章

Jumpserver高可用集群部署:RDP代理模块guacamole部署并实现系统服务管理

jumpserver篇--安装(高可用性 mariadb+haproxy)

Jumpserver双机高可用环境部署笔记

部署mariadb高可用

部署mariadb高可用

MariaDB高可用架构之MHA