增量式备份

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-15 22:21:15 +08:00
parent 45b31ff8b1
commit 70e8096575

View File

@ -36,15 +36,21 @@ cd $backUpPath
# mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD -h $MYSQL_HOST $MYSQL_DATABASE > "$BACKUP_DIR/full_backup.sql"
#else
echo "docker exec maria /usr/bin/mysqlbinlog -u"${userName}" -p"${password}" -h"${host}" --start-position="${LAST_POSITION}" --stop-position="${CURRENT_POSITION}" "$LAST_BINLOG" > "${backUpPath}"/"${dbName}"-"${currentTime}".sql"
docker exec maria /usr/bin/mysqlbinlog -u${userName} -p${password} -h${host} --start-position=${LAST_POSITION} --stop-position=${CURRENT_POSITION} /var/lib/mysql/$LAST_BINLOG > ${backUpPath}/${dbName}-${currentTime}.sql
docker exec maria /usr/bin/mysqlbinlog -u${userName} -p${password} -h${host} --start-position=${LAST_POSITION} --stop-position=${CURRENT_POSITION} /var/lib/mysql/$LAST_BINLOG > ${backUpPath}/${dbName}-incremental-${currentTime}.sql
#fi
# 更新上次备份的binlog文件名和位置
echo "$CURRENT_BINLOG $CURRENT_POSITION" > "last_backup.txt"
# 获取备份文件列表
backup_files=($(find "$backUpPath" -name "$dbName-*.sql" -type f -printf "%f\n"))
backup_files=()
while IFS= read -r -d '' file; do
file_date=$(stat -c %Y "$file")
current_time=$(date +%s)
if (( (current_time - file_date) > 86400 )); then
backup_files+=("$file")
fi
done < <(find "$BACKUP_DIR" -name "$DB_NAME-*.sql.gz" -type f -print0)
# 打印备份文件列表
# 遍历数组,打印每个文件名
for file in "${backup_files[@]}"; do
echo "$file"
done
done