this post was submitted on 23 Jun 2023
5 points (85.7% liked)

Lemmy

12542 readers
51 users here now

Everything about Lemmy; bugs, gripes, praises, and advocacy.

For discussion about the lemmy.ml instance, go to !meta@lemmy.ml.

founded 4 years ago
MODERATORS
 

Hi, Do you have any suggestions on how to backup the database or any other suggestions before upgrading Lemmy?

top 3 comments
sorted by: hot top controversial new old
[–] dudeami0@lemmy.dudeami.win 4 points 1 year ago

To dump a simple postgresql database, you can do something like:

pg_dump postgresql://lemmy:mypassword@example.com/lemmy -f backup.sql

This should result in a file being made named backup.sql for your database.

As for upgrading, my small instance with a 1.5Gb database upgraded with no issues using the docker images on kubernetes.

[–] ruud@lemmy.world 1 points 1 year ago* (last edited 1 year ago)

Either do a pg_dump or stop the database and make a full copy.

The pg_dump won't require downtime but will take longer to restore.

I use this command for the pg_dump

docker exec lemmy_postgres_1 pg_dump -Fc -U lemmy lemmy > /opt/lemmy/backup/lemmy_db_`date +%Y%m%d`.dump
[–] fuser@quex.cc 1 points 1 year ago

you can run something like this on the host - make sure you use the correct container name

#!/bin/bash
# check the container name with docker ps first
container_name="instance_name_postgres_1"

echo "dumping pgsql"
# Backup command
docker exec -t "${container_name}" pg_dumpall -c -U lemmy > lemmy_dump.sql

suggest you not leave unencrypted backup on the host system but copy it somewhere else, preferably after encrypting it with gpg.