Indigo Backup Script
Posted: Thu Jan 09, 2020 5:46 am
Here's a little script which, if scheduled to run once per day, will backup and zip the Perceptive Automation folder containing your database, plugins and scripts to a location of your choice, then delete backups older than 10 days (or whatever you specify). Have fun!
- Code: Select all
import distutils
import distutils.archive_util
import zipfile
import time
path = "/Users/racarter/Documents/Indigo Backups" #Change this to your desired path
number_of_days = 10 #Change this to the number of days you want to keep backups
def remove(path):
if os.path.isdir(path):
try:
indigo.server.log(" - removing folder %s" % path)
os.rmdir(path)
except OSError:
indigo.server.log( " - unable to remove folder: %s" % path)
else:
try:
if os.path.exists(path):
indigo.server.log(" - removing file %s" % path)
os.remove(path)
except OSError:
indigo.server.log( " - unable to remove file: %s" % path)
indigo.server.log ("Starting backup; saving to %s" % path )
time_in_secs = time.time() - (number_of_days * 24 * 60 * 60)
for root, dirs, files in os.walk(path, topdown=False):
for file_ in files:
full_path = os.path.join(root, file_)
stat = os.stat(full_path)
if stat.st_mtime <= time_in_secs:
remove(full_path)
if not os.listdir(root):
remove(root)
archive_filename_template = "Indigo_Backup_%m_%d_%Y__%H_%M_%S"
archive_filename = os.path.expanduser ( path + os.sep + time.strftime ( archive_filename_template, time.localtime() ) )
indigo.server.log (" - archive filename %s" % archive_filename + ".zip")
indigo.server.log (" - save path %s" % indigo.server.getInstallFolderPath() )
try:
distutils.archive_util.make_zipfile ( archive_filename, os.path.expanduser ( indigo.server.getInstallFolderPath()) )
except zipfile.LargeZipFile:
indigo.server.log ("Zip file too big. Would require 64 bit extensions")
indigo.server.log ("Backup Finished.")