autoDeploy/dumpRedis.sh
2025-02-25 21:52:14 +08:00

46 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 备份目录
BACKUP_DIR="/tmp/redisDumps"
# Redis持久化文件路径根据你的Redis配置文件进行调整
# 解析命令行参数
while [[ "$#" -gt 0 ]]; do
case $1 in
--dumpFile) REDIS_DUMP_FILE="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# 创建备份目录(如果不存在)
mkdir -p $BACKUP_DIR
# 执行Redis的BGSAVE命令来创建快照
redis-cli BGSAVE
# 等待持久化操作完成,可以使用 sleep 来等待几秒钟(视情况而定)
sleep 5
# 检查并重命名现有备份文件
if [ -f $BACKUP_DIR/dump2.rdb ]; then
echo "Removing existing dump2.rdb"
rm -f $BACKUP_DIR/dump2.rdb
fi
if [ -f $BACKUP_DIR/dump1.rdb ]; then
echo "Renaming dump1.rdb to dump2.rdb"
mv $BACKUP_DIR/dump1.rdb $BACKUP_DIR/dump2.rdb
fi
if [ -f $BACKUP_DIR/dump.rdb ]; then
echo "Renaming dump.rdb to dump1.rdb"
mv $BACKUP_DIR/dump.rdb $BACKUP_DIR/dump1.rdb
fi
# 复制新的dump.rdb到备份目录
echo "Copying new dump.rdb to $BACKUP_DIR"
cp $REDIS_DUMP_FILE $BACKUP_DIR/dump.rdb
echo "Backup completed successfully."