# Admin functions

**URL:** <https://meta.discourse.org/t/admin-functions/354332>\
**Category:** Product Support\
**Created:** [February 25, 2025, 7:05am UTC](https://meta.discourse.org/t/admin-functions/354332 "2025-02-25T07:05:01Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Joshua\_Lyon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshua_lyon/32/117236_2.png) [@Joshua\_Lyon](https://meta.discourse.org/u/Joshua_Lyon)\
**Post date:** [February 26, 2025, 8:31pm UTC](https://meta.discourse.org/t/admin-functions/354332/10 "2025-02-26T20:31:51Z")

</div>

> [@Joshua\_Lyon](#):
>
> I was just doing some research to see if I could backup from Discourse 3.5 + PG13 and then restore on Discourse 3.5 + PG15 on a different host.

> [@pfaffman](#):
>
> It does. It’s probably time to upgrade your OS anyway. Just spin up a new server and restore your backup.

I ended up doing the backup and restore and it worked as expected.

* * *

For reference in case anyone else runs into a similar issue…

I ran into a bit of an issue at first as the restore process apparently calls the `uploads:migrate_to_s3` internally and it was getting hung up.

```plaintext
2025-02-26 00:24:16] Migrating the database...
[2025-02-26 00:24:24] 
[2025-02-26 00:24:24] Reconnecting to the database...
[2025-02-26 00:24:24] Reloading site settings...
[2025-02-26 00:24:24] Disabling outgoing emails for non-staff users...
[2025-02-26 00:24:24] Disabling readonly mode...
[2025-02-26 00:24:24] Clearing category cache...
[2025-02-26 00:24:24] Reloading translations...
[2025-02-26 00:24:24] Remapping uploads...
[2025-02-26 00:24:24] Restoring uploads, this may take a while...
[2025-02-26 00:25:09] EXCEPTION: 12 of 12208 uploads are not migrated to S3. S3 migration failed for db 'default'.
[2025-02-26 00:25:09] /var/www/discourse/lib/file_store/to_s3_migration.rb:132:in `raise_or_log'
/var/www/discourse/lib/file_store/to_s3_migration.rb:73:in `migration_successful?'
/var/www/discourse/lib/file_store/to_s3_migration.rb:383:in `migrate_to_s3'
/var/www/discourse/lib/file_store/to_s3_migration.rb:59:in `migrate'
/var/www/discourse/lib/file_store/s3_store.rb:354:in `copy_from'
/var/www/discourse/lib/backup_restore/uploads_restorer.rb:69:in `restore_uploads'
/var/www/discourse/lib/backup_restore/uploads_restorer.rb:49:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:167:in `restore_uploads'
/var/www/discourse/lib/backup_restore/restorer.rb:71:in `run'
/var/www/discourse/script/spawn_backup_restore.rb:20:in `restore'
/var/www/discourse/script/spawn_backup_restore.rb:33: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>'
[2025-02-26 00:25:09] Trying to rollback...
[2025-02-26 00:25:09] Rolling back...
[2025-02-26 00:25:10] Cleaning stuff up...

```

I ended up running some SQL queries in the data container to see if I could figure out what was going on.

```plaintext
./launcher enter data
sudo -u postgres psql discourse
SELECT url FROM uploads WHERE url NOT LIKE '%s3%';

```

That just returned some standard built-in items from Discourse, so I tried the reverse:

```plaintext
SELECT url from uploads where url LIKE '%s3%' limit 10;

```

That gave me a bunch of matches in the format:

- `//{my-bucket-name}.s3.dualstack.us-east-2.amazonaws.com/original/2X/5/{image-id}.jpeg`

So then I tried a query to get everything except items which matched that `s3.dualstack` host and I found that there were **12** old entries using a slightly different format (matching the number that failed from prior restore log failure).

- `//{my-bucket-name}.s3-us-east-2.amazonaws.com/{file-path}.jpeg`

When I checked for the existence of those files in the actual bucket, they didn’t exist, so I ended up deleting them with something like:

```plaintext
DELETE FROM uploads where url LIKE '%{my-bucket-name}.s3-us-east-2.amazonaws.com%';

```

After that, the backup and restore worked as expected!

PS. Don’t forget to re-enable emails after you restore the backup!

```plaintext
/admin/site_settings/category/all_results?filter=disable_email

```

---

_[View the full topic](https://meta.discourse.org/t/admin-functions/354332)._
