How to backup and restore non docker


#1

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


#2

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.


#3

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


#4

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.


#5

@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?


#6

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


#7

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


#8

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


#9

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.


#10

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


#11

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

just wanted to say

noelle, you’re great


#12

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

 #!/bin/sh
timestamp=`date +%Y-%m-%d`
dbdump="$timestamp-masto-sql.tgz"
config="$timestamp-mast-config.tgz."
content="$timestamp-masto-content.tgz."

echo
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
echo "Done!"
#######
# END #
#######

Do you have comments or criticism?


#13

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


#14

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


#15

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


#16

Hi all. I’ve started a simple project called incognitum which completely autonomously manages nightly encrypted offsite backups for Mastodon [Docker/Non-Docker].

I’ve posted further details here: Are server backups and snapshots good enough to backup an instance?