SnapDisk is a small Java 21 Swing desktop app that takes one daily snapshot of disk space, stores timestamped records in PostgreSQL, and shows a table + a simple chart of used space over time.
src/— Java source (packages:com.snapdisk.app,db,dao,model,util,tools)lib/— third-party jars (Postgres JDBC, optional JFreeChart)bin/— compiled classes (output)schema.sql— example DB schema
- Java 21
- PostgreSQL JDBC driver (place
postgresql-*.jarinlib/) - JFreeChart jars are optional (put them in
lib/if you want advanced charting)
Compile all sources from the project root (handles spaces in the path):
mapfile -t JAVA_FILES < <(find src -name '*.java' -print0 | xargs -0 -n1 echo)
javac -d bin -sourcepath src -cp "lib/*" "${JAVA_FILES[@]}"- Quick launcher (preferred):
java -cp "bin:lib/*" com.snapdisk.app.Launcher- Or use the helper script that compiles and runs with
--no-dbsupport:
./run.sh --no-db # shows UI with sample dataRun these commands as a Postgres superuser to create the role, database and table used by the app. Adjust passwords as needed.
# create role
psql -U postgres -c "CREATE ROLE snapdisk_user LOGIN PASSWORD 'password';" || true
# create database owned by role
psql -U postgres -c "CREATE DATABASE snapdisk OWNER snapdisk_user;" || true
# create table and grant privileges
psql -U postgres -d snapdisk <<'SQL'
CREATE TABLE IF NOT EXISTS public.disk_snapshots (
id SERIAL PRIMARY KEY,
snapshot_date DATE NOT NULL UNIQUE,
snapshot_time TIME NOT NULL,
total_space BIGINT NOT NULL,
free_space BIGINT NOT NULL,
used_space BIGINT NOT NULL
);
ALTER TABLE public.disk_snapshots OWNER TO snapdisk_user;
GRANT USAGE, CREATE ON SCHEMA public TO snapdisk_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.disk_snapshots TO snapdisk_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO snapdisk_user;
SQLNotes:
- The project currently contains hardcoded DB credentials in
src/com/snapdisk/db/Database.java. Change them before production use.
- Populate history (backfill recent days):
java -cp "bin:lib/*" com.snapdisk.tools.PopulateHistory 14- Automatic one-per-day snapshot on app start (saves total/free/used bytes)
- Table of snapshots (read-only)
- Chart plotting used space as percent of total (start & end labels only)
- Buttons: Clear Data (delete all DB rows) and Export PNG (save chart image)
- If the app reports schema/permission errors, run the DB setup SQL above as a superuser.
- If you prefer to try the UI without a DB, use
./run.sh --no-dbor setSNAPDISK_NO_DB=true.
- Improve persistence config (remove hardcoded credentials)
- Add scheduled snapshot (OS cron / systemd timer)
- Add export CSV and unit tests
Enjoy — open an issue or edit files if you want changes.