增量式备份

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-15 22:36:09 +08:00
parent f9e76f61ac
commit 998fe390a8

View File

@ -36,14 +36,16 @@ 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}-incremental-${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-${LAST_POSITION}${CURRENT_POSITION}-${currentTime}.sql
zip ${backUpPath}/${dbName}-incremental-${LAST_POSITION}${CURRENT_POSITION}-${currentTime}.sql.zip ${backUpPath}/${dbName}-incremental-${LAST_POSITION}${CURRENT_POSITION}-${currentTime}.sql
rm ${backUpPath}/${dbName}-incremental-${LAST_POSITION}${CURRENT_POSITION}-${currentTime}.sql
#fi
# 更新上次备份的binlog文件名和位置
echo "$CURRENT_BINLOG $CURRENT_POSITION" > "last_backup.txt"
backup_files=()
find "$backUpPath" -wholename "${backUpPath}/${dbName}-incremental-*.sql.gz" -type f -print0 | while IFS= read -r -d '' file; do
find "$backUpPath" -wholename "${backUpPath}/${dbName}-incremental-*.sql.zip" -type f -print0 | while IFS= read -r -d '' file; do
file_date=$(stat -c %Y "$file")
current_time=$(date +%s)
if (( (current_time - file_date) > 86400 )); then