Loading

blender-save_backup

  1. import bpy
  2. import os
  3.  
  4.  
  5.  
  6. class save_backup(bpy.types.Operator):
  7.   '''Set our default render settings.'''
  8.   bl_idname = 'blend.save_backup'
  9.   bl_label = 'Save Backup'
  10.   bl_options = {'REGISTER', 'UNDO'}
  11.  
  12.   def execute(self,context):
  13.     import time
  14.     import datetime
  15.  
  16.     if bpy.path.abspath('//') != '':
  17.       full_filename = bpy.path.basename(bpy.context.blend_data.filepath)
  18.       filename = full_filename[:-6]
  19.  
  20.       timestamp_raw = time.time()
  21.       timestamp = datetime.datetime.fromtimestamp(timestamp_raw).strftime('%Y-%m-%d_%H-%M')
  22.  
  23.       os.makedirs(bpy.path.abspath('//backup/'), exist_ok = True)
  24.       bpy.ops.wm.save_as_mainfile(filepath = bpy.path.abspath('//backup/' + filename + '_' + timestamp + '.blend'), copy = True, check_existing=True)
  25.  
  26.     else:
  27.       self.report({'ERROR'}, 'You must save the .blend file first before making backups.')
  28.  
  29.     return {'FINISHED'}

Comments