How to backup and restore non docker


Is there easy way to backup and restore like wordpress way?

For anyone not familiar with wordpress:
export file to xml from admin panel
backup one folder
install new version of wordpress
import xml file
copy one folder

this is very convenient to use new install and clean without any leftovers


Any assistance with this one?

I’m unable to run any clean up commands due to very low disk space so would like to start a new one and just copy over required items only.


this will be different depending on whether you’re using docker or not. are you?


You can get a backup of the database with the pg_dump program. The actual command you’ll run will depend on what name you used for your database; I run

pg_dump mastodon_production > /home/mastodon/backup.psqld

Then you can FTP the backup and your .env_production file to a different server, clear the disk, create the new database, and then restore with psql:

psql mastodon_production < backup.psqld

(This doesn’t create the database on its own; you’ll have to create it yourself first before running the psql import.)

Possibly this isn’t quite what you’re asking, but I figured it might be useful.


@beatrix-bitrot I am not using docker installation

@noelle does that mean that I can follow the production installation guide then just restore the database and everything will be back to normal? Does the database backup also include local user avatar and attachment?


the database contains all the necessary references to the avatars and attachments but the files themselves are stored either in S3 or in the ‘public’ directory somewhere

if they’re in S3 you don’t need to do anything

if they’re in ‘public’ you should move them to the new place


Unless someone beats me to it, I’ll try to spend some time this weekend coming up with a script that’ll put the database backup, .env_production, and the avatars and media into a tarball for easy extraction. (Warning: this is likely to be huge if your instance is more than a few users.)


maybe instead of tarball (because if space is low there will be no room for it?) script can scp or rsync the necessary stuff directly to destination?

fuckin’ good on ya tho


I’d say even the script that just make a pg_dump and then prepares a list of file to be dumped would be a huge win. One could then just ./script | pax -w to tar them or rsync or whatever.


Fair cops. I’ll see what I can put together.


apparently i’m not allowed to post anything under 20 characters so this is filling space

just wanted to say

noelle, you’re great


@noelle I’ve created a backup script. It has to be run by the mastodon user:

timestamp=`date +%Y-%m-%d`

echo -e "Mastodon backup:\n-------------"
echo -e "\n creating database dump"
pg_dump mastodon_production | gzip -9 > "$dbdump" || exit $?

echo -e "creating content archive"

tar cf - /home/mastodon/live/public/system | gzip -9 > "$content" || exit $?

echo -e "creating config archive"

tar cf - /home/mastodon/live/.env.production | gzip -9 > "$config" || exit $?

echo "Done!"
# END #

Do you have comments or criticism?


This is probably a good reference to achieve the backup and restore of a Mastodon instance.


@eruizdechavez You are right. But they’ve been talking about a script for regular backups. I just wanted to share my script with everyone.


@scroom makes sense!

I didn’t take the time to read your message before but now that I did I see it is doing almost exactly what the migration guide explains. I would probably just add an optional section to cover these:

Less crucially, you’ll proably also want to copy the following for convenience:

  • The nginx config (under /etc/nginx/sites-available/default)
  • The systemd config files (/etc/systemd/system/mastodon-*.service), which may contain your server tweaks and customizations
  • The pgbouncer configuration under /etc/pgbouncer (if you’re using it)

I would probably backup all Let’s Encrypt certificates but those require sudo privileges, but I am not sure if those require backup or if you can just regenerate new certs.