Skip to content

.github/workflows/backup_rolling.yml #935

.github/workflows/backup_rolling.yml

.github/workflows/backup_rolling.yml #935

# Copyright 2023 CS Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
on:
push:
branches:
- main
schedule:
- cron: '0 0 * * *' # every day at midnight
jobs:
backup_rolling:
runs-on: ubuntu-latest
environment: backup
strategy:
matrix:
repository: [infrastructure, processing-sentinel-1, processing-sentinel-2, processing-sentinel-3, production-common, reference-system-documentation, reference-system-software, rs-config, rs-issues, user-web-client, website]
steps:
- name: Set up S3cmd cli tool
uses: s3-actions/s3cmd@v1.1
with:
access_key: ${{ secrets.ACCESS_KEY_ID }}
secret_key: ${{ secrets.SECRET_ACCESS_KEY }}
- name: Interact with object storage
run: |
LIST2DELDAILY=$(s3cmd --host=${{ secrets.HOST_BASE }} --host-bucket=${{ secrets.HOST_BUCKET }} ls s3://csc-rs-backup/COPRS/${{ matrix.repository }}/ | grep DAILY | cut -d '/' -f 6 | sort | head -n -15) ;
for BACKUP in ${LIST2DELDAILY} ; do s3cmd --host=${{ secrets.HOST_BASE }} --host-bucket=${{ secrets.HOST_BUCKET }} rm -r s3://csc-rs-backup/COPRS/${{ matrix.repository }}/${BACKUP} ; done ;
LIST2DELMONTHLY=$(s3cmd --host=${{ secrets.HOST_BASE }} --host-bucket=${{ secrets.HOST_BUCKET }} ls s3://csc-rs-backup/COPRS/${{ matrix.repository }}/ | grep MONTHLY | cut -d '/' -f 6 | sort | head -n -2) ;
for BACKUP in ${LIST2DELMONTHLY} ; do s3cmd --host=${{ secrets.HOST_BASE }} --host-bucket=${{ secrets.HOST_BUCKET }} rm -r s3://csc-rs-backup/COPRS/${{ matrix.repository }}/${BACKUP} ; done ;