From 194310ad01dcc58942478599611fc0fddf65636c Mon Sep 17 00:00:00 2001 From: chatton Date: Thu, 22 Jun 2023 00:13:14 +0100 Subject: [PATCH] updating version of docker_volume_backup --- .../docker_backup/.github/workflows/e2e.yml | 2 +- .../docker_backup/.github/workflows/lint.yml | 2 +- .../chatton/docker_backup/FILES.json | 12 ++--- .../chatton/docker_backup/MANIFEST.json | 2 +- .../chatton/docker_backup/README.md | 39 +++++++++++++++- .../roles/docker_s3_backup/defaults/main.yml | 6 ++- .../roles/docker_s3_backup/tasks/main.yml | 15 +++++- .../tests/host_vars/localhost.yml | 46 ++++++++++--------- host_vars/qnap.yml | 3 ++ requirements.yml | 7 ++- roles/setup_hosted_services/templates/plex.j2 | 6 +-- 11 files changed, 96 insertions(+), 44 deletions(-) diff --git a/collections/ansible_collections/chatton/docker_backup/.github/workflows/e2e.yml b/collections/ansible_collections/chatton/docker_backup/.github/workflows/e2e.yml index 1fbc673..7ca070a 100644 --- a/collections/ansible_collections/chatton/docker_backup/.github/workflows/e2e.yml +++ b/collections/ansible_collections/chatton/docker_backup/.github/workflows/e2e.yml @@ -11,7 +11,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.8.9 + python-version: '3.10' - name: Install dependencies run: make deps - name: Test Backup & Restore diff --git a/collections/ansible_collections/chatton/docker_backup/.github/workflows/lint.yml b/collections/ansible_collections/chatton/docker_backup/.github/workflows/lint.yml index 4ef23c8..3d9b251 100644 --- a/collections/ansible_collections/chatton/docker_backup/.github/workflows/lint.yml +++ b/collections/ansible_collections/chatton/docker_backup/.github/workflows/lint.yml @@ -11,7 +11,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: 3.8.9 + python-version: '3.10' - name: Install dependencies run: pip install -r requirements.txt - name: Test Directory diff --git a/collections/ansible_collections/chatton/docker_backup/FILES.json b/collections/ansible_collections/chatton/docker_backup/FILES.json index f527ec5..caaa1e1 100644 --- a/collections/ansible_collections/chatton/docker_backup/FILES.json +++ b/collections/ansible_collections/chatton/docker_backup/FILES.json @@ -88,7 +88,7 @@ "name": "tests/host_vars/localhost.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "388a868ea1dd4cded00276063b18f221bb3ed43040378fdcd6443dc2240d3db5", + "chksum_sha256": "beb7a0118badde41004674e83d1116c88c5e89b9c761d4dc8e8659c7d32fe4b1", "format": 1 }, { @@ -137,7 +137,7 @@ "name": "roles/docker_s3_backup/tasks/main.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "68b33673f05e9291aa60766650d4ccbc4b80e5d44ba1b7d33da954f43d53ca64", + "chksum_sha256": "1557afdcebc2be827d507fc7eb0d3f8dd97dd1cd21705b7122a604d45821eefc", "format": 1 }, { @@ -165,7 +165,7 @@ "name": "roles/docker_s3_backup/defaults/main.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "cd31b1ba5dd374feac22fce70bb91bd948a391c27691f8cc49190427dfd360aa", + "chksum_sha256": "736d895f68004b8dfb7e7949cd6f5f965d6e186952fd329c97a63e7ef85c6d1a", "format": 1 }, { @@ -249,7 +249,7 @@ "name": "README.md", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "678fe27fb5f532e6c89a7538da7931d64f7d6522a4c857a2de5495afabaeaab3", + "chksum_sha256": "9fe665d33b762d64e2c88c6c38d7bc37c321e8787655b5cfea9f7cf709b1bf76", "format": 1 }, { @@ -277,14 +277,14 @@ "name": ".github/workflows/lint.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "aa67d9ff8c695a9c47d18c540186647ef12160ed924608a4adabf4d0bfb5510a", + "chksum_sha256": "770c3a4744e959217cd1e3009919375669572537f37ca023ba1c9c6eca7d3852", "format": 1 }, { "name": ".github/workflows/e2e.yml", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "c78a395feeca4a7f3751cedd0666ad01c7d4e206ffecaf6928deefd0f8d9b384", + "chksum_sha256": "cabad9a267c2f1e47ab974bd71adb04fbe6c986232ae69522c22050de7931483", "format": 1 } ], diff --git a/collections/ansible_collections/chatton/docker_backup/MANIFEST.json b/collections/ansible_collections/chatton/docker_backup/MANIFEST.json index 8eeca7f..9d39d9e 100644 --- a/collections/ansible_collections/chatton/docker_backup/MANIFEST.json +++ b/collections/ansible_collections/chatton/docker_backup/MANIFEST.json @@ -23,7 +23,7 @@ "name": "FILES.json", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "826fa17a526c6aee0a3902560d70a21191cd31c771e120c376ad4fdb714ab618", + "chksum_sha256": "b9d31af90dda151013af86119ebe565a696b750368051de4ca00c637ab446e02", "format": 1 }, "format": 1 diff --git a/collections/ansible_collections/chatton/docker_backup/README.md b/collections/ansible_collections/chatton/docker_backup/README.md index f61e206..d297026 100644 --- a/collections/ansible_collections/chatton/docker_backup/README.md +++ b/collections/ansible_collections/chatton/docker_backup/README.md @@ -1,3 +1,38 @@ -# Ansible Collection - chatton.docker_backup +# Collection chatton.docker_backup -Documentation for the collection. +This collection contains the following roles: + +- [chatton.docker_backup.docker_backup](#chattondocker_backupdocker_backup) (backup docker volumes) +- [chatton.docker_backup.docker_restore](#chattondocker_backupdocker_restore) (restore docker volumes) + +### Shared variables + +| Variable | Description | Default | +|----------|-------------|---------| +| docker_backup_aws_s3_region | The AWS region to use | us-east-1 | +| docker_backup_aws_s3_bucket | The AWS S3 bucket to use | backups | +| docker_backup_host_backup_directory | The directory on the host to store the backup | "" | +| docker_backup_aws_s3_url | The AWS S3 url to use | "" | +| docker_backup_aws_s3_aws_access_key | The AWS access key to use | "" | +| docker_backup_aws_s3_aws_secret_key | The AWS secret key to use | "" | +| docker_backup_aws_s3_permissions | The AWS S3 permissions to use | [] | +| docker_backup_aws_s3_encrypt | Whether to encrypt the backup | true | + +### chatton.docker_backup.docker_backup + +| Variable | Description | Default | +|----------|-------------|---------| +| container_backup | The container to backup | "" | + +This role will stop the given container, backup all non host volumes, and restart the container. +The backup will be uploaded to the given AWS S3 bucket. + +### chatton.docker_backup.docker_restore + +| Variable | Description | Default | +|----------|-------------|---------| +| docker_backup_restore_force | forces a revert to the volume. | false | +| docker_backup_restore_latest_s3_key | specify docker_backup_restore_latest_s3_key true to automatically determine the latest backup in the s3 backup. | false | +| docker_backup_s3_volume.name | The name of the volume to restore | "" | +| docker_backup_s3_volume.s3_key | The s3 key to restore from | "" | +| docker_backup_fail_on_no_s3_backups | causes the task to fail if there are no s3 backups. | true | diff --git a/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/defaults/main.yml b/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/defaults/main.yml index 4d77d44..ad5b41e 100644 --- a/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/defaults/main.yml +++ b/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/defaults/main.yml @@ -2,8 +2,8 @@ # defaults file for chatton.docker_s3_backup # the number of backups of the same volume which should be kept. -# Any excess will be deleted. -docker_backup_retain_count: 3 +# Any excess will be deleted. If undefined, no backups will be deleted. +# docker_backup_retain_count: 3 # the backup directory where backups are stored on the host machine. # these will be uploaded to S3. docker_backup_aws_s3_region: "us-east-1" @@ -13,3 +13,5 @@ docker_backup_aws_s3_url: "" docker_backup_aws_s3_aws_access_key: "" docker_backup_aws_s3_aws_secret_key: "" docker_backup_aws_s3_permissions: [] +docker_backup_aws_s3_encrypt: true +docker_backup_keep_local: false diff --git a/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/tasks/main.yml b/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/tasks/main.yml index cc14f90..3c2568d 100644 --- a/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/tasks/main.yml +++ b/collections/ansible_collections/chatton/docker_backup/roles/docker_s3_backup/tasks/main.yml @@ -52,13 +52,22 @@ aws_access_key: "{{ docker_backup_aws_s3_aws_access_key }}" aws_secret_key: "{{ docker_backup_aws_s3_aws_secret_key }}" region: "{{ docker_backup_aws_s3_region }}" - encrypt: off mode: put + encrypt: "{{ docker_backup_aws_s3_encrypt }}" permission: "{{ docker_backup_aws_s3_permissions }}" with_items: "{{ volume_mounts }}" +# delete local backups if we are not keeping them. +- name: Delete local backups. + file: + path: "{{ docker_backup_host_backup_directory }}/{{ item.Name }}-{{ backup_time }}.tar.gz" + state: absent + when: not docker_backup_keep_local + with_items: "{{ volume_mounts }}" + # try and find latest volume based on the name. - name: Fetch Volumes From S3. + when: docker_backup_retain_count is defined amazon.aws.aws_s3: bucket: "{{ docker_backup_aws_s3_bucket }}" mode: list @@ -71,10 +80,12 @@ with_items: "{{ volume_mounts }}" - name: Find keys to delete. + when: docker_backup_retain_count is defined ansible.builtin.set_fact: s3_keys_to_delete: "{{ s3_list_outputs.results | map(attribute='s3_keys') | keep_last(docker_backup_retain_count) | flatten }}" -- name: Delete old backups. +- name: Delete old s3 backups. + when: docker_backup_retain_count is defined amazon.aws.aws_s3: bucket: "{{ docker_backup_aws_s3_bucket }}" aws_access_key: "{{ docker_backup_aws_s3_aws_access_key }}" diff --git a/collections/ansible_collections/chatton/docker_backup/tests/host_vars/localhost.yml b/collections/ansible_collections/chatton/docker_backup/tests/host_vars/localhost.yml index d2ffd79..25b6999 100644 --- a/collections/ansible_collections/chatton/docker_backup/tests/host_vars/localhost.yml +++ b/collections/ansible_collections/chatton/docker_backup/tests/host_vars/localhost.yml @@ -1,23 +1,25 @@ $ANSIBLE_VAULT;1.1;AES256 -31343237643365393335643262646139363037616365623238316536313238386237353436643738 -3332376365393138633962373132633562363035396161650a323039646238373162333366353533 -37333238643437623538343630393065313463313038616538613838366638636433313637313630 -3733623838373864320a373636303030373737336265353165373463306233333033393266343838 -31323634313531343262323561636438326166343461373133393166303630303865316661356165 -64366435343933396131313665336437363234393239663831363033356433383330323964613833 -36346436383739623163343130376465333465316139303437666333386633313132336234383936 -65353437336637353739373837343766333266396263396562366463626332363061383435353132 -34616134396136333266323930343866663332373864623537623765303435366331613466376137 -63346337303461623036306362306235366365646137316165376634316230396239623132363337 -35363932663361313533663436633532313732646564663463393233316231623361336332336135 -39356338363336336231643661313062303734316539653031313630363866303464643438653035 -37393039623961386539303235636562653130343237336332643639346631326633363366373466 -62356536356664353466383131306664653132393837663635366466613665626535323930366637 -38646263326264313363386634363834626638383563346361386165323430383266646631626362 -64303263383138353739656534623734623638653438353666623464656461316636626564326536 -34616163626539383265353963333734313363343162663434356337393266313637323732346231 -33373835373465666637663330653337373130373732303632326530336132333236313466653239 -30383632363337333833666132363563363361623865616134613538373439353836346366353065 -34356134633038653839333430313738613531653634333430373635373239653362393461306330 -35326532303432316636666134353534626139316331333538356165313965613739653665616237 -3165353731626130666639346263333865316362623134373463 +34636164626337666434313039376166636437323530353763393833363331333831353935633364 +6439626663363038306330646233326634363136306133650a616161313361616639376336613135 +35313033373335353938643338613465643663626162656333393439623764653865643838626332 +3639383861366166330a326565323065373436383037316634643562343065343636623637666363 +36616438396136663765373733306636383430616362633161313666346631636232306462623236 +32653934363239623930633466626361393537643433613834623631636362633762363031356439 +31376530363734663230393130616534343030616333646332333939323835336438323766313439 +36323466353533333335396430363533636437623164306466656133346435613962383235643539 +65663831633530346663343139316139343432313838333439626238393733613139333439613134 +32633736616434376635363434643664326139383166316632333238646432636638313338376234 +62663834316234336230336162396231326436323463393033313038303431386662373263333531 +37303262326561643738393334643330643037326264623737353135383764326637356334363639 +32666637363933656261333738666437386163636664376231363731643433343530363161373366 +61303635313161376662626362636636336265343934353539393035646666636538616432643666 +38366135663933613334393165333638616638373331343731356361303965613532356432376339 +30353033393831363839326231656465616632306562316630636438363339626361396165373038 +30616661636562613466366331633465393639373962356465363333393632376132343565396462 +33363733386263633934363461626537333562633238363936373639323866343135653733393538 +32373061613466663535366564663434636635306165363961643331356232373131306136363230 +62643636303635633930386463346433643330633363646230653866366138346462653032396264 +37643132633262393739306361303065353430346161613232393161666463306335326464316233 +63376562343834346565646266343437343832366230376331383266616438336261636334333563 +62386162643465663066326133666561646630346339653430363362376164363164353761346165 +63656663383133326538 diff --git a/host_vars/qnap.yml b/host_vars/qnap.yml index 76cf630..3eedf19 100644 --- a/host_vars/qnap.yml +++ b/host_vars/qnap.yml @@ -92,6 +92,9 @@ services: glances: true - name: nginx-proxy-manager - name: plex + template_vars: + plex_image: lscr.io/linuxserver/plex + plex_tag: 1.32.4 - name: uptime-kuma - name: mariadb template_vars: diff --git a/requirements.yml b/requirements.yml index f194748..e805a97 100644 --- a/requirements.yml +++ b/requirements.yml @@ -9,7 +9,6 @@ collections: - name: https://github.com/chatton/ansible-portainer.git type: git version: master - # TODO: support encryption -# - name: https://github.com/chatton/ansible-docker-backup.git -# type: git -# version: master + - name: https://github.com/chatton/ansible-docker-backup.git + type: git + version: master diff --git a/roles/setup_hosted_services/templates/plex.j2 b/roles/setup_hosted_services/templates/plex.j2 index a406c66..99c845e 100644 --- a/roles/setup_hosted_services/templates/plex.j2 +++ b/roles/setup_hosted_services/templates/plex.j2 @@ -4,8 +4,8 @@ services: plex: labels: ie.cianhatton.backup.enabled: "true" - ie.cianhatton.backup.schedule: "{{backups.schedule_keys.monthly}}" - image: lscr.io/linuxserver/plex:latest + ie.cianhatton.backup.schedule: "{{ backups.schedule_keys.nightly }}" + image: "{{ template_vars.plex_image }}:{{ template_vars.plex_tag }}" container_name: plex ports: - 32400:32400 @@ -26,7 +26,7 @@ services: tautulli: labels: ie.cianhatton.backup.enabled: "true" - ie.cianhatton.backup.schedule: "{{backups.schedule_keys.nightly}}" + ie.cianhatton.backup.schedule: "{{ backups.schedule_keys.nightly }}" image: lscr.io/linuxserver/tautulli:latest container_name: tautulli environment: