summaryrefslogtreecommitdiff
path: root/scripts/periodic_backup.lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-11-11 21:26:50 +0100
committerRobin Gareus <robin@gareus.org>2018-11-11 21:26:50 +0100
commit02f92300da7a3efe3de7689f06b36edf2b498025 (patch)
tree5a95c1c49c63712aad2ef96998f2cc40753f1c3f /scripts/periodic_backup.lua
parentfb1fe5ce30dff6b3246d14a428928073e655d6b4 (diff)
Add callback script to periodically save a backup snapshot
Diffstat (limited to 'scripts/periodic_backup.lua')
-rw-r--r--scripts/periodic_backup.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/periodic_backup.lua b/scripts/periodic_backup.lua
new file mode 100644
index 0000000000..42c6fdd66a
--- /dev/null
+++ b/scripts/periodic_backup.lua
@@ -0,0 +1,38 @@
+ardour {
+ ["type"] = "EditorHook",
+ name = "Periodically Save Snapshot",
+ author = "Ardour Lua Task Force",
+ description = "Save a session-snapshot peridocally (every 15mins) named after the current date-time",
+}
+
+-- subscribe to signals
+-- http://manual.ardour.org/lua-scripting/class_reference/#LuaSignal.LuaSignal
+function signals ()
+ return LuaSignal.Set():add ({[LuaSignal.LuaTimerDS] = true})
+end
+
+-- create callback function
+function factory ()
+ local _last_snapshot_time = 0 -- persistent variable
+
+ -- callback function which invoked when signal is emitted, every 100ms
+ return function (signal, ref, ...)
+
+ local now = os.time (); -- unix-time, seconds since 1970
+
+ -- skip initial save when script is loaded
+ if (_last_snapshot_time == 0) then
+ _last_snapshot_time = now;
+ end
+
+ -- every 15 mins
+ if (now > _last_snapshot_time + 60 * 15) then
+ _last_snapshot_time = now
+ -- format date-time (avoid colon)
+ local snapshot_name = os.date ("%Y-%m-%d %H.%M.%S", now)
+ -- save session -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Session
+ Session:save_state ("backup " .. snapshot_name, false, false, false)
+ end
+
+ end
+end