What's the point of the .tfstate.backup file?

2,867 views
Skip to first unread message

Carlton Henderson

unread,
Dec 21, 2015, 10:21:29 PM12/21/15
to Terraform
I hope this doesn't come across as facetious, but I can't find any documentation to explain the exact purpose of the terraform.tfstate.backup file.
  • When might I want to restore from backup? (How would I restore from backup safely?)
  • Should I put the backup file in version control if I am already putting my .tfstate file in version control each time the state file changes?
  • Why, sometimes, does the .backup file exactly match the .tfstate file?
  • Should I log these questions as documentation bug, or just leave it here in the google group?
Thanks, 

-Carl

Dave Cunningham

unread,
Dec 21, 2015, 10:28:29 PM12/21/15
to terrafo...@googlegroups.com
I think it's insurance in case some transient problem prevents the new state file from being written, which is "bad".  At least you can salvage some state that way.

For example, running out of disk during the write of the new file would be bad.  Or a bug in Terraform that caused the state to be occasionally mangled (unlikely at this point, but still).

If you're checking in the tfstate, you shouldn't need to delete the backup.

Maybe there's an argument Terraform should re-read the .tfstate after writing it, and if it verifies OK, delete the backup?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/2869d872-524c-427c-b273-a848074685f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Cunningham

unread,
Dec 21, 2015, 10:29:04 PM12/21/15
to terrafo...@googlegroups.com
If you're checking in the tfstate, you shouldn't need to delete the backup.


err I mean "you shouldn't need to keep the backup" 

Carlton Henderson

unread,
Dec 21, 2015, 11:55:24 PM12/21/15
to Terraform
Thanks for your quick response Dave.

If I understand you correctly, it sound a lot like a vim backup file (think readme~). 

When things are working as expected in vim, the readme~ backup file only exists while the readme is open and is deleted when you close vim. 

It sounds like the same logic applies to the terraform.tfstate.backup file but right now I need to delete it myself if I'm satisfied that the state file was written completely and correctly. And that should probably be any time terraform doesn't die with some terrible error.

Dave Cunningham

unread,
Dec 22, 2015, 12:24:00 AM12/22/15
to terrafo...@googlegroups.com
There is one big difference with vim though -- if you delete every line in the file, you can recover the file, and you're happy again.  However with Terraform if you accidentally destroy every instance, you can't get them back again (or the data in their drives) even if you have a tfstate backup.  So the only time the backup is useful is if the infrastructure is still out there, and just the record of its existence is lost.


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages