# 更改 S3 存储桶及所有引用

**URL:** https://meta.discourse.org/t/changing-s3-bucket-and-all-references/167117
**Category:** Support
**Created:** [2020年十月13日 19:26 UTC](https://meta.discourse.org/t/changing-s3-bucket-and-all-references/167117 "2020-10-13T19:26:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Samir\_Faci](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samir_faci/32/119582_2.png) [@Samir\_Faci](https://meta.discourse.org/u/Samir_Faci)
#### Post date: [2020年十月13日 19:26 UTC](https://meta.discourse.org/t/changing-s3-bucket-and-all-references/167117/1 "2020-10-13T19:26:29Z")

</div>

我更改了网站的 S3 存储桶，并将所有资源复制到了新存储桶中。所有内容都保持一致，我还确保所有文件至少具有公共可读权限。

```plaintext
 for i in $(cat files.txt | awk '{print $4}'); do aws --profile gb_root s3api put-object-acl --bucket gb-www-forum --key $i --acl public-read ; done;

```

但部分 URL 和图片引用仍基于旧存储桶名称。

例如：Logo 的 URL 设置为：

[https://geek-beacon-www-forum.s3.dualstack.us-west-1.amazonaws.com/original/2X/8/8d0ac51fff56cdc704af2807c1c2efee13a3fd89.png](https://geek-beacon-www-forum.s3.dualstack.us-west-1.amazonaws.com/original/2X/8/8d0ac51fff56cdc704af2807c1c2efee13a3fd89.png)

这指向的是旧存储桶，所有引用都应更新为新存储桶名称。

**我已尝试的操作：**

### 重新烘焙（Rebake）

```plaintext
cd /var/discourse
./launcher enter app
rake posts:rebake

```

该操作成功执行，但没有任何变化。

### 重映射（Remap，调用失败）

Remap 功能曾被提及，但我似乎无法正确调用它。

```plaintext
root@forum-app:/var/www/discourse# rake --tasks | grep remap
rake posts:remap[find,replace,type,ignore_case] # Remap all posts matching specific string
root@forum-app:/var/www/discourse# rake posts:remap["geek-beacon-www-forum", "gb-www-forum", "string", false]
rake aborted!
Don't know how to build task 'posts:remap[geek-beacon-www-forum,' (See the list of available tasks with `rake --tasks`)
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
(See full trace by running task with --trace)

```

---

<div class="post-metadata">

### Author: ![Samir\_Faci](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samir_faci/32/119582_2.png) [@Samir\_Faci](https://meta.discourse.org/u/Samir_Faci)
#### Post date: [2020年十月15日 05:29 UTC](https://meta.discourse.org/t/changing-s3-bucket-and-all-references/167117/2 "2020-10-15T05:29:20Z")

</div>

由于无人回应，我最终只好执行一些 SQL 查询来尝试修复此问题。

```plaintext
sudo ./launcher enter app
sudo -u postgres psql discourse

```

这恐怕不是完整的列表，但我更新了以下表：

- uploads
- badges
- optimized\_images
- post\_custom\_fields
- post\_revisions
- posts
- stylesheet\_cache

论坛状况已大为改善，但我仍遇到一种奇怪的行为。当我访问包含图片的帖子时，图片依然显示为损坏；但当我尝试编辑该帖子时，图片、预览等一切正常。

如果我保存帖子，图片仍然显示为损坏。如果我下载图片并重新提交，图片依然损坏。

但如果我创建新帖子，则一切正常。

请问我可能遗漏了什么？
