Replicating to local? PG + Tigris → PG + Disk?

I’m at the point where my app is big enough that I want to make sure my local setup matches production as much as possible. Backing up postgres and restoring locally is easy enough, but I am unsure how to go about handling attachments/storage. I’m using rails + tigris, and objects have attached images that’ll break once I restore locally since local isn’t (and shouldn’t be) pointed at prod’s s3/tigris.

My hunch is that I need to spin up an s3-compatible storage system in docker and figure out how to just clone the bucket from prod tigris to it, then the pg restore to local will point to objects in an s3 with the same names. But this feels like a ton of work so I’m asking here if anyone has any suggestions first.

I use Tigris on Fly, and local in development. Your attachments point to blobs, and your blobs have a key and a service_name. When stored in Tigris, the key is used as is, when stored locally, the first four characters are used to determine a directory name for the file.

Install rclone and set up config/rclone/rclone.conf with your Tigris credentials.

s3-download.rb is a script which can be used to sync a local ./tigris directory with the contents from Tigris. It then creates hard links in your storage directory to these files. Hard links don’t take additional storage so you only have one copy of your files. I run this script on a Fly machine in my primary region, but you can remove the checks for ENV['FLY_REGION'] and run it locally.

Finally, create a config/storage/development.yml which will point your :tigris to your local storage, but only when running with RAILS_ENV=development.

rclone is capable of a s3 to s3 copy, so it is possible to do what you described, but it seems like an extra step when the local file system will do just fine for development.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.