0

I move dockers around a lot on EC2 instances. Each docker has a specific folder on the host where it stores it's data.

I want to create a single backup script that will look for any of a list of possible folders and back each up to a file on S3 whose name is date stamped by day of month. So you end up with one month's worth of backups.

I want the backup script to gzip and stream the data to S3 to save on local disk space and IO.

Assume the S3 command line tools are installed and configured.

1
  • Welcome to Server Fault! Please help us in helping you by telling us more about what you've tried and your thoughts on why it didn't work. serverfault.com/help/how-to-ask
    – ErikE
    Aug 1, 2015 at 21:11

1 Answer 1

1
#!/usr/bin/env bash

# List folders here that may or may not be under base path.
# If folder isn't under base path we do nothing.
# If it exists we back it up to S3.
# S3 file is stamped to day of month.
# So you have a months worth of backups.
declare -a folders=(
  "elasticsearch"
  "jenkins"
  "some-cool-app"
)

BASE_PATH="/home/ubuntu/"
BUCKET="my.cool.bucket"

for FOLDER in "${folders[@]}"
do
  test -d ${BASE_PATH}${FOLDER}  && \
    tar -cz -C ${BASE_PATH} ${FOLDER} \
    | aws s3 cp - s3://${BUCKET}/${FOLDER}-$(date '+%d').tgz
done
1
  • btw you need a very recent version of aws command line tools.
    – john.stein
    Aug 5, 2015 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .