bl_info = {
    "name": "Save Incrementally",
    "author": "Clinton Reese",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Toolbar > BezierToSurface",
    "description": "Center on selected without zooming in",
    "warning": "",
    "wiki_url": "",
    "category": "Save It",
}

import bpy
import sys
import os
from datetime import datetime

#panel draw is run when mouse events - not just at creation time
class ICR_PT_SaveScenePanel(bpy.types.Panel):
   bl_label = "Save Scene"
   bl_idname = "ICR_PT_SaveIncrementalPanel"
   bl_space_type = 'VIEW_3D'
   bl_region_type = 'UI'
   bl_category = 'Clintons3D'

   def draw(self, context):
      layout = self.layout

      row = layout.row()

      row.operator('icr.saveincremental', text = 'Save with backup')

class ICR_OT_SaveScene(bpy.types.Operator):
   """ Save with backup """
   bl_idname = 'icr.saveincremental'
   #this is the label that essentially is the text displayed on the button
   bl_label = 'Save Incremental Op'

   def execute(self, context):

      filepath = bpy.data.filepath

      if not os.path.exists(filepath):
         #need message to save scene first
         self.report({"ERROR"}, "Must save the scene first.")
         return {'FINISHED'}

      #make backup folder if needed
      thebasename = os.path.basename(filepath)

      thedirname = os.path.dirname(filepath)
      
      thebackuppath = os.path.join(thedirname, "Backup")

      if not os.path.exists(thebackuppath):
         os.makedirs(thebackuppath)

      # new name is old name plus date time stamp
      now = datetime.now() # current date and time
      date_time = "_" + now.strftime("%Y%m%d%H%M%S")

      splitresult = os.path.splitext(thebasename)

      incrementalname = os.path.join(thebackuppath, splitresult[0] + date_time + splitresult[1])

      bpy.ops.wm.save_mainfile(filepath=bpy.data.filepath)
      bpy.ops.wm.save_as_mainfile(filepath=incrementalname, copy=True)

      #return value that tells blender we finished without failure
      return {'FINISHED'}
#Here we are Registering the Classes       
classes = (
    ICR_PT_SaveScenePanel,
    ICR_OT_SaveScene,
)

def register():
   from bpy.utils import register_class
   for cls in classes:
      register_class(cls)

def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)

   #This is required in order for the script to run in the text editor   
if __name__ == "__main__":
   register()  