From 50279dac194898c2752b16886d1433403b7e9cd3 Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Wed, 29 May 2019 19:03:44 +0000 Subject: [PATCH] add a more general s3 sync script that takes a path from /pub/ and attempts to sync it Signed-off-by: Rick Elrod --- roles/s3-mirror/files/s3-sync-path.sh | 53 +++++++++++++++++++++++++++ roles/s3-mirror/tasks/main.yml | 1 + 2 files changed, 54 insertions(+) create mode 100644 roles/s3-mirror/files/s3-sync-path.sh diff --git a/roles/s3-mirror/files/s3-sync-path.sh b/roles/s3-mirror/files/s3-sync-path.sh new file mode 100644 index 0000000000..9fbe7d0514 --- /dev/null +++ b/roles/s3-mirror/files/s3-sync-path.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# (c) 2019 Red Hat, Inc. +# LGPL +# Author: Rick Elrod + +if [[ "$1" == "" ]] || [[ $1 != /pub* ]] || [[ $1 != */ ]]; then + echo "Syntax: $0 /pub/path/to/sync/" + echo "NOTE! Path must end with a trailing /" + exit 1 +fi + +CMD="aws s3 sync \ + --delete \ + --exclude */.snapshot/* \ + --exclude */source/* \ + --exclude */SRPMS/* \ + --exclude */debug/* \ + --exclude */beta/* \ + --exclude */ppc/* \ + --exclude */ppc64/* \ + --exclude */repoview/* \ + --exclude */Fedora/* \ + --exclude */Live/* \ + --exclude */isolinux/* \ + --exclude */images/* \ + --exclude */EFI/* \ + --exclude */core/* \ + --exclude */extras/* \ + --exclude */LiveOS/* \ + --exclude */development/* \ + --exclude */releases/test/* \ + --no-follow-symlinks \ + " + #--dryrun \ + +echo "$CMD /srv$1 s3://s3-mirror-us-west-1-02.fedoraproject.org$1" +echo "Starting $1 sync at $(date)" >> /var/log/s3-mirror/timestamps +$CMD /srv$1 s3://s3-mirror-us-west-1-02.fedoraproject.org$1 +echo "Ending $1 sync at $(date)" >> /var/log/s3-mirror/timestamps + +# Always do the invalidations because they are quick and prevent issues +# depending on which path is synced. +for file in $(echo /srv/pub/epel/6/*/repodata/repomd.xml | sed 's#/srv##g'); do + aws cloudfront create-invalidation --distribution-id E2KJMDC0QAJDMU --paths "$file" +done + +for file in $(echo /srv/pub/epel/7/*/repodata/repomd.xml | sed 's#/srv##g'); do + aws cloudfront create-invalidation --distribution-id E2KJMDC0QAJDMU --paths "$file" +done + +for file in $(echo /srv/pub/fedora/linux/updates/*/*/*/repodata/repomd.xml | sed 's#/srv##g'); do + aws cloudfront create-invalidation --distribution-id E2KJMDC0QAJDMU --paths "$file" +done diff --git a/roles/s3-mirror/tasks/main.yml b/roles/s3-mirror/tasks/main.yml index 74f40d5541..6e993aeec1 100644 --- a/roles/s3-mirror/tasks/main.yml +++ b/roles/s3-mirror/tasks/main.yml @@ -42,6 +42,7 @@ copy: src={{item}} dest=/usr/local/bin/{{item}} owner=s3-mirror group=s3-mirror mode=0755 with_items: - s3.sh + - s3-sync-path.sh tags: - s3-mirror