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