=== Techimizers Backup & Migrate ===
Contributors: techimizers
Tags: backup, restore, migration, clone, database
Requires at least: 6.4
Tested up to: 6.9
Requires PHP: 8.0
Stable tag: 0.4.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lightweight backup, restore and site-to-site migration for WordPress. Phase 4 development build: verified local backups, restore with automatic rollback, scheduled backups with retention, email alerts on failure, and direct site-to-site migration. Not for production use yet.

== Description ==

This is the Phase 4 build of Techimizers Backup & Migrate. It creates verified backups of a single site, on demand or on a schedule, lets an administrator download and upload them, restores them with a preview, a confirmation step and automatic rollback, and moves a site directly to another WordPress install that runs this plugin.

What is in this build:

* One-click backup of the database (every table with this site's prefix, exported in primary-key batches) and of `wp-content`, uploads and site-root extras such as `.htaccess`, into split zip archives (500 MB parts by default) with a JSON manifest.
* SHA-256 hashes for every file, SQL part and archive part. Every backup is reopened and checked after it is written; only a verified backup is shown as good.
* Downloads streamed through a permission-checked endpoint; the storage folder is never linked.

* Upload of a backup made by this plugin (manifest plus parts), sent in small resumable pieces so low upload limits do not matter, then fully verified before it can be restored.
* Restore preview: what will be replaced, what stays, and how much disk space it needs, before anything is touched.
* Restore confirmation with your password and the typed site name; the confirmation is valid for 10 minutes and for that one restore only.
* Staged restore: the database is imported into temporary tables and files are unpacked beside the site. The live site is only changed in a short final swap that is recorded step by step, so it can be undone after a crash or timeout.
* Health check after the swap (database, administrator account, home page and login page). A restore is reported as successful only after it passes; otherwise the site is rolled back automatically.
* Manual rollback for 7 days after a restore, and a Discard action to free the space sooner.
* WordPress core files, `wp-config.php` and this plugin's own files are never replaced by a restore. The site address is kept.

* Backup schedules: daily, weekly (chosen day), monthly (day 1 to 28) or every N hours, database only or database and files, each with its own retention. Times follow the site timezone and stay correct across daylight-saving changes.
* Schedules never overlap with another backup or a restore: a busy site defers the run, and a run that waits too long is skipped and logged. Missed runs (no traffic, cron off) run once, not as a backlog.
* Retention per schedule: keep the newest N verified backups and optionally delete those older than D days. Manual and uploaded backups, pinned backups, the newest verified backup, backups used by an unfinished restore, and everything while the latest scheduled backup failed are never deleted automatically.
* The Schedules tab shows status, next run, last run and last failure for each schedule, and warns when a run is late or when WP-Cron is turned off.
* Direct site-to-site migration (Migrate tab). On the source, create a one-time migration key for a verified backup; on the destination, paste it. The destination checks both sites (plugin version and folder, WordPress, PHP and database versions, collations, free disk space, single site), downloads the backup in signed, resumable pieces, verifies it like an uploaded backup, and then restores it through the normal plan, password and site-name confirmation, with rollback. The destination keeps its own address, and links to the source address in the database are changed to the destination address (serialized and JSON data included).
* Restores of a backup made at another address change links to that address into links to this site.
* Email alerts (Settings tab) when a scheduled backup fails or is skipped, when a restore fails or is rolled back, or when a rollback fails. Sent with `wp_mail()` to the site admin email or up to five addresses of your choice, at most one per schedule every 6 hours. Manual backups are not emailed.

* A resumable, time- and memory-budgeted job runner with a database lock so a 30-second PHP limit never ruins a job.
* Environment checks that tell you honestly what this server can do, including whether the backup folder is publicly readable.
* An activity log that never stores secrets.
* A protected storage folder with a random name and Apache/IIS guard files.

== Security ==

* Backups are stored unencrypted on your server, in a randomly named folder with Apache and IIS guard files. The environment checks test whether the folder is readable over HTTP and block backups while it is (Nginx needs a `location` rule; the check shows it). Keep a copy off the server and delete backups you no longer need.
* WordPress core files are recorded by version, not copied; `wp-content/cache`, `upgrade`, and other backup plugins' folders are skipped.
* `wp-config.php` is never included in a backup and never written by a restore.
* All administrative actions require the `manage_options` capability and a valid nonce.
* A restore or rollback needs the administrator's password and the typed site name. Five wrong attempts lock confirmation for 15 minutes. Passwords are never stored or logged.
* Archives are treated as hostile: every path is checked against traversal, links and reserved names, every file is checked against its SHA-256 hash, and SQL is limited to an allow-list of statements for this site's own tables. Imported data is never unserialized.
* Uploaded scripts (`.php` and similar) inside uploads are skipped unless explicitly allowed.
* The only public REST endpoint without a credential, `tmbm/v1/ping`, returns `{"ok":true}` and nothing else; it exists so the server can test that it can reach itself.
* Migration keys are shown once, stored only as a SHA-256 hash, work once and expire (2 hours by default, 24 hours at most); they can be revoked. The key's secret is sent once, in the body of an HTTPS request, never in a URL, and never logged. Every later request and reply is signed with a session key derived from it (HMAC-SHA256 over method, route, body hash, timestamp and a single-use nonce), so replayed, altered or forged requests are refused. No WordPress password or login cookie is ever sent between the sites.
* The destination only connects to public https addresses on port 443: it refuses private, loopback, link-local and other internal addresses (checked on every request, with the connection pinned to the checked address), user names in URLs, other ports, proxies and redirects.

== Privacy ==

The plugin does not contact any external service. During a migration the destination site downloads the backup directly from the source site you paired it with; nothing passes through Techimizers or anyone else. Backups contain personal data from your database and uploads; erasing a user does not erase them from existing backups. Delete old backups from the Backups tab.

== Installation ==

1. Upload the `techimizers-backup-migrate` folder to `/wp-content/plugins/`.
2. Activate the plugin.
3. Open Techimizers Backup in the admin menu and run the environment checks.

Scheduled backups use WP-Cron, which only runs when the site gets visits. For reliable timing, set `define( 'DISABLE_WP_CRON', true );` and call `wp-cron.php` from a real server cron job every 5 minutes, for example `*/5 * * * * curl -s https://example.com/wp-cron.php >/dev/null`.

Optional: define `TMBM_BACKUP_DIR` in `wp-config.php` to store backups outside the web root.

Migration needs this plugin, at the same version, installed in the same folder on both sites, and both sites reachable over https at public addresses. Sites behind HTTP authentication, a VPN or a firewall that blocks the destination's server cannot be paired.

Failure alerts are sent with `wp_mail()`. After activating, open the Settings tab and click **Send a test email**; if nothing arrives, install an SMTP plugin.

== Changelog ==

= 0.4.1 =
* Admin screen redesign: navy header band with a version badge and a New backup shortcut, icon tabs, overview stat tiles (verified backups, last backup, next scheduled run, environment status) and quick actions, cleaner tables, badges and forms, numbered migration steps, empty states, and a sideways-scrolling layout on phones. Plain CSS and inline SVG only: no new scripts, fonts or dependencies, and no change to what any action does.

= 0.4.0 =
* Phase 4: direct site-to-site migration. One-time, expiring, revocable migration keys (stored only as a hash); signed, replay-protected requests and replies; SSRF protection (public https addresses only, checked on every request, pinned connection, no redirects or proxies); source and destination compatibility and readiness checks; resumable, integrity-checked chunked download that survives interruptions and source outages; the received backup is verified and restored through the existing plan, confirmation, undo log and rollback; links to the old address are changed to the new one during the restore (serialized- and JSON-safe, never unserialized, before the swap); cleanup of abandoned downloads that never touches verified backups or rollback data; Migrate tab.

= 0.3.1 =
* Phase 3 hardening: email alerts for failed or skipped scheduled backups, failed or rolled-back restores and failed rollbacks (new Settings tab: on by default, admin email, up to 5 addresses, test email, one email per schedule per 6 hours); failures of scheduled backups are recorded the moment the job fails; test suite run on PHP 8.0, 8.2 and 8.4, WordPress 6.4 and 6.9, MySQL 5.7 and 8.0 and MariaDB 10.11; PHP 8.4 deprecation notices fixed; the Phase 0 demo job is only registered when WP_DEBUG is on.

= 0.3.0 =
* Phase 3: backup schedules (create, edit, enable, disable, delete), one self-healing cron event, duplicate-run and overlap protection, missed-run and busy-site handling, per-schedule retention with protected and pinned backups, Schedules tab with status, next run, last run and last failure.

= 0.2.0 =
* Phase 2: backup upload (chunked, resumable, verified), restore preview, password and site-name confirmation, staged database and file restore, write-ahead undo log, automatic rollback after a failed health check or crash, manual rollback and discard, Restore tab.

= 0.1.0 =
* Phase 1: database exporter, file scanner, split zip archiver (ZipArchive with PclZip fallback), manifest with SHA-256 hashes, post-build verification, Backups tab with create, download and delete.

= 0.0.1 =
* Phase 0: plugin skeleton, job table, job runner, preflight, activity log, admin shell.
