Goal
Sync data and/or code from one environment to another
Requirements
You will need:
- an active application on Upsun
- The Upsun CLI installed locally
- An SSH key configured on the project account
-
adminrole granted for the project
Problem
After setting up your environments, you discover you need to sync data from one development environment to another, but Upsun only allows sync’ing from a parent environment to a child environment. For example, let’s say you have the following environments setup:
❯ upsun environment:list Your environments are: +-----------+---------+--------+-------------+ | ID | Title | Status | Type | +-----------+---------+--------+-------------+ | main* | Main | Active | production | | dev | dev | Active | development | | sprint | sprint | Active | development | | staging | staging | Active | development | +-----------+---------+--------+-------------+
(Note: your production environment may be named something different than main; adjust accordingly)
However, after doing some work in the sprint environment, you want to sync that data to your dev and staging environments. You try upsun environment:sync but discover you can only sync from the main environment because it is the parent. And if you also want the file mount data to sync, you’ll have to do it manually as well. Instead, let’s change dev and staging’s parent!
Steps
The first thing we need to do is change the parent for our two environments from master to sprint:
❯ upsun environment:info parent sprint -e dev Property parent set to: sprint
and
❯ upsun environment:info parent sprint -e staging Property parent set to: sprint
After you change both environments, if you do an environment:list you should now see the two environments indented to indicate sprint is their parent:
❯ upsun environment:list Your environments are: +-------------+---------+--------+-------------+ | ID | Title | Status | Type | +-------------+---------+--------+-------------+ | main | Main | Active | production | | sprint* | sprint | Active | development | | dev | dev | Active | development | | staging | staging | Active | development | +-------------+---------+--------+-------------+
2.
Now we can sync data/code from sprint to dev and/or staging!
❯ upsun sync data -e dev Are you sure you want to synchronize data from sprint to dev? [Y/n] y Synchronizing environment dev Waiting for the activity img23cpt4lorc (Paul Gilzow synchronized devs data from sprint): Redeploying environment dev, as a clone of sprint
Note that:
Synchronizing “code” means there will be a Git merge from the parent to the
child. Synchronizing “data” means that all files in all services (including
static files, databases, logs, search indices, etc.) will be copied from the
parent to the child.
3.
Once you are finished sync’ing, or just need to change an environment back to being a child of your production environment, simply do the same thing we did in Step 1, but point it back to main
❯ upsun environment:info parent main -e dev Property parent set to: main
Now if you perform a sync on my dev environment, it will sync from the main environment:
❯ upsun sync data -e dev Are you sure you want to synchronize data from main to dev? [Y/n] y Synchronizing environment dev Waiting for the activity dz424vndxxto6 (Paul Gilzow synchronized devs data from Main): <snip> Redeploying environment dev, as a clone of main
Conclusion
Upsun is extremely flexible and gives you a multitude of ways to bend it to fit your workflow, including the ability to sync from any environment to another!
Comments
Please sign in to leave a comment.