> For the complete documentation index, see [llms.txt](https://www.trentbauer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.trentbauer.com/guides/other-guides/portainer/restore-stack-env-file.md).

# Restore stack env file

Sometimes we accidentally remove items from our environmental variables section and need to restore them.

#### You will need backups BEFORE following this

If you do not have backups, you may be out of luck!

For backup software, I personally use [Borg UI](https://github.com/karanhudia/borg-ui) for file level backups and PBS for entire VMs - I may write a guide for it in the future, but the software is constantly changing at the moment.&#x20;

[Veeam B\&R is free for 7 machines in a homelab](https://www.veeam.com/blog/backup-replication-community-edition-features-description.html) which is a great product to have on your resume.

## Get the stack ID

1. Log into your Portainer instance and navigate to the relevant stack
2. Have a look at the URL - you are looking for the ID - I have highlighted in bold below\
   `http://portainer.yourdomain.com/#!/2/docker/stacks/crowdsec-unifi?`**`id=867`**`&type=2&regular=true&orphaned=false&orphanedRunning=false`

## Get the volume path

1. Log into your Portainer instance
   1. If you have multiple hosts, select the host running Portainer
2. Select Containers
3. Locate Portainer in the list and open it
4. Scroll down to Volumes and locate the /data volume
5. If it is direct mount (host/path is grey), copy the path\
   Skip the rest of this section
6. If it is a docker volume (host/path is a link), click on the volume name
7. Copy the mount path

## File to restore

The file to restore will be your mount path will be **`MOUNTPATH`**`/compose/`**`STACKID`**`/stack.env`&#x20;

#### Some examples,

```
var/snap/docker/common/var-lib-docker/volumes/portainer/_data/compose/867/stack.env
var/lib/docker/volumes/portainer/_data/compose/123/stack.env
etc/portainer/compose/666/stack.env
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.trentbauer.com/guides/other-guides/portainer/restore-stack-env-file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
