Skip to content

Instantly share code, notes, and snippets.

@ali1234
Last active November 27, 2021 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ali1234/415c5ac863c5649c41a22fe061351a22 to your computer and use it in GitHub Desktop.
Save ali1234/415c5ac863c5649c41a22fe061351a22 to your computer and use it in GitHub Desktop.
Blender Infinite Backups
bl_info = {
"name": "Infinite Backups",
"author": "Alistair Buxton <a.j.buxton@gmail.com>",
"version": (1, 0),
"blender": (2, 80, 0),
"doc_url": "https://gist.github.com/ali1234/415c5ac863c5649c41a22fe061351a22",
"tracker_url": "https://gist.github.com/ali1234/415c5ac863c5649c41a22fe061351a22",
"category": "System",
}
import pathlib
import datetime
import bpy
from bpy.app.handlers import persistent
@persistent
def infinite_backups_save_handler(*args, **kwargs):
# saving the file will trigger this hook again, so disable it first
bpy.app.handlers.save_post.remove(infinite_backups_save_handler)
# calculate the filename for the backup
full_orig = pathlib.Path(bpy.data.filepath)
path = full_orig.parent # the directory
name = full_orig.stem # the name without extension
suff = full_orig.suffix # probably ".blend" but maybe something else?
# get ISO 8601 UTC time as a string
# guaranteed to be monotonic and alphanumeric sortable
time = datetime.datetime.now().replace(microsecond=0).isoformat()
# construct the backup filename
full_new = path / (name + '-' + time + suff)
# save a copy to the backup filename
# copy=True so that it doesn't change the current active file
bpy.ops.wm.save_as_mainfile(filepath=str(full_new), copy=True)
# re-enable the hook for the next save
bpy.app.handlers.save_post.append(infinite_backups_save_handler)
def register():
# note: we use save_post so that the backup filename matches the
# actual saved filename if it was a "save as" event.
bpy.app.handlers.save_post.append(infinite_backups_save_handler)
def unregister():
bpy.app.handlers.save_post.remove(infinite_backups_save_handler)
@ali1234
Copy link
Author

ali1234 commented Nov 23, 2021

This add-on makes an automatic timestamped backup whenever you save in Blender. Unlike the built-in backup system, this will never delete any old backups.

There is no GUI or configuration. Just enable the add-on and then save as usual. Backups will be created in the same directory.

P.S. No warranty if this destroys your files. The code is only a few lines so please read them and ensure they do what you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment