This R script initializes and configures the drive_stats table in MariaDB for Backblaze HDD data analysis.
It automatically handles directory setup, configuration loading, database connection, table creation, indexing, and partitioning.
-
Automatic Directory Setup:
Createsinfile/,outfile/, andtmp/directories if they do not exist. -
Configurable Database Connection:
Loads connection parameters fromconfig.ymlfor flexible deployment. -
Table Creation:
Generates adrive_statstable with all major SMART attribute columns (normalized and raw) for Backblaze HDD reliability analysis. -
Indexing:
- Creates single-column indexes on critical fields such as:
date,serial_number,vendor,model,source_file,failure, etc.
- Adds composite indexes to accelerate analytic queries:
(model, date)(vendor, model, failure)(date, failure)
- Creates single-column indexes on critical fields such as:
-
Partitioning:
Automatically partitions the table bydatefrom April 2013 through December 2039, improving scalability and query performance on time-series workloads. -
Validation and Safety Checks:
Checks for existing indexes and partitions before creating new ones to ensure idempotent behavior.
-
MariaDB:
Running and accessible with user credentials provided inconfig.yml. -
R Environment:
Ensure R (≥4.0.0) is installed and accessible via command line or RStudio. -
Required R Packages:
install.packages(c( "RMariaDB", "tictoc", "stringr", "purrr", "dplyr", "lubridate", "yaml" ))