> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Resource initialization

> Learn how resources are allocated by default upon first deployment, and how you can define a resource initialization strategy that better fits your needs.

export const SyncIcon = () => <svg width="24px" height="24px" style={{
  display: 'inline',
  verticalAlign: 'middle'
}}>
    <title id="sync-icon">Sync</title>
    <path fill="current" className="fill-target" fillRule="evenodd" clipRule="evenodd" d="M12.1,2.7L13.7,4l2,1.8c0.4,0.3,0.4,0.9,0,1.2l-2,1.6l-1.6,1.3c-0.5,0.4-1.1,0-1.1-0.6V7.2 c-2.8,0.5-5,2.9-5,5.9c0,2.7,1.8,5,4.3,5.8c0.5,0.1,0.8,0.6,0.7,1.1c-0.1,0.6-0.7,1-1.3,0.8C6.4,19.7,4,16.6,4,13.1 C4,9,7.1,5.7,11,5.2V3.3C11,2.6,11.6,2.3,12.1,2.7z M17.6,9c-0.4,0.3-0.5,0.8-0.3,1.3c0.2,0.4,0.4,0.8,0.5,1.2 c0.1,0.5,0.6,0.8,1.1,0.7c0.6-0.1,1-0.7,0.8-1.3c-0.1-0.2-0.2-0.5-0.3-0.8v0c-0.1-0.3-0.2-0.6-0.3-0.8C18.8,8.8,18.1,8.6,17.6,9z M17.2,16c-0.2,0.5-0.1,1,0.3,1.3c0.5,0.3,1.2,0.2,1.4-0.3c0.2-0.4,0.4-0.8,0.6-1.3c0-0.1,0.1-0.2,0.1-0.3c0.2-0.6-0.2-1.2-0.8-1.3 c-0.5-0.1-1,0.2-1.1,0.7C17.6,15.2,17.4,15.6,17.2,16z M13.7,18.9C13.2,19,12.9,19.5,13,20s0.7,0.9,1.3,0.8c0.5-0.1,1-0.3,1.5-0.6 c0.5-0.3,0.7-1,0.3-1.5c-0.3-0.4-0.9-0.5-1.3-0.3C14.5,18.6,14.1,18.8,13.7,18.9z"></path>
  </svg>;

export const MergeIcon = () => <svg width="24px" height="24px" style={{
  display: 'inline',
  verticalAlign: 'middle'
}}>
    <title id="merge-icon">Merge</title>
    <g>
      <g transform="translate(-89.000000, -1127.000000)">
        <g transform="translate(50.000000, 920.000000)">
          <g transform="translate(34.000000, 204.000000)">
            <path fill="current" className="fill-target" d="M22.7,22.7L22.7,22.7c0.4-0.4,0.4-1,0-1.4l-2-2c-0.4-0.4-1-0.4-1.4,0l0,0c-0.4,0.4-0.4,1,0,1.4l2,2 C21.7,23.1,22.3,23.1,22.7,22.7z M13.7,11H16v4.8c0,0.5-0.2,1-0.6,1.4l-4.1,4.1c-0.4,0.4-0.4,1,0,1.4h0c0.4,0.4,1,0.4,1.4,0 l4.7-4.7c0.4-0.4,0.6-0.9,0.6-1.4V11h2.3c0.4,0,0.7-0.5,0.4-0.9l-3.3-3.3c-0.2-0.2-0.5-0.2-0.7,0l-3.3,3.3 C13,10.5,13.3,11,13.7,11z"></path>
          </g>
        </g>
      </g>
    </g>
  </svg>;

export const BranchIcon = () => <svg width="24px" height="24px" style={{
  display: 'inline',
  verticalAlign: 'middle'
}}>
    <title id="branch-icon">Branch</title>
    <path fill="current" className="fill-target" d="M14.5,4.9l1.6,1.6l-2.4,2.4c-0.4,0.4-0.4,1,0,1.4l0.1,0.1c0.4,0.4,1,0.4,1.4,0L17.6,8l1.6,1.6c0.3,0.3,0.9,0.1,0.9-0.4V4.5 c0-0.3-0.2-0.5-0.5-0.5h-4.7C14.4,4,14.2,4.5,14.5,4.9z M8.8,4H4.5C4.2,4,4,4.2,4,4.5v4.3c0,0.4,0.5,0.7,0.9,0.4l1.4-1.4l4.1,4.1 c0.4,0.4,0.6,0.9,0.6,1.4V19c0,0.6,0.4,1,1,1l0,0c0.6,0,1-0.4,1-1v-6.6c0-0.5-0.2-1-0.6-1.4L7.7,6.3l1.4-1.4C9.5,4.5,9.2,4,8.8,4z"></path>
  </svg>;

Resources (CPU, RAM, disk) are allocated per container. Each app and service in your project runs as a separate container within an environment.

<Warning>
  This page describes resource initialization on Upsun Flex projects. On Upsun Fixed projects, resources are automatically distributed across your containers, and you cannot configure per-container resources manually. For details, see [container sizes](https://docs.upsun.com/anchors/fixed/app/reference/sizes/) in the Upsun Fixed documentation.
</Warning>

By default, when you first deploy your project or add a new container to it,
Upsun uses the `parent` [resource initialization strategy](#specify-a-resource-initialization-strategy),
which copies resource allocations from the parent environment.
If no parent environment exists, Upsun falls back to [preset resource amounts](#default-resources) instead.

You can also specify a different strategy when [branching](#environment-branch), [merging](#environment-merge),
[activating](#environment-activation), or [restoring a backup](#backup-restoration).

The strategy applied by default depends on how the environment is created:

* For standard branching and activation, the default strategy depends on the environment type.
* For environments created through a source integration, the strategy configured on the integration applies instead.

## Default resources

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

| Resource type | Default amount                                                                                                                                                                                                                                                              |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CPU           | 0.5                                                                                                                                                                                                                                                                         |
| RAM           | Depends on the [container profile](/docs/manage-resources/adjust-resources#shared-cpu-container-sizes) assigned to each [container type](https://developer.upsun.com/docs/manage-resources/adjust-resources#default-container-profiles) (for example, PHP uses `HIGH_CPU`). |
| Disk size\*   | 512 MB                                                                                                                                                                                                                                                                      |

\* Only applicable if the app or service requires a disk (for example, databases such as MariaDB or PostgreSQL).

To allocate different resources, specify a [resource initialization strategy](#specify-a-resource-initialization-strategy), or [adjust resources](/docs/manage-resources/adjust-resources) after deployment.

<Warning>
  Changing resource allocation directly affects your costs. Review the [Upsun pricing page](https://upsun.com/pricing/) before increasing resources. You can [monitor your current costs](/docs/administration/billing/bp-monitor-billing) in the Console.
</Warning>

## Specify a resource initialization strategy

Upsun provides the following resource initialization strategies:

| Strategy  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `default` | Uses the parent environment's resource allocation for new containers. If no parent environment exists, allocates [default resources](#default-resources) instead.                                                                                                                                                                                                                                                                                                                                         |
| `manual`  | Skips automatic allocation. The first deployment fails until you configure resources manually through [the Console](https://console.upsun.com/) or `resources:set` in the CLI.<br /><br /> This strategy lets you set the exact resources you want with a single deployment. Other strategies may require fine-tuning after the first deployment, which generates a second deployment. During that window, your environment runs briefly with unnecessary resources, and both deployments cause downtime. |
| `minimum` | Uses the Upsun [minimum resources](#minimum-resources) for new containers.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `parent`  | Uses the parent environment's resource allocation for new containers. If no parent environment exists, or if the container does not exist on the parent environment, falls back to allocating [default resources](#default-resources).                                                                                                                                                                                                                                                                    |
| `child`   | Uses the child environment's resource allocation for new containers. Used only when merging a child environment into its parent.                                                                                                                                                                                                                                                                                                                                                                          |
| `backup`  | When restoring a backup, initializes new containers using the same resource allocation as when the backup was taken.                                                                                                                                                                                                                                                                                                                                                                                      |

<Accordion title="Minimum resource amounts per container type" id="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.
</Accordion>

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`           | `default` (staging) / `minimum` (development), unless a source integration uses its configured strategy |
| [Environment merge](#environment-merge)           | `child`, `default`, `minimum`, `manual`  | `child`                                                                                                 |
| [Environment activation](#environment-activation) | `parent`, `default`, `minimum`           | `default` (staging) / `minimum` (development)                                                           |
| [Backup restoration](#backup-restoration)         | `backup`, `parent`, `default`, `minimum` | `backup`                                                                                                |

### First deployment

<Info>
  <h4>Resource initialization strategies</h4>
  Available: `parent`, `default`, `minimum`, `manual` <br />
  Default: `parent`
</Info>

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.

<Tabs>
  <Tab title="Without a source integration">
    If you're not using a [source integration](/docs/integrations),
    you can use a [Git push option](/docs/environments#push-options) to specify a resource initialization strategy.
    To do so, run the following command:

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

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

    ```bash Terminal theme={null}
    upsun push --resources-init=minimum
    ```

    <Note>
      Alternatively, you can use the official Git syntax for [push options](/docs/environments#push-options):

      ```bash Terminal theme={null}
      git push upsun -o resources.init=minimum
      ```
    </Note>

    You can specify a different resource initialization strategy for each deployment.
  </Tab>

  <Tab title="With a source integration">
    If you're using a [source integration](/docs/integrations), you can specify a resource initialization strategy for that integration.

    <Note>
      After a resource initialization strategy is specified for a source integration, it applies to environments created through that integration until you change it.

      This behavior can differ from the environment-type defaults described for standard branching, which may result in larger resources being allocated than expected.
    </Note>

    #### When creating a new source integration

    To specify a resource initialization strategy when [creating your source integration](/docs/integrations/source),
    include the `--resources-init` flag in your source integration options.<br />
    For example, if you [set up a GitHub integration](/docs/integrations/source/github), use the following options:

    ```bash Terminal theme={null}
    upsun integration:add \
      --project <PROJECT_ID> \
      --type github \
      --repository <OWNER/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:

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

    For example, to use the `minimum` strategy for environments created through the integration, run the following command:

    ```bash Terminal theme={null}
    upsun integration:update --resources-init=minimum
    ```
  </Tab>
</Tabs>

### Environment branch

<Info>
  <h4>Resource initialization strategies</h4>
  Available: `parent`, `default`, `minimum` <br />
  Default: `default` (staging) / `minimum` (development)

  When using a [source integration](/docs/integrations/source), defaults are per environment type:

  * `default` for production and staging environments
  * `minimum` for development environments

  `parent` is not available for production environments in source integrations.
</Info>

| Environment type | Default strategy | Resources allocated                            |
| ---------------- | ---------------- | ---------------------------------------------- |
| Staging          | `default`        | [default resource amounts](#default-resources) |
| Development      | `minimum`        | [minimum resources](#minimum-resources)        |

<Note>
  To override these defaults, use the CLI (development environments only) or the API (all environment types). See the **With a source integration** tab below.
</Note>

Use the methods below to specify a different [resource initialization strategy](#specify-a-resource-initialization-strategy).

<Note>
  Regardless of strategy or integration, Upsun applies the parent's disk size to the child environment if the child's disk size is smaller. This ensures the branch can be created.
</Note>

<Tabs>
  <Tab title="Without a source integration">
    Run the following command:

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

    For example, to inherit resources from the parent environment, run the following command:

    ```bash Terminal theme={null}
    upsun environment:branch --resources-init=parent
    ```
  </Tab>

  <Tab title="In the Console (without source integration)">
    1. Navigate to the environment you want to branch from.
    2. Click <BranchIcon /> **Branch**.
    3. Enter a name and a type for the new environment.
    4. Select an initialization strategy from the proposed list.
    5. Click **Branch**.
  </Tab>

  <Tab title="With a source integration">
    When you push a new branch to your repository, your [source integration](/docs/integrations/source) creates an environment using the resource initialization strategy configured on the integration.

    To override these defaults:

    #### Using the CLI (development environments only)

    Run the following command to update your integration's resource initialization strategy:

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

    For example, to use the `parent` strategy:

    ```bash Terminal theme={null}
    upsun integration:update --resources-init=parent
    ```

    <Note>
      When using the CLI, the value applies to **development** environments only. Production and staging environments always use the `default` strategy.
    </Note>

    #### Using the API (full per-type control)

    To set the resource initialization strategy independently for each environment type, use the API:

    ```bash Terminal theme={null}
    curl -X PATCH https://api.upsun.com/projects/<PROJECT_ID>/integrations/<INTEGRATION_ID> \
      -H "Authorization: Bearer <API_TOKEN>" \
      -H "Content-Type: application/json" \
      -d '{
        "environment_init_resources": {
          "production": "<STRATEGY>",
          "staging": "<STRATEGY>",
          "development": "<STRATEGY>"
        }
      }'
    ```

    Valid strategies: `minimum`, `default`, `manual`, `parent` (however, `parent` is not available for production environments).

    See [available resource initialization strategies](#specify-a-resource-initialization-strategy) for details.
  </Tab>
</Tabs>

### Environment merge

<Info>
  <h4>Resource initialization strategies</h4>
  Available: `child`, `default`, `minimum`, `manual` <br />
  Default: `child`
</Info>

When you [merge](/docs/glossary#merge) a child environment into its parent, any apps and services that exist on the child but not on the parent are created on the parent environment.

These new apps and services are granted resources according to the selected strategy. However, you can specify a different resource initialization strategy.

<Note>
  Apps and services already running on the parent environment keep their existing resources.
</Note>

<Tabs>
  <Tab title="Using the CLI">
    Run the following command:

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

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

    ```bash Terminal theme={null}
    upsun environment:merge --resources-init=manual
    ```
  </Tab>

  <Tab title="In the Console">
    1. Navigate to the environment you want to merge into its parent.
    2. Click <MergeIcon /> **Merge**.
    3. 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.
           </Note>
    4. Click **Merge**.
  </Tab>
</Tabs>

### Environment activation

<Info>
  <h4>Resource initialization strategies</h4>
  Available: `parent`, `default`, `minimum` <br />
  Default: `default` if the new environment is of type `staging`, `minimum` if the new environment is of type `development`
</Info>

When you activate a new environment, the resource initialization strategy applied depends on the environment type:

| Environment type | Default strategy | Resources allocated                            |
| ---------------- | ---------------- | ---------------------------------------------- |
| Staging          | `default`        | [default resource amounts](#default-resources) |
| Development      | `minimum`        | [minimum resources](#minimum-resources)        |

To specify a different strategy, run the following command:

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

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

```bash Terminal theme={null}
upsun environment:activate --resources-init=parent
```

<Note>
  [Setting resources](/docs/manage-resources/adjust-resources) on an inactive environment using the Console or the CLI automatically activates it.
</Note>

### Backup restoration

<Info>
  <h4>Resource initialization strategies</h4>
  Available: `backup`, `parent`, `default`, `minimum` <br />
  Default: `backup`
</Info>

<Tabs>
  <Tab title="Using the CLI">
    When you [restore a backup](/docs/environments/restore) using the CLI,
    you can restore it to your current environment or a different environment.

    #### Restore to your current environment

    By default, when you [restore a backup](/docs/environments/restore) using the CLI, it is restored to your current environment.
    The resources of every container running on the environment revert to the state they were in when the backup was taken.

    <Note>
      To skip restoring resources, use the `--no-resources` option.
    </Note>

    If you deleted containers after backing up but before restoring, they are recreated using the `backup` strategy and granted the same resources as when the backup was taken.

    <Note>
      To skip restoring deleted containers, use the `--no-code` option.
    </Note>

    When you restore previously deleted containers,
    you can specify a different resource initialization strategy for them.

    #### Restore to a different environment

    The `backup` strategy applies by default.
    All apps and services are initialized as new containers on the environment,
    and granted the same resources as in the backup.
    You can specify a different resource initialization strategy for all containers.

    #### Specify a resource initialization strategy

    Run the following command:

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

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

    ```bash Terminal theme={null}
    upsun backup:restore --resources-init=minimum
    ```
  </Tab>

  <Tab title="In the Console">
    When you [restore a backup](/docs/environments/restore) using the Console, it is restored to your current environment.
    The resources of every container running on the environment revert to the state they were in when the backup was taken.

    <Note>
      To skip restoring resources, use the `--no-resources` option.
    </Note>

    If you deleted containers after backing up but before restoring, they are recreated using the `backup` strategy and granted the same resources as when the backup was taken.

    <Note>
      To skip restoring deleted containers, restore the backup using the CLI and use the `--no-code` option.
    </Note>
  </Tab>
</Tabs>

## Environment sync

[Syncing an environment](/docs/glossary#sync) means propagating changes from a parent environment into a child environment (the opposite direction of an [environment merge](#environment-merge)).
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, code and resources, data and resources, or all three)

<Note>
  If the child's disk is smaller than the parent's, Upsun automatically applies the parent's disk size before syncing.
  This ensures the sync can succeed.
</Note>

<Tabs>
  <Tab title="Using the CLI">
    Run the following commands depending on your needs:

    * Sync only resources:

      ```bash Terminal theme={null}
      upsun sync resources
      ```

    * Sync only code:

      ```bash Terminal theme={null}
      upsun sync code
      ```

    * Sync only data:

      ```bash Terminal theme={null}
      upsun sync data
      ```

    * Sync everything:

      ```bash Terminal theme={null}
      upsun sync code data resources
      ```

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

  <Tab title="In the Console">
    1. Navigate to your Production environment.
    2. Click <SyncIcon /> **Sync**.
    3. Select the sync options you want from the proposed list.
    4. Select **Sync resources from Production into Staging**.
    5. Click **Sync**.
  </Tab>
</Tabs>
