from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search


Backing up a Mastodon instance requires backing up the following:

  • media files (may be on another server)
  • 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.


  • 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.