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.
I wasn’t sure if that was the correct way to access a file “outside the app from within the app”, but it seemed to find the backup file and start the restore. The restore finished with the ambiguous messages:
Finished!
[FAILED]
Restore done.
Tried to access my forum again, but it’s still not working, so I guess the restore didn’t work?
You can’t. You need to copy the backup file into the correct directory. Please follow the instructions at Restore a backup from the command line if you want to restore from the command line.
Voici le script fonctionnel que j’utilise pour restaurer la production vers le développement et les tests :
#!/bin/sh
set +x
set -e
# Ce script restaure la dernière sauvegarde productive vers l'environnement de test/développement
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
# s'assurer que /var/www/discourse/public/backups/default/ existe avec la bonne propriété
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
# reconstruire le conteneur
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}
Il manquait rails runner "SiteSetting.set('backup_location', 'local')" ce qui empêchait la restauration à partir de l’archive de sauvegarde.
Notez que la sortie du script du lanceur a dû être expurgée car elle divulguerait des secrets dans sa sortie, surtout lorsqu’elle est effectuée via un travail CI/CD visible.
Heureux que vous ayez une solution. Voici quelques éléments qui faciliteront les choses pour quelqu’un d’autre.
Si vous utilisez DISCOURSE_ALLOW_RESTORE: 'true' dans votre app.yml, vous pouvez ignorer l’activation de la restauration. (Vous pouvez de même placer votre authentification Google dans ENV et les garder complètement hors de la base de données.)
Si vous avez à la fois une pré-production et une production utilisant le même compartiment S3, vous pouvez restaurer la dernière sauvegarde avec
Si vous avez besoin de la lire localement, vous pourriez de même remplacer le paramètre du site par une variable d’environnement et cela lirait la sauvegarde la plus récente du magasin local.