Effortlessly set up automatic backups and automatic optimizations of DaVinci Resolve Studio's PostgreSQL databases
Here are some workflow tools designed for Mac or Linux systems that are running as PostgreSQL servers for DaVinci Resolve Studio.
This repository includes:
- For macOS:
- A
bash
script that will let you effortlessly create, load, and startlaunchd
user agents that will automatically backup and automatically optimize your PostgreSQL databases - A
bash
script to uninstall the above tools
- A
- For CentOS Linux:
- A
bash
script for CentOS Linux that will let you effortlessly create and startsystemd
units and timers that will automatically backup and automatically optimize your PostgreSQL databases - A
bash
script to uninstall the above tools
- A
- Download the repository
davinci-resolve-postgresql-workflow-tools-master
to your~/Downloads
folder. - In Terminal, execute the following command to run the script:
~/Downloads/davinci-resolve-postgresql-workflow-tools-master/macos-install.sh
If you run into a permissions error, change the permissions on the file by running the following command first:
chmod 755 ~/Downloads/davinci-resolve-postgresql-workflow-tools-master/macos-install.sh
The script will then:
- Prompt you for the name of your PostgreSQL database;
- Prompt you for the path of the folder where your backups will go;
- Prompt you for how often you want to back the database up, in seconds; and
- Prompt you for how often you want to optimize the database, in seconds.
Once you run through this script, you will be automatically backing up and optimizing your database according to whatever parameters you entered.
The script creates macOS launchd
user agents, so these automatic backups and automatic database optimizations will continue on schedule, even after the system is rebooted. It's neither necessary nor desirable to run the script more than once per individual Resolve database.
To verify that everything is in working order, you can periodically check the log files located in ~/DaVinci-Resolve-PostgreSQL-Workflow-Tools/logs
.
- From an admin user account [neither
root
norpostgres
], download the repositorydavinci-resolve-postgresql-workflow-tools-master
to your~/Downloads
folder. - In Terminal, from within your
~/Downloads/davinci-resolve-postgresql-workflow-tools-master
folder, make the script executable:
chmod 755 centos-install.sh
- Then, execute the script:
sudo ./centos-install.sh
The script will then:
- Prompt you for the name of your PostgreSQL database;
- Prompt you for the path of the folder where your backups will go;
- Be sure to use the absolute path
- Prompt you for how often you want to back the database up; and
- Be sure to use
systemd
notation like1h
or3h
or1d
, etc.
- Be sure to use
- Prompt you for how often you want to optimize the database.
- Be sure to use
systemd
notation like1h
or3h
or1d
, etc.
- Be sure to use
Once you run through this script, you will be automatically backing up and optimizing your database according to whatever parameters you entered.
The script creates systemd
units and timers, so these automatic backups and automatic database optimizations will continue on schedule, even after the system is rebooted. It's neither necessary nor desirable to run the script more than once per individual Resolve database.
To verify that everything is in working order, you can periodically check the log files located in /usr/local/DaVinci-Resolve-PostgreSQL-Workflow-Tools/logs
.
This script has been tested and works for PostgreSQL servers for:
- DaVinci Resolve Studio 14
- DaVinci Resolve Studio 15
- DaVinci Resolve Studio 16
- macOS Sierra 10.12.6 or later
- PostgreSQL 9.5.4 or later (as provided by the DaVinci Resolve Studio installer)
- pgAdmin III (as provided by the DaVinci Resolve Studio installer)
- CentOS 7.3 or later
- PostgreSQL 9.5.4 or later
Jathavan Sriram wrote a great article back in 2014 about how to use pgAdmin III tools in bash
, instead of having to use the psql
shell.
The core insights from his 2014 article still apply, but several crucial changes need to be made for modern systems:
- Apple deprecated
cron
in favor oflaunchd
. - Starting with DaVinci Resolve 12.5.4 on macOS, DaVinci Resolve has been using PostgreSQL 9.5.
- The locations of
reindexdb
andvacuumdb
in PostgreSQL 9.5.4 have changed from what they were in PostgreSQL 8.4.
On macOS, this script creates and installs bash
scripts and launchd
agents that, together, regularly and automatically backup and optimize the PostgreSQL databases that DaVinci Resolve Studio uses.
On CentOS Linux, this script creates and installs bash
scripts, systemd
units, and systemd
timers that, together, regularly and automatically backup and optimize the PostgreSQL databases that DaVinci Resolve Studio uses. After a reboot, each systemd
timer will be delayed by a random number of seconds, up to 180 seconds, so as to stagger the database utilities for optimal performance.
The .pgpass
file that the script creates assumes that the password for your PostgreSQL database is DaVinci
, which is a convention from Blackmagic Design.
Make sure that you create the directory where your backups are going to go before running the script.
If you have any spaces in the full path of the directory where your backups are going, be sure to escape them with \
when you run the script.
The pg_hba.conf
file should be configured so that that these three lines use the trust
method of authentication:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
N.B. Running the GUI app DaVinci Resolve Project Server somehow seems to change the authentication method back to md5
. The scripts might continue to run, but because they'll be throwing errors, the logging won't be accurate. As a workaround, don't open this GUI app, or you'll have to go back to the pg_hba.conf
file and manually change these lines back to trust
again.
The script should be run from a regular user account with admin privileges. Do not run this script from either the root
or postgres
user accounts.
Because the script generates launchd
user agents, the backups and optimizations will only occur while logged into the same account from which the script was run. Stay logged into the same account.
The .pgpass
file that the script creates assumes that the password for your PostgreSQL database is DaVinci
, which is a convention from Blackmagic Design.
Make sure that you create the directory where your backups are going to go before running the script.
Be sure to use the absolute path for the directory into which the backups will go.
The pg_hba.conf
file should be configured so that that these three lines use the trust
method of authentication:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
The script should be run from a regular user account with admin privileges. Do not run this script from either the root
or postgres
user accounts.
The *.backup
files that this script generates can be restored into a new, totally blank PostgreSQL database in the event of a disk failure. These *.backup
files are also handy even just to migrate entire databases from one PostgreSQL server to another.
In the event of a disk failure hosting the PostgreSQL database, the procedure to restore from these *.backup
files to a new PostgreSQL server is as follows:
-
Set up a new, totally fresh PostgreSQL server
-
Create a fresh PostgreSQL database on the server, naming your database whatever you want it to be named
- If the version of Resolve you're using is the same version you were using when the
*.backup
file was created, you can just connect your client workstation and create a new blank database via the GUI; - But if your
*.backup
file was created for some earlier version of Resolve, you'll need to hop into thepostgres
superuser account and create a completely blank database:sudo su - postgres createdb <newdatabasename>
- If the version of Resolve you're using is the same version you were using when the
-
From a normal user acccount on the PostgreSQL server [not
root
orpostgres
], run the command:pg_restore --host localhost --username postgres --single-transaction --clean --if-exists --dbname=<dbname> <full path to your backup file>
You might see some error messages when you run the
pg_restore
command, but they are harmless, according to the PostgreSQL documentation. -
If the version of Resolve you're using is the same version you were using when the
*.backup
file was created, you should be good to go, but if your*.backup
file was created for some earlier version of Resolve, you should now be able to connect the the database via the GUI on the client and then upgrade it for your current version.
If you wish to stop automatically backing up and optimizing a particular database, you can run macos-uninstall.sh
:
chmod 755 macos-uninstall.sh
sudo ./macos-uninstall.sh
The script will ask you what database you want to stop backing up and optimizing. The database you specify will then stop being backed up, stop being optimized, and all relevant files will be safely and cleanly removed from your system. The database itself will remain untouched.
If you wish to stop automatically backing up and optimizing a particular database, you can run centos-uninstall.sh
:
chmod 755 centos-uninstall.sh
sudo ./centos-uninstall.sh
The script will ask you what database you want to stop backing up and optimizing. The database you specify will then stop being backed up, stop being optimized, and all relevant files will be safely and cleanly removed from your system. The database itself will remain untouched.