monicahq / monica

Personal CRM. Remember everything about your friends, family and business relationships.
https://beta.monicahq.com
GNU Affero General Public License v3.0
21.56k stars 2.16k forks source link

Add export to API #5673

Open asteriske opened 2 years ago

asteriske commented 2 years ago

I'd like to automate database exports but it doesn't look like /settings/export or /settings/exportToSql is exposed. Can it be opened to the API?

MarkusDick commented 2 years ago

Hi @asbiin, I would like to work on this. I would put the Method exportToSql from the SettingsController to a trait called SQLExporter. To use it in the SettingsController@exportToSql and an ApiExportController@exportToSql.

MarkusDick commented 2 years ago

You can check it out here: https://github.com/MarkusDick/monica/commit/bc37e36ca4e6266bfeef44873c142e450139d947

MarkusDick commented 2 years ago

A little python script to get a SQL-backup:

import requests

url = "https://example.com/api/exportToSql"
access_token = "EXAMPLE_KEY"
data = {'Authorization': 'Bearer ' + access_token}

r = requests.post(url, headers=data)
open('backup.sql', 'wb').write(r.content)
asbiin commented 2 years ago

Actually, I don't think this is a good idea. Data export is not to be done in a synchronous way, and api callable. It must stay a way to export data occasionally. The problem here is it would be too easy to run the export too many times (imagine you run it each minutes ...), and that would not be costless. Today, data export can have impact on the app performances, and I would rather run it on an asynchronous job with low priority. The user will be able to download an archive some minutes after requested it.

At the same time, I'm working on a json export #4779, which will include more data (like photos or documents), and that will be more reliable.

If the concern is how to backup data on a hosted instance, then it's better to backup the database and data assets on the deployed platform instead of use monica data export.

asteriske commented 2 years ago

If the concern is how to backup data on a hosted instance, then it's better to backup the database and data assets on the deployed platform instead of use monica data export.

Exactly, I want to backup data from my dockerized instance. Does this advice mean to use mysqldump or similar?