#!/bin/bash -e

BUCKET_NAME=$1

TIMESTAMP=$(date +%F_%T | tr ':' '-')
YEAR=$(date +%Y)
MONTH=$(date +%m)
S3_FILE="${BUCKET_NAME}/${HOSTNAME}/${YEAR}/${MONTH}/jenkins-${TIMESTAMP}.tar.gz"

# create temporary tar file
JENKINS_BACKUP_FILE=$(mktemp /tmp/jenkins.tar.gz.XXXXX)

# create s3 bucket if it doesn't already exist
/usr/local/bin/s3cmd mb "s3://${BUCKET_NAME}"

# tar both jenkins directories
sudo tar czvf "$JENKINS_BACKUP_FILE" /media/data/jenkins /var/lib/jenkins

# upload to s3
/usr/local/bin/s3cmd put "$JENKINS_BACKUP_FILE" "s3://${S3_FILE}"

# remove temporary file
if [[ -f "$JENKINS_BACKUP_FILE" ]]; then
  rm "$JENKINS_BACKUP_FILE"
fi

#!/bin/bash -e

BUCKET_NAME=$1

TIMESTAMP=$(date +%F_%T | tr ':' '-')
YEAR=$(date +%Y)
MONTH=$(date +%m)
S3_FILE="${BUCKET_NAME}/${HOSTNAME}/${YEAR}/${MONTH}/jenkins-${TIMESTAMP}.tar.gz"

# create the temporary directory if it doesn't exist
if [[ ~ -d /media/data/tmp ]]; then
    sudo mkdir /media/data/tmp
    sudo chmod 777 /media/data/tmp
fi

# create temporary tar file
JENKINS_BACKUP_FILE=$(mktemp /media/data/tmp/jenkins.tar.gz.XXXXX)

# create s3 bucket if it doesn't already exist
/usr/local/bin/s3cmd mb "s3://${BUCKET_NAME}"

# tar both jenkins directories
sudo tar czvf "$JENKINS_BACKUP_FILE" /media/data/jenkins /var/lib/jenkins

# upload to s3
/usr/local/bin/s3cmd put "$JENKINS_BACKUP_FILE" "s3://${S3_FILE}"

# remove temporary file
if [[ -f "$JENKINS_BACKUP_FILE" ]]; then
  rm "$JENKINS_BACKUP_FILE"
fi

Change the location of the backup directory
Change the location of the backup directory

The original directory was /tmp and when the backup ran it filled the
root filesystem and would cause the monitors to send of warnings until
the space was freed up again.  This change puts the backup directory in
a volume that has a lot more space.
