Skip to content

Instantly share code, notes, and snippets.

@Johannestegner
Created March 25, 2017 08:28
Show Gist options
  • Save Johannestegner/6d3948811bc815e0aeaabc5a7155b850 to your computer and use it in GitHub Desktop.
Save Johannestegner/6d3948811bc815e0aeaabc5a7155b850 to your computer and use it in GitHub Desktop.
Backup script for teamcity using basic auth via curl.
#!/usr/bin/env bash
# Change the following parameters to suit the backup you wish to create.
SERVER="https://XXXXXX" # URL to the server to back up.
WITH_TIMESTAMPS=false # If true, the file will be suffixed with current date-time.
INCLUDE_CONFIGS=true # To include configurations or not.
INCLUDE_DATABASE=true # To include database or not.
INCLUDE_BUILD_LOGS=true # To include build logs or not.
INCLUDE_PERSONAL_CHANGES=true # To include personal changes or not.
FILE_NAME_PREFIX="automatic-backup" # Name of the file (if timestamp is true, it will be suffixed with that).
USER="XXXXXX" # User which will create the backup (a user with access to backup).
PASSWORD="XXXXXX" # Password of the user.
echo "Creating teamcity backup. URL to Teamcity installation: $SERVER."
echo "Settings:"
echo "Use timestamp in filename: $WITH_TIMESTAMPS"
echo "Include configurations: $INCLUDE_CONFIGS"
echo "Include build logs: $INCLUDE_BUILD_LOGS"
echo "Include personal changes: $INCLUDE_PERSONAL_CHANGES"
echo "Include database: $INCLUDE_DATABASE"
echo "Backing up with filename: $FILE_NAME_PREFIX"
echo "Starting backup..."
PARAMTERS="&includeConfigs=$INCLUDE_CONFIGS&includeDatabase=$INCLUDE_DATABASE&includeBuildLogs=$INCLUDE_BUILD_LOGS&includePersonalChanges=$INCLUDE_PERSONAL_CHANGES"
URL="$SERVER/app/rest/server/backup?fileName=$FILE_NAME_PREFIX&addTimestamp=$WITH_TIMESTAMPS$PARAMTERS"
RESPONSE=$(curl -u $USER:$PASSWORD -X POST $URL)
echo "Response: $RESPONSE"
@Johannestegner
Copy link
Author

Johannestegner commented Mar 25, 2017

Example usage (backup every 12'th hour).

# crontab -e
0 */12 * * * /path/to/script.sh >> /path/to/logs/tc-backup.log 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment