New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export and import support #834
Comments
What issues did you run into? Export/Import has been requested a few times, and I agree would be useful:
For moving data between self-hosted instances, it could be as simple as a couple management commands – one command to produce a database dump, and another for importing it. Export/import through web UI would be more tricky:
It would have to be done very carefully, as there's lots of potential for unintended side-effects and security oopsies. There was one time when a customer deleted a big project by accident and asked if it's possible to restore it. Obviously I could not restore the whole database, as it would roll back data for all other users. I restored a database backup to a separate system, and wrote export/import commands to export/import a single account. Here are the commands I used: export.py: from itertools import chain
from django.core.management.base import BaseCommand
from django.core.serializers import serialize
from django.contrib.auth.models import User
from hc.accounts.models import Credential, Profile, Project
from hc.api.models import Channel, Check, Flip, Notification, Ping
class Command(BaseCommand):
help = """Export a single account's data in a JSON format."""
def handle(self, *args, **options):
email = "foo@example.org"
user_q = User.objects.filter(email=email)
credential_q = Credential.objects.filter(user__email=email)
profile_q = Profile.objects.filter(user__email=email)
project_q = Project.objects.filter(owner__email=email)
check_q = Check.objects.filter(project__owner__email=email)
channel_q = Channel.objects.filter(project__owner__email=email)
ping_q = Ping.objects.filter(owner__project__owner__email=email)
flip_q = Flip.objects.filter(owner__project__owner__email=email)
notification_q = Notification.objects.filter(owner__project__owner__email=email)
chained = chain(
user_q,
credential_q,
profile_q,
project_q,
check_q,
channel_q,
ping_q,
notification_q,
flip_q,
)
print(serialize("json", chained, indent=2)) restore.py: from django.core.management.base import BaseCommand
from django.core.serializers import deserialize
class Command(BaseCommand):
help = """Export a single account's data in a JSON format."""
def handle(self, *args, **options):
f = open("foo_at_example_org.json", "r")
for i, obj in enumerate(deserialize("json", f)):
obj.save(force_insert=True)
if i % 1000 == 0:
print(i) Note: I have not checked what happens with Postgres sequences if you use the above scripts to import data in an empty database. |
I have a self hosted healthchecks instance and I had to change my VPS last month. I exported all the database and tried to import back but it's not being easy. Maybe if there is a option to export and import in some known format like json or yaml.
Is there something like that in the roadmap for this project? If not, maybe I can give a shot.
The text was updated successfully, but these errors were encountered: