summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 7297a96..6df2bd7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -95,6 +95,25 @@ enum Cmd {
#[arg(long, default_value_t = 30)]
limit: i64,
},
+ /// Print metrics in Prometheus text format (the same numbers /metrics serves).
+ Metrics,
+ /// Drop the files of releases beyond the retention window, and sweep
+ /// abandoned staging directories. Rows are never deleted (ยง15).
+ Gc {
+ /// Versions per pkgbase whose files are kept. Defaults to the
+ /// `retention_versions` setting.
+ #[arg(long)]
+ keep: Option<usize>,
+ /// Show what would be removed without removing it.
+ #[arg(long)]
+ dry_run: bool,
+ },
+ /// Write a consistent snapshot of the database with `VACUUM INTO`.
+ Backup {
+ /// Destination file. It must not already exist: a backup that silently
+ /// overwrites last week's backup is not a backup.
+ to: PathBuf,
+ },
}
fn main() -> anyhow::Result<()> {
@@ -317,6 +336,41 @@ fn main() -> anyhow::Result<()> {
}
Ok(())
}
+ Cmd::Metrics => {
+ print!("{}", aur_build::ops::metrics(&cfg, &ctx.db)?.to_prometheus());
+ Ok(())
+ }
+ Cmd::Gc { keep, dry_run } => {
+ let keep = keep.unwrap_or(aur_build::ops::DEFAULT_KEEP);
+ if dry_run {
+ let (kept, evict) = aur_build::ops::plan_retention(&ctx.db, keep)?;
+ println!("retention: keep {keep} version(s) per pkgbase");
+ println!(" {} release(s) keep their files", kept.len());
+ for e in evict {
+ let files = aur_build::ops::release_files(&cfg, &ctx.db, e.release_id)?;
+ println!(" release {} would lose {} file(s)", e.release_id, files.len());
+ for f in files {
+ println!(" {}", f.display());
+ }
+ }
+ return Ok(());
+ }
+ let r = aur_build::ops::retention(&cfg, &ctx.db, Some(keep))?;
+ println!(
+ "kept {} release(s), evicted {}, removed {} file(s), freed {} bytes, swept {} staging dir(s)",
+ r.releases_kept, r.releases_evicted, r.files_removed, r.bytes_freed, r.staging_swept
+ );
+ Ok(())
+ }
+ Cmd::Backup { to } => {
+ let path = aur_build::ops::backup(&ctx.db, &to)?;
+ println!(
+ "wrote {} bytes to {} (VACUUM INTO, single file, no WAL)",
+ std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0),
+ path.display()
+ );
+ Ok(())
+ }
}
}