Handy scripts #771
kentcdodds
started this conversation in
Ideas
Replies: 2 comments
-
Here's my functions that I use in a local zsh plugin that reliably pulls from primary if that helps anyone. fly_backup_prod() {
app=$1 # i have this hardcoded but could be read from fly.toml or something
primary=$(fly status --app $app | grep primary | awk '{print $2}')
echo "Connecting to production"
fly ssh console --command "litefs export -name sqlite.db production-$(date +'%y-%m-%d').db" --app $app --machine $primary
fly ssh sftp get production-$(date +'%y-%m-%d').db --app $app --machine $primary
}
fly_files_prod() {
app=$1 # i have this hardcoded but could be read from fly.toml or something
primary=$(fly status --app $app | grep primary | awk '{print $2}')
fly ssh sftp shell --app $app --machine $primary
}
fly_ssh_prod() {
app=$1 # i have this hardcoded but could be read from fly.toml or something
primary=$(fly status --app $app | grep primary | awk '{print $2}')
fly ssh console --app $app --machine $primary
}
fly_proxy_prod() {
app=$1 # i have this hardcoded but could be read from fly.toml or something
fly proxy 5556:5555 --app $app
}
fly_prisma_prod() {
app=$1 # i have this hardcoded but could be read from fly.toml or something
primary=$(fly status --app $app | grep primary | awk '{print $2}')
fly ssh console -C "npm run prisma:studio" --app $app --machine $primary
}
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Does anyone have a script that can dump the primary database into the staging app database? I'm essentially not even using the staging app atm because it has no data. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have good instructions for backing up and restoring the database among other things. I think it would be really nice to package that up in a script.
I've been working on this a little bit already, but it's occurred to me that we should probably make this more formal and write it in JS instead of bash (because it's getting complicated). In particular, with multiple instances of the app you need to make sure each command you run against fly runs against the same instance and you probably want to run some of these against the primary instance as well.
Fly has the
fly status --json
command which should make it possible to determine the primary and then you can run things against that.I'm posting this here in case anyone wants to continue from where I left off. Here's the bash script I've got so far. These don't work. I remembered a bit ago that these scripts would run locally, not on the machine so they're partway fixed from that mistake and they also assume some environment variables which should probably be inquirer inputs.
./other/scripts/backup-db.sh
./other/scripts/restore-db.sh
Anyone who's interested in giving us a head start on this is welcome to do so!
Beta Was this translation helpful? Give feedback.
All reactions