Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

KB migration: Restore an environment #6063

Merged
merged 14 commits into from
Nov 22, 2019
Merged
3 changes: 3 additions & 0 deletions _data/toc/cloud-guide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ pages:
- label: Set up RabbitMQ service
url: /cloud/project/project-conf-files_services-rabbit.html

- label: Restore an environment
url: /cloud/env/restore-environment.html

- label: Configuration management for store settings
url: /cloud/live/sens-data-over.html
include_versions: [2.2","2.3"]
Expand Down
Binary file added common/images/copy-git-clone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added common/images/select-commit-hash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions guides/v2.2/cloud/env/restore-environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
title: Restore an environment
group: cloud-guide
---

If you encounter issues in your environment and do not have a [valid snapshot]({{ page.baseurl }}/cloud/project/project-webint-snap.html), you can try restoring your environment in one of the following ways:

- SSH
- Git

## SSH

If you have not created a snapshot, but you can access the environment using SSH, follow these steps to restore your environment:

1. Disable configuration management
1. Uninstall Magento
1. Reset the git branch

Performing these steps:

- Returns your Magento installation to its original state by restoring the database, removing the deployment configuration, and clearing `var/` subdirectories.
- Resets your git branch to a stable state in the past.

### Disable configuration management

You must disable [configuration management]({{ page.baseurl }}/cloud/live/sens-data-over.html) so that it does not automatically apply the previous configuration settings during deployment.

To disable configuration management, make sure that your `app/etc/` directory does not contain the `config.php` file.

{:.procedure}
To remove the configuration file:

1. [SSH to your environment]({{ page.baseurl }}/cloud/env/environments-ssh.html#ssh).
1. Remove the configuration file:
- For Magento 2.2:

```bash
rm app/etc/config.php
```

- For Magento 2.1:

```bash
rm app/etc/config.local.php
```

### Uninstall Magento

Uninstalling the Magento software drops and restores the database, removes the deployment configuration, and clears `var/` subdirectories.

{:.procedure}
To uninstall the Magento software:

1. [SSH to your environment]({{ page.baseurl }}/cloud/env/environments-ssh.html#ssh).
1. Uninstall the Magento application.

```bash
php bin/magento setup:uninstall
```

1. Confirm that Magento was successfully uninstalled.

The following message displays to confirm a successful uninstallation:

```terminal
[SUCCESS]: Magento uninstallation complete.
```

### Reset the git branch

Resetting your branch reverts the code to a stable state in the past.

{:.procedure}
To reset your branch:

1. Clone the project to your local development environment. You can find the command in your Project Web Interface:

![Click to copy the git clone command]({{ site.baseurl }}/common/images/copy-git-clone.png)

1. Review the git history. Use `--reverse` to display history in reverse chronological order:

```bash
git log --reverse
```

1. Choose a commit hash that represents the last known stable state of your code.

To reset your branch to its original initialized state, find the very first commit that created your branch.

![Select a commit hash in the git console]({{ site.baseurl }}/common/images/select-commit-hash.png)

1. Use the hard reset option to reset your branch.

```bash
git reset --h <commit_hash>
```

1. Push your changes to trigger a redeploy, which reinstalls Magento.

```bash
git push --force <origin> <branch>
```

## Git

If you have not created a snapshot, cannot access your environment using SSH, and your deployment keeps failing, you must complete the steps in the [previous section](#ssh), and then force a redeployment.

### Force a redeployment

Make a commit (this might be an empty commit, although we do not recommend it) and push it to the server to trigger redeploy:

```bash
git commit --allow-empty -m "<message>" && git push <origin> <branch>
```

## Uninstall failed

If executing the `setup:uninstall` command fails and cannot be completed, you might need to manually reset the database:

1. [SSH to your environment]({{ page.baseurl }}/cloud/env/environments-ssh.html#ssh).
1. Connect to the database.

```bash
mysql -h database.internal
```

1. Drop the `main` database.

```shell
drop database main;
```

1. Create an empty `main` database.

```shell
create database main;
```

1. Delete the following configuration files.

- `config.php`
- `config.php.bak`
- `env.php`
- `env.php.bak`

After resetting the database, [push your changes to trigger a redeploy]({{ page.baseurl }}/cloud/reference/cli-ref-topic.html#git-commands) and install Magento using the new database Or [run the redeploy command]({{ page.baseurl }}/cloud/reference/cli-ref-topic.html#environment-commands).
2 changes: 1 addition & 1 deletion guides/v2.2/cloud/project/project-webint-snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can back up and restore specific environments at any time using a snapshot.
A _snapshot_ is a complete backup of an environment that includes all persistent data from all running services (for example, your MySQL database, Redis, and so on) and any files stored on the mounted volumes. Because an environment deploys as a read-only file system, restoring a snapshot is very fast.

{: .bs-callout-warning }
If you want to rollback to previous code or remove added extensions in an environment, restoring a snapshot is not the recommended method. See [Rollbacks to remove code](#rollback-code).
If you want to rollback to previous code or remove added extensions in an environment, restoring a snapshot is not the recommended method. See [Rollbacks to remove code](#rollback-code). If you need to restore an unstable environment that does not have a snapshot, see [Restore an environment]({{ page.baseurl }}/cloud/env/restore-environment.html).

You have up to **7 days** to _restore_ a snapshot.

Expand Down
1 change: 1 addition & 0 deletions guides/v2.3/cloud/env/restore-environment.md