From 70e809657523bcda5b9d8164728e225d5e7aaac0 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Sat, 15 Jul 2023 22:21:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E9=87=8F=E5=BC=8F=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backUpIncremental.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/backUpIncremental.sh b/backUpIncremental.sh index d2e8b67..c138713 100755 --- a/backUpIncremental.sh +++ b/backUpIncremental.sh @@ -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