Commit 063f5c09 by John Eskew

Preserve older versions of go-server backups.

parent 3ddfaa35
......@@ -64,17 +64,24 @@ GO_SERVER_H2DB_BACKUP_PATH: "artifacts/db_backup/"
GO_SERVER_H2DB_BACKUP_LOCATION: "{{ GO_SERVER_HOME }}/{{ GO_SERVER_H2DB_BACKUP_PATH }}/{{ GO_SERVER_H2DB_NAME }}"
# For use in backup/restore of a GoCD configuration.
GO_SERVER_BACKUP_ENVIRONMENT: "sandbox"
GO_SERVER_BACKUP_SNITCH_URL: "https://nosnch.in/4444444444"
GO_SERVER_BACKUP_FILENAME: "go-server-latest-backup.tgz"
GO_SERVER_TEMP_RESTORE_DIRECTORY: "/tmp/go-server-backup"
GO_SERVER_BACKUP_S3_BUCKET: "edx-tools-gocd-backup"
GO_SERVER_BACKUP_S3_BUCKET: "edx-{{ GO_SERVER_BACKUP_ENVIRONMENT }}-gocd-backup"
GO_SERVER_BACKUP_S3_OBJECT: "{{ GO_SERVER_BACKUP_FILENAME }}"
GO_SERVER_BACKUP_SNITCH_URL: "https://nosnch.in/4444444444"
GO_SERVER_BACKUP_APT_PKGS: ["python-pip", "jq"]
GO_SERVER_BACKUP_PIP_PKGS: ["boto", "awscli"]
GO_SERVER_BACKUP_API_URL: "http://localhost:8153/go/api/backups"
GO_SERVER_BACKUP_TMP_LOCATION: "/tmp/{{ GO_SERVER_BACKUP_FILENAME }}"
GO_SERVER_BACKUP_CRON_SCRIPT_LOCATION: "/root/gocd_backup.sh"
# When "true", attempts to restore go-server backup from S3.
GO_SERVER_RESTORE_BACKUP: "false"
# When "true", attempts to configure regular, cron-based backups to S3 on go-server.
GO_SERVER_CONFIGURE_BACKUPS: "false"
# password file setup
GO_SERVER_PASSWORD_FILE_NAME: "password.txt"
GO_SERVER_ADMIN_USERS: ["admin"]
......
......@@ -103,9 +103,8 @@
group: "{{ GO_SERVER_GROUP }}"
force: no
# If a GoCD restore file is specified, attempt to download and restore it.
- include: download_backup.yml
when: GO_SERVER_BACKUP_S3_BUCKET and GO_SERVER_BACKUP_S3_OBJECT
when: GO_SERVER_BACKUP_S3_BUCKET and GO_SERVER_BACKUP_S3_OBJECT and GO_SERVER_RESTORE_BACKUP == "true"
- name: replace the admin line in the password file post-restore
lineinfile:
......@@ -127,4 +126,4 @@
state: restarted
- include: setup_regular_backup.yml
when: GO_SERVER_BACKUP_S3_BUCKET and GO_SERVER_BACKUP_S3_OBJECT
when: GO_SERVER_BACKUP_S3_BUCKET and GO_SERVER_BACKUP_S3_OBJECT and GO_SERVER_CONFIGURE_BACKUPS == "true"
......@@ -7,6 +7,7 @@ gocd_password="{{ GO_SERVER_BACKUP_PASSWORD }}"
gocd_backup_location="{{ GO_SERVER_BACKUP_TMP_LOCATION }}"
s3_backup_bucket="{{ GO_SERVER_BACKUP_S3_BUCKET }}"
snitch_url="{{ GO_SERVER_BACKUP_SNITCH_URL }}"
gocd_backup_base=gocd-"{{ GO_SERVER_BACKUP_ENVIRONMENT }}"
# Trigger the backup and capture the backup path.
# The output of the api call is documented here:
......@@ -52,22 +53,37 @@ null)
;;
esac
# Make backup into a tarball.
tar zcvf "$gocd_backup_location" -C "$(dirname "$backup_path")" "$(basename "$backup_path")"
# Make latest backup into a tarball.
backup_dir_name="$(basename "$backup_path")"
tar zcvf "$gocd_backup_location" -C "$(dirname "$backup_path")" "${backup_dir_name}"
# Transfer tarball to S3.
aws_output=$(aws s3 cp "$gocd_backup_location" "s3://$s3_backup_bucket" 2>&1)
dated_backup_filename="${gocd_backup_base}-${backup_dir_name}.tgz"
# Transfer tarball to S3 with datetime'd filename.
aws_output=$(aws s3 cp "${gocd_backup_location}" "s3://${s3_backup_bucket}/${dated_backup_filename}" 2>&1)
case $aws_output in
*failed*)
echo "Backup transfer failed: $aws_output"
exit
;;
*)
echo "Backup transfer of ${dated_backup_filename} to S3 bucket $s3_backup_bucket succeeded."
;;
esac
# Transfer tarball to S3 with official backup filename.
aws_output=$(aws s3 cp "${gocd_backup_location}" "s3://${s3_backup_bucket}" 2>&1)
case $aws_output in
*failed*)
echo "Backup transfer failed: $aws_output"
exit
;;
*)
echo "Backup transfer to S3 bucket $s3_backup_bucket succeeded."
echo "Backup transfer of $(basename "${gocd_backup_location}") to S3 bucket $s3_backup_bucket succeeded."
# Report to Dead Man's Snitch.
curl $snitch_url
;;
esac
# Remove the tarball.
rm -f "$gocd_backup_location"
rm -f "$gocd_backup_location"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment