diff --git a/docs/superpowers/plans/2026-08-15-nstarikov-storage-migration.md b/docs/superpowers/plans/2026-08-15-nstarikov-storage-migration.md new file mode 100644 index 0000000..4cb1ad5 --- /dev/null +++ b/docs/superpowers/plans/2026-08-15-nstarikov-storage-migration.md @@ -0,0 +1,154 @@ +# Nstarikov Storage Migration Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Relocate non-latency-sensitive persistent files from the root disk to the mounted 100 GB storage volume, retain Directus backups predictably, and preserve service paths. + +**Architecture:** Use `/var/www/dzen.nstarikov.ru/storage` as the single storage root. Copy online first; stop only the relevant process for a final `rsync --delete`; preserve the former path as a symlink or explicit Compose bind mount. Keep timestamped rollback directories until every post-check passes. + +**Tech Stack:** ext4, rsync, Docker Compose, gzip, shell, Caddy. + +--- + +### Task 1: Validate storage and create isolated target directories + +**Files:** +- Modify: `/etc/fstab` only if the existing storage mount is not persistent; otherwise no config change. + +- [ ] **Step 1: Confirm the mounted volume and free capacity** + + Run: `findmnt -no SOURCE,TARGET /var/www/dzen.nstarikov.ru/storage && df -h / /var/www/dzen.nstarikov.ru/storage` + + Expected: the storage target is on its own filesystem with at least 80 GB free. + +- [ ] **Step 2: Create only named category directories** + + Run: `install -d -m 0755 /var/www/dzen.nstarikov.ru/storage/{directus-backup,geopolitics-story-temp,vk2ok-storage,dzen-media,n8n-archive,caddy-logs}` + + Expected: all target directories exist on the storage filesystem; nothing is stored directly in the videos directory. + +### Task 2: Migrate Directus dumps and apply explicit retention + +**Files:** +- Modify: `/var/www/api.nstarikov.ru/backup/backup.sh` +- Move: `/var/www/api.nstarikov.ru/backup` to `/var/www/dzen.nstarikov.ru/storage/directus-backup` + +- [ ] **Step 1: Back up the backup script and add deterministic retention** + + Retain the latest `directus_*.sql.gz` from every one of the latest 14 calendar days. For files older than those days, retain the latest file from each of the three newest ISO weeks. Delete all other matching dumps only after a successful dump and gzip integrity check. Do not delete `backup.sh` or non-matching files. + +- [ ] **Step 2: Make an online copy and record a manifest** + + Run: `rsync -aHAX --info=progress2 /var/www/api.nstarikov.ru/backup/ /var/www/dzen.nstarikov.ru/storage/directus-backup/ && (cd /var/www/dzen.nstarikov.ru/storage/directus-backup && sha256sum directus_*.sql.gz > .migration-sha256)` + + Expected: destination contains every source dump and a checksum manifest. + +- [ ] **Step 3: Stop only the dump writer, final-sync, and switch compatibility path** + + Run from `/var/www/api.nstarikov.ru`: `docker compose stop backup-pg`; run `rsync -aHAX --delete`; rename source to `backup.pre-storage-YYYYmmddHHMMSS`; create `backup -> /var/www/dzen.nstarikov.ru/storage/directus-backup`; then `docker compose up -d backup-pg`. + + Expected: `backup-pg` is running and `/backup` resolves to the storage filesystem. + +- [ ] **Step 4: Verify data and retention contract** + + Run: `sha256sum -c .migration-sha256`, `gzip -t directus_*.sql.gz`, inspect the next `backup-pg` log, and count selected daily/weekly files after retention logic runs. + + Expected: all pre-migration dumps validate; future runs keep 14 daily plus 3 older weekly dumps. + +### Task 3: Migrate bot media without changing application paths + +**Files:** +- Move: `/var/www/bots/geopolitics_tg_story/temp_videos` to `storage/geopolitics-story-temp` +- Move: `/var/www/bots/vk2ok/storage` to `storage/vk2ok-storage` + +- [ ] **Step 1: Copy both sources online** + + Run `rsync -aHAX --info=progress2` for each source into its named target directory. + + Expected: target file counts and byte totals match their sources before cutover. + +- [ ] **Step 2: Cut over geopolitics temporary-video storage** + + Stop `geopolitics_story_app`, final-sync with `--delete`, rename the old source with a timestamp, create a symlink at `temp_videos`, then start the container. + + Expected: the bot resumes and new writes follow the symlink onto storage. + +- [ ] **Step 3: Cut over vk2ok storage** + + From `/var/www/bots/vk2ok`, stop `api`, `worker`, and `beat`; final-sync with `--delete`; rename the old source with a timestamp; create the `storage` symlink; start the three services. + + Expected: API, worker, and beat are healthy and all storage paths resolve to the target filesystem. + +### Task 4: Migrate Dzen media using Compose mounts + +**Files:** +- Modify: `/var/www/dzen.nstarikov.ru/docker-compose.yml` +- Move: `/var/www/dzen.nstarikov.ru/data/media` to `storage/dzen-media` + +- [ ] **Step 1: Copy current media and prepare the explicit mount** + + Copy `data/media/` to `storage/dzen-media/`. Add `/var/www/dzen.nstarikov.ru/storage/dzen-media:/app/data/media` to API, worker, and beat while keeping the existing data and videos mounts unchanged. + +- [ ] **Step 2: Recreate only Dzen API, worker, and beat** + + Stop those three services, run a final `rsync -aHAX --delete`, rename the old media directory to a timestamped rollback name, then recreate the three services with the changed Compose file. + + Expected: uploads and generated media resolve from the new bind mount; Redis remains untouched. + +- [ ] **Step 3: Verify Dzen application health and a known media response** + + Run the existing health endpoint and an HTTP request to one existing media asset. + + Expected: health is successful and the media asset returns its expected content type and successful status. + +### Task 5: Move inactive n8n archive + +**Files:** +- Move: `/var/www/n8n.nstarikov.ru/archive` to `storage/n8n-archive` + +- [ ] **Step 1: Confirm no active Compose service consumes `archive`** + + Run `docker compose ps` from `/var/www/n8n.nstarikov.ru` and inspect mounts for active n8n containers. + + Expected: no active container uses the archival directory. + +- [ ] **Step 2: Copy, validate, and switch the compatibility path** + + Use rsync, compare file counts and byte totals, rename source to a timestamped rollback directory, and create `archive -> /var/www/dzen.nstarikov.ru/storage/n8n-archive`. + + Expected: no application downtime and the archive path resolves to storage. + +### Task 6: Migrate Caddy logs last and prove external reachability + +**Files:** +- Modify: `/var/www/caddy/docker-compose.yml` or the equivalent active Compose file +- Move: `/var/www/caddy/logs` to `storage/caddy-logs` + +- [ ] **Step 1: Inspect the active Caddy logging policy before alteration** + + Read Caddy log blocks and preserve their existing rolling/retention settings. Do not add generic logrotate or use `copytruncate`. + +- [ ] **Step 2: Copy and switch the single Caddy log bind mount** + + Perform online rsync, stop/recreate Caddy for a final rsync and an updated log-source bind mount (or an equivalent parent-level compatibility symlink). Preserve the old directory as a rollback name. + + Expected: only a brief proxy interruption; new log writes appear under `storage/caddy-logs`. + +- [ ] **Step 3: Verify Caddy and public hosts** + + Check container health/logs, request `https://nstarikov.ru/`, `https://api.nstarikov.ru/`, and `https://dzen.nstarikov.ru/`, and confirm each response is successful. + +### Task 7: Final accounting and deferred cleanup + +**Files:** +- No source-code changes. + +- [ ] **Step 1: Verify every migration target and service** + + Run `df -h / /var/www/dzen.nstarikov.ru/storage`; `findmnt`; `readlink -f` for every compatibility path; and targeted Docker health/log checks. + + Expected: root usage has decreased by the moved data size, targets live on storage, and all affected services are healthy. + +- [ ] **Step 2: Retain rollback sources until explicit cleanup approval** + + Keep every timestamped `*.pre-storage-*` directory untouched after verification. Report their paths and sizes. Do not remove them in this migration because removal is destructive and needs a final explicit decision.