docker-apps/mealie/mealie_jm.txt
2025-04-03 22:57:52 +02:00

158 lines
6.9 KiB
Plaintext

# https://docs.mealie.io/documentation/getting-started/installation/postgres/
Create user and group
---------------------
Credentials -> Local Users -> Add
Full Name: mealie
Username: mealie
Disable Password: <select>
Email: <leave blank>
UID: (note)
Create New Primary Group: <select>
Create Home Directory: <uncheck>
Samba Authentication: <uncheck>
Save
mealie UID: 3011
mealie GID: 3010
Create datasets
---------------
# In Truenas shell:
# list datasets
zfs list | grep -i "docker.*mealie"
zfs list | grep -i "NData2.*mealie"
# create following datasets if not present
zfs create SSD1/docker/data/mealie
zfs create SSD1/docker/data/mealie/appdata
zfs create SSD1/docker/data/mealie/pgdata
zfs create SSD1/docker/data/mealie/pgbackups
chown -R mealie:mealie /mnt/SSD1/docker/data/mealie
chown -R postgres:postgres /mnt/SSD1/docker/data/mealie/pgdata
chown -R postgres:postgres /mnt/SSD1/docker/data/mealie/pgbackups
Create folders
--------------
mkdir -p /mnt/SSD1/docker/stacks/mealie/secrets
Copy folder to docker stacks
----------------------------
# In Windows cmd shell in mealie folder, enter:
./cp2nas 10.0.0.20
# or
pscp -P 22 -r stacks/*.* root@10.0.0.20:/mnt/SSD1/docker/stacks/mealie/
Create secrets
--------------
# In Truenas shell:
cd /mnt/SSD1/docker/stacks/mealie/secrets
# database secrets
echo -n 'your_postgresql_database_name' > /mnt/SSD1/docker/stacks/mealie/secrets/mealie_postgresql_database
echo -n 'your_postgresql_username' > /mnt/SSD1/docker/stacks/mealie/secrets/mealie_postgresql_username
openssl rand 36 | base64 -w 0 > /mnt/SSD1/docker/stacks/mealie/secrets/mealie_postgresql_password
# smtp email secrets
echo -n 'your_smtp_destination' > /mnt/SSD1/docker/stacks/mealie/secrets/smtp_destination
echo -n 'your_smtp_from' > /mnt/SSD1/docker/stacks/mealie/secrets/smtp_from
echo -n 'your_smtp_host' > /mnt/SSD1/docker/stacks/mealie/secrets/smtp_host
echo -n 'your_smtp_password' > /mnt/SSD1/docker/stacks/mealie/secrets/smtp_password
echo -n 'your_smtp_username' > /mnt/SSD1/docker/stacks/mealie/secrets/smtp_username
# restrict access
chown -R mealie:mealie /mnt/SSD1/docker/stacks/mealie/secrets/
chmod -R 400 /mnt/SSD1/docker/stacks/mealie/secrets/
# read existing acl permissions, if any
getfacl /mnt/SSD1/docker/stacks/mealie/secrets
# set acl permissions
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/mealie/secrets
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/mealie/secrets/mealie_postgresql_password
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/mealie/secrets/mealie_postgresql_username
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/mealie/secrets/mealie_postgresql_database
# NB! if you want to remove all acl entries from a folder recursively, use setfacl -b -R <foldername>
# to list secrets in secrets dir
cd /mnt/SSD1/docker/stacks/mealie/secrets
for i in $(ls -1); do echo $i = `cat $i`; done | sort
Backup mealie database
----------------------
# In truenas shell:
mkdir /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)
chown pgadmin:pgadmin /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)
# Using browser, log in to pgAdmin on truenas
# Connect to servers; refer to "connecting to servers.txt", which also explains how to obtain db passwords
# To perform plain text backup:
# Navigate to Servers => mealie -> Databases -> mealie
# Right click on mealie database and select Backup...
# Enter the following on the different tabs of dialog box that opened:
General:
# Replace ##### with date in YYYY-MM-DD format when backup is being made
Filename: /#####/mealie-backup.sql (this maps to: /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/#####/mealie-backup.sql on truenas)
# Or click on folder icon and navigate to the folder that was created above. Enter mealie-backup.sql in Save As field, then click on Create
Format: Plain
Encoding: UTF8
Role name: mealie
Data Options:
Sections:
Pre-data: <select>
Data: <select>
Post-data: <select>
Objects:
Check public to select all objects
Click Backup
# After backup, verify presence of backup file:
ls -al /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)
# copy backup file(s) to mealie backups folder, replacing $(date -I) with date when backup was made if not today
mkdir /mnt/SSD1/docker/data/mealie/pgbackups/$(date -I)/
cp -vr /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)/mealie-backup.sql /mnt/SSD1/docker/data/mealie/pgbackups/$(date -I)/
chown -R postgres:postgres /mnt/SSD1/docker/data/mealie/pgbackups/
Migrating database
------------------
# In truenas shell
jlmkr shell docker
cd /opt/stacks/mealie
docker compose down
# remove all files/folders from pgdata; if any are already in this folder with data to be retained, move it to another folder before executing next command
rm -r /mnt/data/mealie/pgdata/*
# for some reason, mealie interferes with the database if it starts up with postgresql the first time, therefore we need to treat mealie a bit differently
# in Windows, comment out the complete mealie service in the compose.yml file (if you use notepad++, left click on start of the first row of the mealie service, hold in ALT and SHIFT and drag mouse down in the same column to the last row of the service; release ALT, SHIFT and mouse button and type in #; then hit ESC)
# transfer the mealie stack with the modified compose.yml file to truenas; in mealie folder, execute:
./cp2nas 10.0.0.20
# or
pscp -P 22 -r stacks/*.* root@10.0.0.20:/mnt/SSD1/docker/stacks/mealie/
# start, this time only postgresql will start
docker compose up -d
# After successfull startup of postgres:
docker exec mealie-postgresql-1 psql -U <your_db_user> -d postgres -c "DROP DATABASE \"<your_db_name>\";"
docker exec mealie-postgresql-1 psql -U <your_db_user> -d postgres -c "CREATE DATABASE \"<your_db_name>\";"
docker exec mealie-postgresql-1 psql -U <your_db_user> -d <your_db_name> -f /mnt/backups/$(date -I)/mealie-backup.sql # replace $(date -I) with the appropriate date
# stop postgresql
docker compose down
# now undo the comment out of the mealie service in the compose.yml file (if you use notepad++, you can remove the # using the same steps as described above, except this time, press delete to delete the column of #'s)
# transfer the mealie stack with the restored compose.yml file to truenas; in mealie folder, execute:
./cp2nas 10.0.0.20
# or
pscp -P 22 -r stacks/*.* root@10.0.0.20:/mnt/SSD1/docker/stacks/mealie/
# start mealie and postgresql
docker compose up -d
docker stop mealie-mealie-1
docker exec mealie-postgresql-1 psql -U mealie -d postgres -c "DROP DATABASE \"mealie\";"
docker exec mealie-postgresql-1 psql -U mealie -d postgres -c "CREATE DATABASE \"mealie\";"
docker exec mealie-postgresql-1 psql -U mealie -d mealie -f /mnt/backups/2024-09-01/mealie-backup.sql
docker start mealie-mealie-1
Stop truenas mealie
---------------------------
# In truenas shell
heavyscript app --stop mealie
# NB: Do NOT stop mealie with truenas gui
If you need to log into db
--------------------------
docker exec -it mealie_postgresql bash
psql -U <your_db_user> -d <your_db_name>