Autosave does not create a backup?

I have been working on one of my first projects in years. Had some big bugs and learning curves, so started from 0 backwards implementing the hardest parts.
Today I asked chatgpt for some help, copied their code, pasted and compiled. It didnt run how i wanted.
Closed the app as I did not save it and needed to leave the house.

Came back to find that the code had automatically saved when compiled, destroying my reference. (no i do not have 96 copies named rev1, rev2, rev3...... I was not saving things that did not work and saving things that did.)

I am looking and looking, where the autosave made some duplicate or backup before just destroying the original file - but seems there are none.

Am I done my project? Call it quits? Why is something like Auto-Save enabled by default? Was there some sort of a prompt I missed in setup enabling or disabling that?

This really sucks

Welcome to the forum

You can turn of the autosave in your preferences, but I have always thought that it should not be on by default for the very reason that you have found out

Indeed, and thank you.
I have since disabled autosave in my preferences while trying to find a solution to get the old file back :frowning:

If you have an Apple then Time Machine. If Windows the same thing just not sure of the name.
Back when I got paid to do this I created a bat file that created a backup before invoking the IDE (NOT Arduino)

1 Like

Sounds pretty cool! I am on a macbook, however it seems that i never set up any part of time machine. I thought that maybe it was my hail marry, but no go. pretty cool you had a paid job in this! I would have at least 100 backups if i had a bat file make something each time i uploaded.

Are you aware there is an Archive option under the IDE Tools menu. The problem is it creates the archive one folder higher than it should so different projects with same file names is a challenge.

I did not know there was an Archive option - but still that wasn't really in my workflow. I was being careful to not save something broken. Especially over something working.

In 65 years of programming I have never lost a module, guess I just got lucky or I RTFM.

Hi @joesipaq. It might be possible to recover your code in a different way. Arduino IDE copies your sketch to a temporary folder during the compilation process. It is possible the full sketch is still stored in that folder. It would be at this location:

$TMPDIR/arduino/sketches/<some hash>/<sketch name>/<sketch name>.ino.cpp

(where $TMPDIR is the system temporary folder, <some hash> is some characters used to differentiate the folder name, and <sketch name> is the name of the sketch)

For example:

/private/var/folders/sx/07hx_hp11nz50sf4ljwylj080000gn/T/arduino/sketches/3A9AF02994178C2791F98B37AF39F346/MySketch/MySketch.ino.cpp

Note that a .cpp file extension has been appended to the original sketch filename.

You can try doing a search through that folder for the filename of your sketch.


:warning: This storage location is temporary in nature. It might be overwritten by Arduino IDE or deleted by your operating system at any time. So if you are going to try to recover the sketch from this location, you should do it as soon as possible and immediately move it to a safe location once you find it. You should also be careful to avoid performing actions that would trigger the loss of the data before attempting the recovery:

  • Do not compile or upload your sketch in Arduino IDE.
  • Do not close Arduino IDE.
  • Do not shut down or restart your computer.
  • Do not perform any operations to automatically free up disk space.

If you find the sketch file in the temporary folder, you will notice Arduino IDE made some changes in the code. These changes are minimal so it will be easy to convert the code back to your original sketch. We can help you out with that if you have trouble.

I use an external editor called Genny, which automatically creates a backup file. When I get close to a final version, I rename the .ino file to (yymmdd).txt and then save it again in Genny. It may complain that the file is missing, but I just ignore that and save anyway. Bingo; I’ve got a backup file to fall back on. I haven't checked if the IDE saves the file in the sketch directory when working this way, but there’s usually a temporary copy in the work folder. See @ptillisch #9 for reference.

Probably just a heck of a lot smarter than I, so I wouldn't call that luck. I haven't had enough workflows like this to know better it seems.

Thanks for the heads up. Issue was that I did close it. I did not click on a save button when closing it (like what popped up some times) and did not realize that there was a "feature" that was on by default that automatically saved every time I uploaded the code to see how it was working.
I'm also on a macbook, but there is probably a similar temp file for it.

I feel I could have done the same if I just clicked Save-As to make a new checkpoint or revision. But not needed another editor. This has been very trial and error as I've been away from programming for so many years. It has not been that much like riding a bike haha.

The information I provided in post #9 is for macOS. Look around in case a copy of your sketch is still present somewhere.

1 Like

When I used windows and was paid to code I had a simple trick for backups. Just create a batch file with same name as the exe and place it in the path but found before exe, in the batch file create a backup using date time pieces in the name, then call the exe via the full path to prevent recursion. Easy and works every time. If I could do that with my MacOS I would be a happy camper but so far I can't figure it out.

Well, due to my frustrating and skimming of everything, seems I did not take this as seriously as I should have - as I had closed Arduino IDE, Compiled and uploaded my sketch multiple times after, turned off my computer as I left the office.

That being said, I did fine a few copies of sketches that were in process in the /private/var/folders/SEARCHED_FOR_ARDUINO and found some pretty close to how it was.

This is something that may save someone else completely and thanks for the help everyone and especially @ptillisch

1 Like

I would recommend learning a revision control system like Git. It's trivial to set up a Git repository inside your project: just run git init inside your project directory on the command line (or use a graphical Git tool if you prefer). Then commit snapshots of your code whenever you get to points where you want to save the changes you've made (I sometimes even commit experimental changes in case they actually work, since I can roll them back easily).

I suppose it's kind of like Time Machine, but you have control over what changes gets saved and when, and you can describe why those changes were made.

That is cool and all. But, my qualm was that something was being saved without my knowledge as there was a default auto-save when compiled selected when IDE is installed. I have my own system that I though was working. Make it akin to printing it out on a paper when I got to a point I liked, and shredding the old one so nothing got confused.

With this project and the casualness I am doing this in, learning how to use git as a tool that will expedite my workflow would be an afternoon spent doing something I don't enjoy, vs getting my project done. It would have been quicker and easier for me to just save-as and start from there each time I had a new revision, and not have a why those changes were made section, because I do not care at this level of spaghetti coding.

Yeah, the auto-save feature seems like a misfeature to me. I only suggested Git as a way to avoid this and similar issues in the future. But if you don't care about why each change is made, then save-as to save backups seems like a good enough method.

It is true that the auto save feature of Arduino IDE 1.x only saves the sketch when you trigger a compile or upload, but the auto save feature of Arduino IDE 2.x saves the sketch immediately after every edit you make to the sketch code.

Although I advocate the use of Git for any professional or long term project, and use it myself for every project, I think your perspective on its use is reasonable. If your motivation for doing the project is purely for enjoyment/entertainment, then it makes sense to operate in a manner that is most enjoyable, even if less efficient than alternative approaches.

It is worth noting that, although the ability to clearly document the nature and reasons for making each change to a project via commit messages is a very valuable feature of Git, it is not mandatory. Git can be used to periodically create a simple backup at arbitrary points in the project development, just the same as you would do with the "caveman version control" system of saving copies of the project.

This approach of using Git in only the most basic possible manner could offer a more gentle transition than trying to jump right into using it to its full potential. I'm confident that those who began by using Git this way would gradually start using its other capabilities over time as their value became clear.

I don't add this with the intention of convincing @joesipaq, but rather for the benefit of others who might be interested in using a formal version control system for their projects.