Mastodon/admin/backups

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< Mastodon‎ | admin
Revision as of 01:05, 26 December 2021 by Woozle (talk | contribs) (Created page with "==About== Backing up a Mastodon instance requires backing up the following: * media files (may be on another server) * database ===Database=== For reasons unknown to humma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

About

Backing up a Mastodon instance requires backing up the following:

  • media files (may be on another server)
  • database

Database

For reasons unknown to hummankind, Mastodon is hard-wired to use PostgreSQL for its main database engine, despite the fact that Mastodon uses Ruby on Rails which provides a database-agnostic framework. The most obvious way to back up Mastodon's data is to use the pg_dump client utility, preferably running on the machine where the backup data will be stored.

Steps:

  • Get the PostgreSQL connection credentials. These should be in <public html>/.env.production (DB_* settings).
  • If the PostgreSQL server is directly accessible:
    • Create the ~/.pgpass file (or modify it) so it has the password for the user you want to connect as. Details are here.
    • [NOT TESTED] From the backup target machine, run: pg_dump -U <DB_USER> -h <host> -p <DB_PORT> <DB_NAME> > <output_filename>
  • If it's not directly accessible, you'll have to tunnel via ssh and I haven't worked out how to do that via CLI.