Terraform state records what Terraform manages. Before changing state directly, preserve a copy: a mistaken edit can be destructive, and even a reliable backend cannot prevent every outage or accidental deletion. If state becomes corrupt, Terraform may be unable to read it at all; restoring a backup may be the only option. section 6.5.1 section 6.2.1 section 6.6.4
Save the current state
Run `terraform state pull > my_backup.tfstate` before manipulating state. `state pull` reads the latest state from the configured backend and writes it to standard output; the redirect saves that snapshot as a local file. section 6.5.1
Restore the snapshot
Run `terraform state push my_backup.tfstate` to send the saved file to the backend. You can also pipe it through standard input with `cat my_backup.tfstate | terraform state push -`. Terraform rejects a push when the snapshot has a different lineage or a lower serial than the backend state. If deliberately reverting to an older backup, `terraform state push -force my_backup.tfstate` bypasses those protections; confirm that this is the snapshot you intend to restore. section 6.5.1 section 6.3
Make recovery a backend practice, not just an emergency command. Keep reliable backups, restrict and log state access, and test backups regularly so the team knows they work. Backend versioning can help with corruption, but external backups still matter if the backend itself becomes unavailable. The exact setup depends on the backend. section 6.4.2 section 6.6.4









