Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pillar/registry.sls
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sync:
/home/collect/scrapyd/dbs:
/home/collect/scrapyd/eggs:
/home/collect/scrapyd/jobs:
exclude: "*/requests.queue/*"
/home/collect/scrapyd/logs:

apache:
Expand Down
25 changes: 15 additions & 10 deletions salt/aws/files/sync-to-s3.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Backup multiple directories and upload to AWS S3
# Sync a single directory into S3.

set -euo pipefail

Expand All @@ -24,16 +24,21 @@ if [ ! -x "$AWS_CLI" ]; then
exit 3
fi

if [ -z "$SYNC_DIRECTORIES" ]; then
echo "Error: SYNC_DIRECTORIES isn't set or is empty"
if [ -z "$S3_SYNC_BUCKET" ]; then
echo "Error: S3_SYNC_BUCKET isn't set or is empty"
exit 4
fi

for DIRECTORY in "${SYNC_DIRECTORIES[@]}"; do
SAFENAME="${DIRECTORY/#\//}"
SAFENAME="${SAFENAME/%\//}"
if [ ! -e "$1" ]; then
echo "Error: DIRECTORY isn't set or doesn't exist."
exit 5
fi

DIRECTORY=$1
SAFENAME=${DIRECTORY/#\//}
SAFENAME="${SAFENAME/%\//}"
shift

set +e
$AWS_CLI s3 sync "$DIRECTORY" "s3://$S3_SYNC_BUCKET/$SAFENAME/" --only-show-errors --delete 2>&1 | grep -v "You did not provide the number of bytes specified by the Content-Length HTTP header"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need this anymore?

2>&1 | grep -v "You did not provide the number of bytes specified by the Content-Length HTTP header"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may still want to ignore these alerts (files changing as the script runs).
I want to see how much the exclude functionality reduces these warnings first.

set -e
done
set +e
$AWS_CLI s3 sync --only-show-errors --delete "${@}" "$DIRECTORY" "s3://$S3_SYNC_BUCKET/$SAFENAME/"
set -e
Comment thread
jpmckinney marked this conversation as resolved.
16 changes: 5 additions & 11 deletions salt/aws/sync.sls
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ include:
file.managed:
- contents: |
MAILTO=root
15 03,15 * * * root /home/sysadmin-tools/bin/sync-to-s3.sh
{%- for directory, entry in pillar.sync.directories|items %}
{%- set minute = (loop.index0 * 5) % 60 %}
{{minute}} 03,15 * * * root /home/sysadmin-tools/bin/sync-to-s3.sh {{ directory }}
{%- for option, value in entry | default({}, true) | items %} --{{ option }} "{{ value }}"{% endfor %}
{%- endfor %}
- require:
- file: /home/sysadmin-tools/bin/sync-to-s3.sh

set SYNC_DIRECTORIES setting:
file.keyvalue:
- name: /home/sysadmin-tools/aws-settings.local
- key: SYNC_DIRECTORIES
- value: '( "{{ pillar.sync.directories|join('" "') }}" )'
- append_if_not_found: True
- require:
- file: /home/sysadmin-tools/bin
- sls: aws