r2
Apps & AutomationInteract with Cloudflare R2 buckets used by Pagecord. Use when the user wants to list objects, inspect bucket stats, fetch files, or check backup integrity in R2.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/lylo/pagecord/blob/HEAD/.agents/skills/r2/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/r2, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
R2
Use the Cloudflare API for R2 buckets.
Setup
- Read
CLOUDFLARE_ACCOUNT_IDand the relevant bucket token from/Users/olly/dev/pagecord/.env. - Bucket tokens follow
CLOUDFLARE_R2_{BUCKET}orCLOUDFLARE_R2_{BUCKET}_READ_ONLY. - Map bucket names by uppercasing and replacing hyphens with underscores.
- Also try matching just a distinctive suffix, such as
WAL_BACKUPS, if the full name has a common prefix likepagecord-. - If
CLOUDFLARE_ACCOUNT_IDis missing, stop and say so. - If more than one bucket token is configured and the user did not specify a bucket, list the candidates and ask.
Base API URL:
https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/r2/buckets/{BUCKET}
All requests use Authorization: Bearer {TOKEN}. Show the bucket and token env var in use, but never print the raw token.
Paginate object listings using the cursor from result_info when is_truncated is true. Always fetch all pages for check, inspect, and stat.
Commands
ls [bucket] [prefix]
List objects in a bucket, optionally filtered by prefix, using GET /objects?per_page=1000&prefix={PREFIX}. Display key, human-readable size, and last modified date. Show total count and total size. Limit display to the first 100 rows and say when display is truncated.
stat [bucket]
Fetch all pages and report total object count, total size, oldest object, newest object, and WAL-G structure if detected.
cat [bucket] [key]
Fetch one object with GET /objects/{KEY}. Pretty-print JSON. Warn before fetching objects larger than 100 KB when the size is known.
check [bucket]
Surface-level backup integrity check from object listings only:
- Fetch all object keys.
- Detect WAL-G structure when both
*/basebackups_005/and*/wal_005/prefixes exist. - For WAL-G, list base backup directories matching
*/basebackups_005/base_*/. - Verify each base backup has a
{dir_name}_backup_stop_sentinel.json. - Extract WAL segments matching
*/wal_005/[0-9A-F]{24}.lz4. - Sort WAL segments by timeline, log, and segment; verify continuity, including segment rollover from
0xFFto0x00with log increment. - Check WAL recency and warn if the latest segment is older than 15 minutes.
If no WAL-G structure is detected, report object count, size, and age of the newest object.
inspect [bucket]
Deep backup integrity check:
- Run all
checksteps first. - Fetch and parse each
_backup_stop_sentinel.json. - Inspect
StartTime,FinishTime,LSN,FinishLSN,PgVersion,Hostname,CompressedSize,UncompressedSize, andIsPermanent. - Verify backups completed cleanly, LSNs are monotonic,
PgVersionandHostnameare consistent, and the latest WAL segment is ahead of the latest backupFinishLSN.
Output
- Use concise tables for listings and checks.
- Sizes should be human-readable.
- Timestamps should be UTC.
- For errors, show the HTTP status and response body.
- Keep raw API responses out of the final answer unless requested.