Comments (1)
I exported all the database and tried to import back but it's not being easy.
What issues did you run into?
Export/Import has been requested a few times, and I agree would be useful:
- for moving account data when migrating servers (like in your case)
- when moving from the hosted service to self-hosted (and vice-versa)
- for self-service backups and recovery through the web UI ("oops, I deleted the wrong project, now what?")
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:
- when exporting data, it should carefully select fields to include in the export. For example, exporting internal database IDs would be a security problem
- when importing data, it would have to handle data conflicts. For example, what to do if we're importing a check, but a check with the same UUID already exists (and potentially belongs to a different user account)?
- as Healthchecks evolves, and new database fields get added, the importing code would need to maintain backwards-compatibility for importing backups produced with older Healthchecks versions
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 = "[email protected]"
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.
from healthchecks.
Related Issues (20)
- Slack integration - default integration name to channel name HOT 1
- Unexpected "down" after sending ping HOT 2
- Read only user can create project, can we have "true" read only users ? HOT 3
- Discord Webhook integration HOT 6
- Return UUID in "List Existing Checks" response HOT 4
- "System" option for Appearance HOT 1
- Add TLS support for Receiving Emails HOT 3
- RP_ID can't be changed after initial deployment? HOT 2
- Unable to use different domains for web GUI and pings? HOT 2
- [Docker] replace pip with apt HOT 1
- Feature request: High-Availability HOT 2
- Alert gets sent even though check is OK HOT 2
- SITE_ROOT in local_settings.py HOT 2
- New type of API key: read-only, but returns check and channel UUIDs HOT 3
- gotify integration should allow to set priorities
- Slack legacy webhook integration HOT 2
- Mute all checks while updating HOT 3
- Get informed if job run time is too short HOT 2
- Hi, how to fix this error ,please help me, whenever user register it gives: SMTPAuthenticationError at /accounts/register/ (535, b'Incorrect authentication data')
- [docker] .env includes DEBUG=False yet banner still states "Running in debug mode, do not use in production." HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from healthchecks.