Add push-based full-site backup command to Stack2 Connector (zero-disk streaming) - #2
Add push-based full-site backup command to Stack2 Connector (zero-disk streaming)#2leighharro with Copilot wants to merge 7 commits into
Conversation
Agent-Logs-Url: https://github.com/leighharro/stack2-wp/sessions/301c52fa-fd4f-40ef-b182-a43276bcdc72 Co-authored-by: leighharro <15240396+leighharro@users.noreply.github.com>
|
@copilot this could create a massive amount of chunks which in turn could exceed file limits. |
…-row SQL batches Agent-Logs-Url: https://github.com/leighharro/stack2-wp/sessions/12a9026f-d3f7-426b-a43f-0b7a83b69928 Co-authored-by: leighharro <15240396+leighharro@users.noreply.github.com>
Done in commit 87653a6. Here's what changed:
|
|
@copilot this backup system only does a backup on uploads. |
Agent-Logs-Url: https://github.com/leighharro/stack2-wp/sessions/97bb6496-4b5e-43d6-96b4-dc82f75ff28e Co-authored-by: leighharro <15240396+leighharro@users.noreply.github.com>
Fixed in commit 305b2ad. The backup now creates a standard ZIP archive of the entire WordPress site:
The backup type The temp ZIP is deleted from the WordPress server immediately after being pushed, so no disk space is retained. Requires the PHP |
|
@copilot this is getting better but the entire Wordpress folder needs to be backed up as there are times where people add other files to that directory |
Agent-Logs-Url: https://github.com/leighharro/stack2-wp/sessions/740dbb28-89b9-41f5-af3b-87bef2cf80cb Co-authored-by: leighharro <15240396+leighharro@users.noreply.github.com>
Done in commit 874a997. The backup now archives the entire WordPress root ( The backup directory itself ( |
|
@copilot this is now backing up the correct files and database. Chunking is good. The issue now is that you could have a 10GB site and only have 12gb of storage. So you can't create a backup zip of that you'll likely go over storage quota. |
… files Agent-Logs-Url: https://github.com/leighharro/stack2-wp/sessions/6acd8237-c2ab-4f07-9518-2b02a6f402b4 Co-authored-by: leighharro <15240396+leighharro@users.noreply.github.com>
…n write Agent-Logs-Url: https://github.com/leighharro/stack2-wp/sessions/6acd8237-c2ab-4f07-9518-2b02a6f402b4 Co-authored-by: leighharro <15240396+leighharro@users.noreply.github.com>
Done in commit New approach — zero-disk streaming:
Each chunk now carries The final chunk carries |
Stack2 had no way to initiate or stream a WordPress site backup. This adds a
backupcommand to the existing signed command endpoint that streams every file in the WordPress installation directly to the Stack2 API in 10 MB chunks — no ZIP archive is ever written to disk, no local disk accumulation, and no polling required.New capabilities
action: backup— initiates a full-site streaming backup (types:database,files,full). Database is dumped in 1,000-row batches to a small temp file; all other files are streamed directly from disk. Pushes each 10 MB chunk to Stack2 immediately as it is read, then deletes the SQL temp file. Returnsbackup_id,total_chunks,total_bytes, andbackup_type.action: backup_cleanup— safety net to remove any orphaned SQL temp file if a push fails mid-way.GET /wp-json/stack2/v1/backup/{id}/status— returns the outcome of the most recent backup (status:pushedorfailed).Architecture
class-stack2-backup-service.phpclass-stack2-http-client.phppush_backup_chunk()— signs and POSTs each chunk to Stack2class-stack2-backup-rest-controller.phpBACKUP_API.mdBackup file tree
Files are streamed directly from WordPress — no ZIP is ever created on disk.
database/database.sqldatabase,fullwordpress/wp-admin/,wp-includes/,wp-content/,wp-config.php,.htaccess,index.php, and any other files present in the WordPress rootfiles,fullPush flow
WordPress reads each file directly and pushes every 10 MB piece to
POST {stack2_base_url}/api/websites/backup/chunkimmediately. Each chunk carriesfile_pathandfile_chunk_indexso Stack2 can reconstruct the original directory tree without reassembling a single archive. The final chunk carries summary metadata (total_chunks,total_bytes,backup_type) so Stack2 knows when to finalise. Signing uses:A hold-back pattern ensures the last chunk is always identified correctly: the plugin buffers one chunk ahead and only pushes it when the next read confirms more data exists, so
is_last=truecan be attached without a separate pass.Supporting changes
wp-content/uploads/stack2-backups/{backup_id}.sql.tmp), which is deleted immediately after its chunks are pushed. Orphaned SQL temp files are cleaned up by an hourly WP-Cron hook (stack2_backup_cleanup_event). The directory is protected by.htaccess.pushed/failed), timestamp, backup ID, total bytes streamed, and any error.wp_optionskeys track backup state:stack2_last_backup_at,_status,_id,_size,_error,_type,_total_chunks.ZipArchiveis not needed).