# Resource initialization

When you first deploy your project or add a new container to it,
Upsun uses [default resources](#default-resources)
unless you specify a [resource initialization strategy](#specify-a-resource-initialization-strategy).

You can also use a specific resource initialization strategy when performing certain actions,
such as [branching](#environment-branch), [merging](#environment-merge),
and [activating](#environment-activation) an environment, or [restoring a backup](#backup-restoration).

## Default resources

Upsun allocates the following default resources to every container when deployed for the first time:

| Resource type               | Amount |
| --------------------------- | ----------- |
| CPU                         | 0.5 |
| RAM                         | Depends on the [container profile](https://docs.upsun.com/manage-resources/adjust-resources.md#advanced-container-profiles). |
| Disk size (only applicable if the app or service requires a disk)                   | 512 MB |

If you don't want to use these default resources, you can specify a [resource initialization strategy](https://docs.upsun.com/manage-resources/resource-init.md#specify-a-resource-initialization-strategy).
You can also [adjust resources](https://docs.upsun.com/manage-resources/adjust-resources.md) after your project or new container has been deployed.

**Note**: 

For information on costs related to resource usage, see the [Upsun pricing page](https://upsun.com/pricing/).
You can [monitor these costs](https://docs.upsun.com/administration/billing/monitor-billing.md) in the Console.

## Specify a resource initialization strategy

Upsun provides the following resource initialization strategies:

| Strategy | Description |
| ---------| ----------- |
| `default`  | Initializes new containers using the [Upsun default resources](#default-resources). This strategy applies when you first deploy your project (or new container) unless you explicitly specify a different strategy, or allocate resources manually via the `resources:set` CLI command.  |
| `manual`   | With this strategy, the first deployment fails and you need to configure resources manually through [the Console](https://console.upsun.com/), or using `resources:set` in the CLI.   This strategy allows you to set the exact resources you want, with a single deployment. Other strategies may require fine-tuning, and therefore generate a second deployment. In this case, your environment would run for a short time with unwanted resources, and both deployments would generate downtime.|
| `minimum`  | Initializes new containers using the Upsun minimum resources (see below). |
| `parent`   | Initializes new containers using the same resources as on the parent environment. If there is no parent environment, or if the container doesn't already exist on the parent, the `default` strategy applies instead. |
| `child`    | Initializes new containers using the same resources as on the child environment. Only relevant during merge activities. |
| `backup`   | When restoring a backup, initializes new containers using the same resources as when the backup was taken. |

**More information on…**: 

**Upsun minimum resources**
The following table shows the resources Upsun allocates to your containers when you opt for the ``minimum`` [resource initialization strategy](#specify-a-resource-initialization-strategy).

| Container | CPU | RAM | Disk* |
| .NET core | 0.1 | 64 MB | 0 MB |
| Chrome Headless | 0.1 | 64 MB | None |
| Elasticsearch | 0.1 | 448 MB | 256 MB |
| Elasticsearch Premium | 0.1 | 448 MB | 256 MB |
| Elixir | 0.1 | 64 MB | 0 MB |
| Go | 0.1 | 64 MB | 0 MB |
| InfluxDB | 0.1 | 448 MB | 256 MB |
| Java | 0.1 | 448 MB | 0 MB |
| Kafka | 0.1 | 448 MB | 512 MB |
| MariaDB | 0.1 | 448 MB | 256 MB |
| Memcached | 0.1 | 352 MB | None |
| MongoDB | 0.1 | 448 MB | 256 MB |
| MongoDB Premium | 0.1 | 448 MB | 256 MB |
| Network Storage | 0.1 | 448 MB | 256 MB |
| Node.js | 0.1 | 64 MB | 0 MB |
| OpenSearch | 0.1 | 448 MB | 256 MB |
| Oracle MySQL | 0.1 | 448 MB | 256 MB |
| PHP | 0.1 | 64 MB | 0 MB |
| PostgreSQL | 0.1 | 448 MB | 256 MB |
| Python | 0.1 | 64 MB | 0 MB |
| RabbitMQ | 0.1 | 448 MB | 256 MB |
| Redis ephemeral | 0.1 | 352 MB | None |
| Redis persistent | 0.1 | 352 MB | 256 MB |
| Ruby | 0.1 | 64 MB | 0 MB |
| Rust | 0.1 | 64 MB | 0 MB |
| Solr | 0.1 | 448 MB | 256 MB |
| Varnish | 0.1 | 448 MB | None |
| Vault KMS | 0.1 | 448 MB | 256 MB |
* The disk size is set to ``None`` when the container never uses disk, and to ``0 MB`` when the container doesn’t require disk but can use it.

You can specify a resource initialization strategy when performing the following actions:

| Action                                                                | Available strategies                     | Default  |
|-----------------------------------------------------------------------|------------------------------------------|----------|
| [First deployment](#first-deployment) | `parent`, `default`, `minimum`, `manual` | `parent` |
| [Environment branch](#environment-branch) | `parent`, `default`, `minimum` | `parent` |
| [Environment merge](#environment-merge) | `child`, `default`, `minimum`, `manual` | `child` |
| [Environment activation](#environment-activation) | `parent`, `default`, `minimum` | `parent` |
| [Backup restoration](#backup-restoration) | `backup`, `parent`, `default`, `minimum` | `backup` |

### First deployment

**Resource initialization strategies**: 

Available: ``parent``, ``default``, ``minimum``, ``manual``  
Default: ``parent``

You can define [which resource initialization strategy](#specify-a-resource-initialization-strategy) Upsun uses to allocate resources
when you first deploy your project or add a new container.

```bash {}
upsun push --resources-init=<INITIALIZATION_STRATEGY>
```

For example, to use the ``minimum`` strategy for your deployment, run the following command:

    Terminal

```bash {}
upsun push --resources-init=minimum
```

**Note**: 

Alternatively, you can use the official Git syntax for [push options](https://docs.upsun.com/environments.md#push-options):

    Terminal

```bash {}
git push upsun -o resources.init=minimum
```

Note that you can specify a different resource initialization strategy for each of your deployments.
If you’re using a [source integration](https://docs.upsun.com/integrations.md),
you can use the ``--resources-init`` flag to specify a resource initialization strategy.
**Note**: 

Once a resource initialization strategy is specified for your source integration,
it applies to **all** the deployments you launch through that source integration.

#### **When creating a new source integration**
To specify a resource initialization strategy when [creating your source integration](https://docs.upsun.com/integrations/source.md),
include the ``--resources-init`` flag in your source integration options. 
For example, if you [set up a GitHub integration](https://docs.upsun.com/integrations/source/github.md), use the following options:

    Terminal

```bash {}
upsun integration:add \
  --project <PROJECT_ID> \
  --type github \
  --repository  \
  --token <GITHUB_ACCESS_TOKEN> \
  --base-url <GITHUB_URL>
  --resources-init <INITIALIZATION_STRATEGY>
```

#### **Update an existing source integration**
To specify a resource initialization strategy for an existing source integration,
run the following command:

    Terminal

```bash {}
upsun integration:update --resources-init=<INITIALIZATION_STRATEGY>
```

For example, to use the ``minimum`` strategy for your deployment, run the the following command:

    Terminal

```bash {}
upsun integration:update --resources-init=minimum
```

### Environment branch

**Resource initialization strategies**: 

Available: ``parent``, ``default``, ``minimum``  
Default: ``default`` if the new environment is of type ``staging``, ``minimum`` if the new environment is of type ``development``

By default, when you [branch an environment](https://docs.upsun.com/glossary.md#branch) to create a new child environment, 
the resources allocated to this child environment depends on its type (staging or development). 
If the child environment is a staging environment, the default resources are allocated.
If the child environment is a development environment, the minimum resources are allocated. 
However, you can specify a different [resource initialization strategy](#specify-a-resource-initialization-strategy).

**Note**: 

When you branch an environment, regardless of the strategy you specified,
Upsun checks if the child environment’s disk size is at least equivalent to the parent’s. 
If not, the parent environment’s disk size is automatically applied to the child environment.
This ensures the branching can succeed.

```bash {}
upsun environment:branch --resources-init=<INITIALIZATION_STRATEGY>
```

For example, to use the ``parent`` resource initialization strategy, run the following command:

    Terminal

```bash {}
upsun environment:branch --resources-init=parent
```

 - Navigate to the environment you want to branch from.
 - Click Branch **Branch**.
 - Enter a name and a type for the new environment.
 - Select an initialization strategy from the proposed list.
 - Click **Branch**.

### Environment merge

**Resource initialization strategies**: 

Available: ``child``, ``default``, ``minimum``, ``manual``  
Default: ``child``

When you [merge](https://docs.upsun.com/glossary.md#merge) a child environment into its parent environment,
any apps and services you created on the child are merged and therefore created on the parent.

When this happens, any new app or service container created on the parent environment is granted the same resources as on the child environment.
However, you can specify a different resource initialization strategy.

**Note**: 

Any other container already running on the parent environment keeps its resources.

```bash {}
upsun environment:merge --resources-init=<INITIALIZATION_STRATEGY>
```

For example, to use the ``manual`` resource initialization strategy, run the following command:

    Terminal

```bash {}
upsun environment:merge --resources-init=manual
```

 - Navigate to the environment you want to merge into its parent.
 - Click Merge

 **Merge**.
 - Select an initialization strategy from the proposed list.
**Note**: 

The list of strategies is only displayed if a new app or service is included in the merge.

 - Click **Merge**.

### Environment activation

**Resource initialization strategies**: 

Available: ``parent``, ``default``, ``minimum``  
Default: ``default`` if the new environment is of type ``staging``, ``minimum`` if the new environment is of type ``development``

When you activate a new environment, Upsun allocates the resources depending on the environment type. 
If the environment is a staging environment, the default resources are allocated. 
If the environment is a development environment, the minimum resources are allocated. 

You can also specify a different resource initialization strategy using the CLI.
To do so, run the following command:

```bash  {location="Terminal"}
upsun environment:activate --resources-init=<INITIALIZATION_STRATEGY>
```

For example, to use the `parent` resource initialization strategy, run the following command:

```bash  {location="Terminal"}
upsun environment:activate --resources-init=parent
```

**Note**: 

[Setting resources](https://docs.upsun.com/manage-resources/adjust-resources.md) on a inactive environment using the Console or the CLI automatically activates it.

### Backup restoration

**Resource initialization strategies**: 

Available: ``backup``, ``parent``, ``default``, ``minimum``  
Default: ``backup``

```bash {}
upsun backup:restore --resources-init=<INITIALIZATION_STRATEGY>
```

For example, to use the ``minimum`` resource initialization strategy, run the following command:

    Terminal

```bash {}
upsun backup:restore --resources-init=minimum
```

When you [restore a backup](https://docs.upsun.com/environments/restore.md) using the Console, it is restored to your current environment.
The resources of every container already running on the environment are reverted to their original state when the backup was taken.
**Note**: 

If you don’t want to restore the resources from when the backup was taken,
opt out of restoring the resources.
To do so, when you restore your backup, use the ``--no-resources`` option.

If you deleted containers after backing up but before restoring, they are recreated using the ``backup`` strategy.
Meaning, they are granted the same resources as in the backup.
**Note**: 

If you don’t want to restore previously deleted containers,
opt out of restoring the code.
To do so, restore the backup using the CLI, and use the ``--no-code`` option.

## Environment sync

[Syncing an environment](https://docs.upsun.com/glossary.md#sync) means merging changes from a parent environment into a child environment.
You can sync:

- Only the code
- Only the data (databases, files)
- Only the resources (CPU and RAM, instances, and disk space)
- Any combination of the three (code and data, data and resources, etc.)

**Note**: 

When you sync the data, Upsun checks if the child environment’s disk size is at least equivalent to the parent’s. 
If not, the parent environment’s disk size is automatically applied to the child environment.
This ensures the sync can succeed.

```bash {}
upsun sync resources
```

 - Sync only code:

    Terminal

```bash {}
upsun sync code
```

 - Sync only data:

    Terminal

```bash {}
upsun sync data
```

 - Sync everything:

    Terminal

```bash {}
upsun sync code data resources
```

You can adjust the command depending on the exact combination of elements you want to sync.

 - Navigate to your Production environment.
 - Click  **Sync**.
 - Select the sync options you want from the proposed list.
 - Select **Sync resources from Production into Staging**.
 - Click **Sync**.


