Page 1 of 1

Indigo Backup Script

PostPosted: Thu Jan 09, 2020 5:46 am
by racarter
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.")

Re: Indigo Backup Script

PostPosted: Thu Jan 09, 2020 6:03 am
by yassi
Nice, thanks!

Re: Indigo Backup Script

PostPosted: Thu Jan 09, 2020 6:43 am
by tazswe
Maybe something for Indigo 8.0


Skickat från min iPad med Tapatalk

Re: Indigo Backup Script

PostPosted: Thu Jan 09, 2020 9:00 am
by Umtauscher
Thanks, I tried it and get the error:
"Zip File Error, Would require 64 bit extensions"

Sorry, but what does than mean?
TIA
Wilhelm

Re: Indigo Backup Script

PostPosted: Thu Jan 09, 2020 9:10 am
by racarter
It means your backup is too big for some reason.

Re: Indigo Backup Script

PostPosted: Thu Jan 09, 2020 9:30 am
by Umtauscher
So, I just deleted 5 GB of log files an now it works!
Thanks

Wilhelm