A user, Ankhamax, is seeking help to restore their Discourse site from a backup after an upgrade. zogstrip confirms it’s possible and provides the backup location (public/backups/default/) and the restore command (script/discourse restore <filename.of.the.backup.tar.gz>). pfaffman encounters issues with the restore command due to missing dependencies and SSO problems, offering a workaround via the Rails console. fefrei suggests using /users/admin-login for access. srchip and Eric_Keller share their successful restore methods, including enabling and disabling restore mode. mrded suggests restoring directly to PostgreSQL. deargle clarifies the discourse command usage. lyseoy faces issues restoring from an external file path. gerhard advises copying the backup to the correct directory. Eric_Keller shares a detailed script for restoring backups, and pfaffman suggests using DISCOURSE_ALLOW_RESTORE in app.yml to simplify the process.
I did a backup of my site before I upgraded to the latest version of the discourse however I can’t even access my site any more even though the upgrade appears to be successful as no error is displayed. Is there anyway that I can restore my site from the backup that I created earlier from terminal app as I can’t access the site?
Is it possible?
If yes, where do discourse save or store the backups that I executed from the admin panel?
Is there any guide on how to restore the site from backup?
This seems like a handy thing to be able to do since if you screw up configuring SSO you can’t get back into your site. I spent a week one day trying to get SSO configured, and now that it is configured correctly it seems that my account on the SSO (which I don’t control) is gone, so I can’t get in.
So, script/discourse restore fails because thor isn’t installed.
gem install thor fixes that, but then I’m still denied because:
URGENT: FATAL: Peer authentication failed for user "discourse"
Solving my immediate problem, I suppose I could turn off SSO from the Rails console. . .
edit: to disable SSO from the rails console:
cd /var/discourse
./launcher enter app
rails c
SiteSetting.enable_sso=false
exit
exit
The goal was to automate it without any entering container with the launcher.
Imagine your instance got lost for any reason. The only files you stored in git was your containers/app.yml and luckily you have a daily tarball backup.
No estaba seguro si esa era la forma correcta de acceder a un archivo “fuera de la aplicación desde dentro de la aplicación”, pero pareció encontrar el archivo de respaldo e iniciar la restauración. La restauración terminó con mensajes ambiguos:
¡Terminado!
[FAILED]
Restauración completada.
Intenté acceder a mi foro nuevamente, pero aún no funciona, así que supongo que la restauración no funcionó.
No puedes. Necesitas copiar el archivo de respaldo en el directorio correcto. Sigue las instrucciones en Restore a backup from the command line si deseas restaurar desde la línea de comandos.
Aquí está el script de trabajo que utilizo para restaurar producción a desarrollo y pruebas:
#!/bin/sh
set +x
set -e
# Este script restaura la última copia de seguridad productiva al entorno de prueba/desarrollo
CONTAINER_NAME=app-test
LATEST_BACKUP=$(mc ls s3/backup-prod/default | tail -n 1 | cut -d ' ' -f 5)
mc cp s3/backup-prod/default/${LATEST_BACKUP} /tmp
# asegurar que /var/www/discourse/public/backups/default/ exista con la propiedad adecuada
docker exec -i ${CONTAINER_NAME} sh -c "mkdir -p /var/www/discourse/public/backups/default/ && chown -R discourse:www-data /var/www/discourse/public/backups/default/"
cat /tmp/${LATEST_BACKUP} | docker exec -i ${CONTAINER_NAME} sh -c "cat - > /var/www/discourse/public/backups/default/${LATEST_BACKUP}"
docker exec -i ${CONTAINER_NAME} sh -x << EOF
discourse enable_restore
rails runner "SiteSetting.set('backup_location', 'local')"
discourse restore ${LATEST_BACKUP}
discourse disable_restore
rm -f /var/www/discourse/public/backups/default/${LATEST_BACKUP}
EOF
# reconstruir contenedor
cd /var/lib/discourse/discourse_docker
stdbuf -oL -eL ./launcher rebuild ${CONTAINER_NAME} 2>&1 | sed 's/DISCOURSE_google_oauth2_client_secret=[^ ]*/DISCOURSE_google_oauth2_client_secret=***REDACTED***/g'
cd -
rm -f /tmp/${LATEST_BACKUP}
Faltaba rails runner "SiteSetting.set('backup_location', 'local')" y esto impedía la restauración desde el archivo tar de copia de seguridad.
Tenga en cuenta que la salida del script del lanzador tuvo que ser redactada, ya que revelaría secretos en su salida, especialmente cuando se realiza a través de un trabajo visible de CI/CD.
Me alegra que tengas una solución. Aquí hay un par de cosas que facilitarán las cosas a otra persona.
Si usas DISCOURSE_ALLOW_RESTORE: 'true' en tu app.yml, puedes omitir la activación de la restauración. (De manera similar, puedes poner tu autenticación de Google en ENV y mantenerla completamente fuera de la base de datos).
Si tienes tanto staging como producción usando el mismo bucket S3, puedes restaurar la última copia de seguridad con
Si necesitas leerlo localmente, de manera similar podrías anular la configuración del sitio con una ENV y leería la copia de seguridad más reciente de la tienda local.