How to download Discourse backup and restore local database

Navigate to the website’s backup interface, and you will see the current backup status.


Click the download button.

It should be noted that when you download, the system will send a link to your email address.

You can use the link received in your email address to download the data.

Download Link

Click the download link address received in the email to download.


The downloaded file is a tar.gz file, which you need to decompress before use.

For example, our current downloaded file is: isharkfly-2023-09-14-092024-v20230910021213.tar

After a series of complex decompression steps, you will find the dump.sql file.

This file is your entire database backup.

Data Recovery

The psql installation path for PQadmin on Windows is: C:\Users\yhu\AppData\Local\Programs\pgAdmin 4\v7\runtime

Our command is: psql -h nas1120 -p 5433 -U postgres -W -d discourse -f C:\\Users\\yhu\\Downloads\\isharkfly-2023-09-14-092024-v20230910021213\\isharkfly-2023-09-14-092024-v20230910021213\\dump.sql\\dump.sql

Local databases cannot be overwritten during recovery.

If your local database already exists, you need to clear the existing local database before recovery.

The backup recovery process requires restoring all data and table structures.

The recovery program cannot restore on top of existing data structures and cannot perform incremental recovery.

Check Table Data

Check the table data to confirm that some table data has been restored.


Timestamps are generally a good way to verify.

1 Like

Supplement.
If the mail service fails, admin with ssh permissions can see all backup files in /var/discouse/{standalone | web_only}/backup/default.

A note:
If the mail service fails, admin with ssh permissions can see all backup files in /var/discouse/{standalone | web_only}/backup/default.

3 Likes

How do I use Minio for backups? I don’t understand the error messages in the logs. The logs are as follows:

....
[2023-10-03 13:33:24] Removing tmp '/var/www/discourse/tmp/backups/default/2023-10-03-133319' directory...
[2023-10-03 13:33:24] Gzipping archive, this may take a while...
[2023-10-03 13:33:25] Uploading archive...
[2023-10-03 13:33:27] EXCEPTION: Aws::S3::Errors::Forbidden
[2023-10-03 13:33:27] /var/www/discourse/vendor/bundle/ruby/3.2.0/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/object.rb:445:in `rescue in exists?'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/object.rb:440:in `exists?'
/var/www/discourse/lib/backup_restore/s3_backup_store.rb:46:in `upload_file'
/var/www/discourse/lib/backup_restore/backuper.rb:344:in `upload_archive'
/var/www/discourse/lib/backup_restore/backuper.rb:41:in `run'
/var/www/discourse/script/spawn_backup_restore.rb:9:in `backup'
/var/www/discourse/script/spawn_backup_restore.rb:31:in `block in <main>'
/var/www/discourse/script/spawn_backup_restore.rb:4:in `fork'
/var/www/discourse/script/spawn_backup_restore.rb:4:in `<main>'
[2023-10-03 13:33:27] Deleting old backups...
[2023-10-03 13:33:28] Cleaning stuff up...
[2023-10-03 13:33:28] Removing archive from local storage...
[2023-10-03 13:33:28] Removing '.tar' leftovers...
[2023-10-03 13:33:28] Marking backup as finished...
[2023-10-03 13:33:28] Notifying 'XXX' of the end of the backup...

The log above should indicate that S3 does not have permission.

Please confirm that your S3 permission settings are correct.

Here are my settings, please experts take a look and see where the problem is:

  1. Discourse Settings
  2. Minio Backup Bucket Permissions Settings
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "*"
                ]
            },
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListBucketMultipartUploads"
            ],
            "Resource": [
                "arn:aws:s3:::discourse-backup"
            ]
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "*"
                ]
            },
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::discourse-backup/*"
            ]
        }
    ]
}
  1. Minio Upload Bucket Permissions are public

Refer to this article to see: discourse-docs/minio.md at master · rishabhnambiar/discourse-docs · GitHub

This article is from when path style was still supported; now only dns style is supported. I can’t find any configuration tutorials for using MinIO anywhere online.

Let’s see if it might be in the Minio settings.

Try using other tools, for example, tools that can directly access the bucket, to see if you can upload directly.

If you can upload directly here, then it’s likely a Discourse configuration issue. If you cannot upload directly here, then it’s likely a permissions issue.