restore portainer from s3

pull/9/head
Cian Hatton 3 years ago
parent 70723f0d6d
commit c8dd1aa55b

@ -24,12 +24,12 @@ aws_s3:
region: "us-east-1"
bucket: "backups"
# any files to be copied which are required in the docker compose files
# as volume mounts.
config_files:
- destination_directory: /etc/config/dashy
dashy:
destination_dir: /etc/config/dashy
destination_file: dashy-config.yml
source_file: dashboards/dashy-config.yml
- destination_directory: /etc/config/olivetin
olivetin:
destination_dir: /etc/config/olivetin
destination_file: config.yml
source_file: olivetin/config.yml

@ -18,7 +18,6 @@ sections:
assets:
- bitcoin
- ethereum
- monero
- cosmos
- polkadot
- dogecoin

@ -13,6 +13,10 @@ actions:
icon: restart
shell: docker restart dashy
timeout: 30
- title: Restart Dashy 2
icon: restart
shell: docker restart dashy
timeout: 30
- title: Restart Olivetin
icon: restart
shell: docker restart olivetin

@ -1,2 +1,7 @@
---
# handlers file for setup_hosted_services
- name: restart-dashy
shell: docker restart dashy
- name: restart-olivetin
shell: docker restart olivetin

@ -1,11 +1,10 @@
- name: Docker | Pull ubuntu
- name: Docker | Pull images
docker_image:
name: ubuntu
source: pull
- name: Docker | Pull busybox
docker_image:
name: busybox
name: "{{item}}"
source: pull
with_items:
- ubuntu
- busybox
- name: Docker Compose | Create a directory if it does not exist
file:
@ -26,21 +25,32 @@
dest: "{{docker_compose_directory}}/{{item.name}}/stack.env"
with_items: "{{services}}"
- name: Config Files | Create a directory if it does not exist
file:
path: "{{item.destination_directory}}"
path: "{{item}}"
state: directory
mode: '0755'
with_items: "{{config_files}}"
with_items:
- "{{dashy.destination_dir}}"
- "{{olivetin.destination_dir}}"
- name: Dashy | Config Files
copy:
src: "{{dashy.source_file}}"
dest: "{{dashy.destination_dir}}/{{dashy.destination_file}}"
notify:
- restart-dashy
- name: Config Files | Copy config file
- name: Olivetin | Config Files
copy:
src: "{{item.source_file}}"
dest: "{{item.destination_directory}}/{{item.destination_file}}"
with_items: "{{config_files}}"
src: "{{olivetin.source_file}}"
dest: "{{olivetin.destination_dir}}/{{olivetin.destination_file}}"
notify:
- restart-olivetin
- name: Install python dependencies (requests)
ansible.builtin.pip:
pip:
name: requests
- name: Docker | Find docker volumes

@ -1,2 +1,7 @@
---
docker_compose_directory: /etc/docker-compose/portainer
aws_s3:
s3_url: "l8x8.ie11.idrivee2-6.com"
aws_access_key: "nyNMQ3fRMSV0bA1xw5uV"
region: "us-east-1"
bucket: "backups"

@ -9,12 +9,55 @@
src: docker-compose.yml
dest: "{{docker_compose_directory}}/docker-compose.yml"
# TODO: Look for portainer_data
- name: Portainer | Check if volume exists
shell: docker volume ls -f name=portainer_portainer_data --format '{{ '{{' }} .Name {{ '}}' }}'
register: portainer_volume
changed_when: False
- name: Portainer | Pull images
docker_image:
name: "{{item}}"
source: pull
with_items:
- ubuntu
- busybox
- name: Docker Volume Backup | Restore Portainer volume from S3
when: (portainer_volume.stdout_lines | length) == 0
docker_container:
command: "restore-volume --s3 --volume portainer_portainer_data"
image: "ghcr.io/chatton/docker-volume-backup:v0.3.0"
name: "s3-restore-portainer"
cleanup: true # delete container after it's done.
state: started # container should execute.
detach: no # task fails if container exits.
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /tmp:/tmp # temp s3 archive goes here
env:
AWS_ACCESS_KEY_ID: "{{aws_s3.aws_access_key}}"
AWS_SECRET_ACCESS_KEY: "{{aws_s3_secrets.aws_secret_key}}"
AWS_DEFAULT_REGION: "{{aws_s3.region}}"
AWS_BUCKET: "{{aws_s3.bucket}}"
AWS_ENDPOINT: "{{aws_s3.s3_url}}"
- name: Portainer | Docker compose up
community.docker.docker_compose:
project_src: "{{docker_compose_directory}}"
# TODO: if there was no portainer_data, register admin user
# http POST <portainer url>/api/users/admin/init Username="<admin username>" Password="<adminpassword>"
# Don't really need this as long as there is an S3 backup.
#- name: Portainer | Register Admin User
# when: (portainer_volume.stdout_lines | length) == 0
# uri:
# url: http://localhost:9000/api/users/admin/init
# method: POST
# body:
# Username: admin
# Password: "{{portainer.password}}"
# status_code: 200
# body_format: json
# register: result
# until: result.status == 200
# retries: 60
# delay: 1

Loading…
Cancel
Save